summaryrefslogtreecommitdiffstats
path: root/gita/__main__.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--gita/__main__.py77
1 files changed, 59 insertions, 18 deletions
diff --git a/gita/__main__.py b/gita/__main__.py
index b2bc32b..6809f15 100644
--- a/gita/__main__.py
+++ b/gita/__main__.py
@@ -18,14 +18,15 @@ import os
import sys
import csv
import argparse
+import argcomplete
import subprocess
from functools import partial
-import pkg_resources
from itertools import chain
from pathlib import Path
import glob
+from typing import Dict, Optional
-from . import utils, info, common
+from . import utils, info, common, io, get_version
def _group_name(name: str, exclude_old_names=True) -> str:
@@ -146,13 +147,28 @@ def f_info(args: argparse.Namespace):
with open(csv_config, "w", newline="") as f:
writer = csv.writer(f)
writer.writerow(to_display)
+ elif cmd == "set-length":
+ csv_config = common.get_config_fname("layout.csv")
+ print(f"Settings are in {csv_config}")
+ defaults = {
+ "branch": 19,
+ "symbols": 5,
+ "branch_name": 27,
+ "commit_msg": 0,
+ "commit_time": 0, # 0 means no limit
+ "path": 30,
+ }
+ with open(csv_config, "w", newline="") as f:
+ writer = csv.DictWriter(f, fieldnames=defaults)
+ writer.writeheader()
+ writer.writerow(defaults)
def f_clone(args: argparse.Namespace):
if args.dry_run:
if args.from_file:
- for url, repo_name, abs_path in utils.parse_clone_config(args.clonee):
+ for url, repo_name, abs_path in io.parse_clone_config(args.clonee):
print(f"git clone {url} {abs_path}")
else:
print(f"git clone {args.clonee}")
@@ -172,28 +188,35 @@ def f_clone(args: argparse.Namespace):
f_add(args)
return
+ # TODO: add repos to group too
+ repos, groups = io.parse_clone_config(args.clonee)
if args.preserve_path:
utils.exec_async_tasks(
- utils.run_async(repo_name, path, ["git", "clone", url, abs_path])
- for url, repo_name, abs_path in utils.parse_clone_config(args.clonee)
+ utils.run_async(repo_name, path, ["git", "clone", r["url"], r["path"]])
+ for repo_name, r in repos.items()
)
else:
utils.exec_async_tasks(
- utils.run_async(repo_name, path, ["git", "clone", url])
- for url, repo_name, _ in utils.parse_clone_config(args.clonee)
+ utils.run_async(repo_name, path, ["git", "clone", r["url"]])
+ for repo_name, r in repos.items()
)
def f_freeze(args):
- repos = utils.get_repos()
+ """
+ print repo and group information for future cloning
+ """
ctx = utils.get_context()
if args.group is None and ctx:
args.group = ctx.stem
+ repos = utils.get_repos()
+ group_name = args.group
group_repos = None
- if args.group: # only display repos in this group
- group_repos = utils.get_groups()[args.group]["repos"]
+ if group_name: # only display repos in this group
+ group_repos = utils.get_groups()[group_name]["repos"]
repos = {k: repos[k] for k in group_repos if k in repos}
seen = {""}
+ # print(repos)
for name, prop in repos.items():
path = prop["path"]
url = ""
@@ -211,7 +234,16 @@ def f_freeze(args):
url = parts[1]
if url not in seen:
seen.add(url)
- print(f"{url},{name},{path}")
+ # TODO: add another field to distinguish regular repo or worktree or submodule
+ print(f"{url},{name},{path},")
+ # group information: these lines don't have URL
+ if group_name:
+ group_path = utils.get_groups()[group_name]["path"]
+ print(f",{group_name},{group_path},{'|'.join(group_repos)}")
+ else: # show all groups
+ for gname, g in utils.get_groups().items():
+ group_repos = "|".join(g["repos"])
+ print(f",{gname},{g['path']},{group_repos}")
def f_ll(args: argparse.Namespace):
@@ -435,8 +467,9 @@ def main(argv=None):
title="sub-commands", help="additional help with sub-command -h"
)
- version = pkg_resources.require("gita")[0].version
- p.add_argument("-v", "--version", action="version", version=f"%(prog)s {version}")
+ p.add_argument(
+ "-v", "--version", action="version", version=f"%(prog)s {get_version()}"
+ )
# bookkeeping sub-commands
p_add = subparsers.add_parser("add", description="add repo(s)", help="add repo(s)")
@@ -598,11 +631,17 @@ def main(argv=None):
info_cmds.add_parser("rm", description="Disable information item.").add_argument(
"info_item", choices=info.ALL_INFO_ITEMS, help="information item to delete"
)
+ info_cmds.add_parser(
+ "set-length",
+ description="Set default column widths for information items. "
+ "The settings are in layout.csv",
+ )
ll_doc = f""" status symbols:
+: staged changes
*: unstaged changes
- _: untracked files/folders
+ ?: untracked files/folders
+ $: stashed changes
branch colors:
{info.Color.white}white{info.Color.end}: local has no remote
@@ -780,17 +819,18 @@ def main(argv=None):
cmds = utils.get_cmds_from_files()
for name, data in cmds.items():
help = data.get("help")
+ repo_help = help
cmd = data["cmd"]
if data.get("allow_all"):
choices = utils.get_choices()
nargs = "*"
- help += " for all repos or"
+ repo_help += " for all repos or"
else:
choices = utils.get_repos().keys() | utils.get_groups().keys()
nargs = "+"
- help += " for the chosen repo(s) or group(s)"
- sp = subparsers.add_parser(name, description=help)
- sp.add_argument("repo", nargs=nargs, choices=choices, help=help)
+ repo_help += " for the chosen repo(s) or group(s)"
+ sp = subparsers.add_parser(name, description=help, help=help)
+ sp.add_argument("repo", nargs=nargs, choices=choices, help=repo_help)
is_shell = bool(data.get("shell"))
sp.add_argument(
"-s",
@@ -805,6 +845,7 @@ def main(argv=None):
cmd = cmd.split()
sp.set_defaults(func=f_git_cmd, cmd=cmd)
+ argcomplete.autocomplete(p)
args = p.parse_args(argv)
args.async_blacklist = {