summaryrefslogtreecommitdiffstats
path: root/gita
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-07-18 10:49:23 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-07-18 10:49:23 +0000
commita2a738495ed1b8602c67efc28827d993b1b47150 (patch)
tree67a4ab28374c2489f5cd30dbed4242ea80f0ee77 /gita
parentReleasing progress-linux version 0.16.5-1. (diff)
downloadgita-a2a738495ed1b8602c67efc28827d993b1b47150.tar.xz
gita-a2a738495ed1b8602c67efc28827d993b1b47150.zip
Merging upstream version 0.16.6.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'gita')
-rw-r--r--gita/__main__.py24
-rw-r--r--gita/info.py82
2 files changed, 72 insertions, 34 deletions
diff --git a/gita/__main__.py b/gita/__main__.py
index 3d091c6..b2bc32b 100644
--- a/gita/__main__.py
+++ b/gita/__main__.py
@@ -165,6 +165,11 @@ def f_clone(args: argparse.Namespace):
if not args.from_file:
subprocess.run(["git", "clone", args.clonee], cwd=path)
+ # add the cloned repo to gita; group is also supported
+ cloned_path = os.path.join(path, args.clonee.split("/")[-1].split(".")[0])
+ args.paths = [cloned_path]
+ args.recursive = args.auto_group = args.bare = args.skip_submodule = False
+ f_add(args)
return
if args.preserve_path:
@@ -497,12 +502,6 @@ def main(argv=None):
help="Change to DIRECTORY before doing anything.",
)
p_clone.add_argument(
- "-f",
- "--from-file",
- action="store_true",
- help="If set, clone repos in a config file rendered from `gita freeze`",
- )
- p_clone.add_argument(
"-p",
"--preserve-path",
dest="preserve_path",
@@ -515,6 +514,19 @@ def main(argv=None):
action="store_true",
help="If set, show command without execution",
)
+ xgroup = p_clone.add_mutually_exclusive_group()
+ xgroup.add_argument(
+ "-g",
+ "--group",
+ choices=utils.get_groups(),
+ help="If set, add repo to the specified group after cloning, otherwise add to gita without group.",
+ )
+ xgroup.add_argument(
+ "-f",
+ "--from-file",
+ action="store_true",
+ help="If set, clone repos in a config file rendered from `gita freeze`",
+ )
p_clone.set_defaults(func=f_clone)
p_rename = subparsers.add_parser(
diff --git a/gita/info.py b/gita/info.py
index bfb463b..10d8bea 100644
--- a/gita/info.py
+++ b/gita/info.py
@@ -1,8 +1,8 @@
-import os
import csv
import subprocess
from enum import Enum
from pathlib import Path
+from collections import namedtuple
from functools import lru_cache, partial
from typing import Tuple, List, Callable, Dict
@@ -41,11 +41,11 @@ class Color(Enum):
default_colors = {
- "no-remote": Color.white.name,
- "in-sync": Color.green.name,
+ "no_remote": Color.white.name,
+ "in_sync": Color.green.name,
"diverged": Color.red.name,
- "local-ahead": Color.purple.name,
- "remote-ahead": Color.yellow.name,
+ "local_ahead": Color.purple.name,
+ "remote_ahead": Color.yellow.name,
}
@@ -195,49 +195,75 @@ def get_commit_time(prop: Dict[str, str]) -> str:
return f"({result.stdout.strip()})"
+default_symbols = {
+ "dirty": "*",
+ "staged": "+",
+ "untracked": "?",
+ "local_ahead": "↑",
+ "remote_ahead": "↓",
+ "diverged": "⇕",
+ "in_sync": "",
+ "no_remote": "∅",
+ "": "",
+}
+
+
+@lru_cache()
+def get_symbols() -> Dict[str, str]:
+ """
+ return status symbols with customization
+ """
+ custom = {}
+ csv_config = Path(common.get_config_fname("symbols.csv"))
+ if csv_config.is_file():
+ with open(csv_config, "r") as f:
+ reader = csv.DictReader(f)
+ custom = next(reader)
+ default_symbols.update(custom)
+ return default_symbols
+
+
def get_repo_status(prop: Dict[str, str], no_colors=False) -> str:
- head = get_head(prop["path"])
- dirty, staged, untracked, color = _get_repo_status(prop, no_colors)
- info = f"{head:<10} [{dirty+staged+untracked}]"
- if color:
- return f"{color}{info:<17}{Color.end}"
- return f"{info:<17}"
+ branch = get_head(prop["path"])
+ dirty, staged, untracked, situ = _get_repo_status(prop)
+ symbols = get_symbols()
+ info = f"{branch:<10} [{symbols[dirty]+symbols[staged]+symbols[untracked]+symbols[situ]}]"
+
+ if no_colors:
+ return f"{info:<18}"
+ colors = {situ: Color[name].value for situ, name in get_color_encoding().items()}
+ color = colors[situ]
+ return f"{color}{info:<18}{Color.end}"
def get_repo_branch(prop: Dict[str, str]) -> str:
return get_head(prop["path"])
-def _get_repo_status(prop: Dict[str, str], no_colors: bool) -> Tuple[str]:
+def _get_repo_status(prop: Dict[str, str]) -> Tuple[str, str, str, str]:
"""
Return the status of one repo
"""
path = prop["path"]
flags = prop["flags"]
- dirty = "*" if run_quiet_diff(flags, [], path) else ""
- staged = "+" if run_quiet_diff(flags, ["--cached"], path) else ""
- untracked = "?" if has_untracked(flags, path) else ""
-
- if no_colors:
- return dirty, staged, untracked, ""
+ dirty = "dirty" if run_quiet_diff(flags, [], path) else ""
+ staged = "staged" if run_quiet_diff(flags, ["--cached"], path) else ""
+ untracked = "untracked" if has_untracked(flags, path) else ""
- colors = {situ: Color[name].value for situ, name in get_color_encoding().items()}
diff_returncode = run_quiet_diff(flags, ["@{u}", "@{0}"], path)
- has_no_remote = diff_returncode == 128
- has_no_diff = diff_returncode == 0
- if has_no_remote:
- color = colors["no-remote"]
- elif has_no_diff:
- color = colors["in-sync"]
+ if diff_returncode == 128:
+ situ = "no_remote"
+ elif diff_returncode == 0:
+ situ = "in_sync"
else:
common_commit = get_common_commit(path)
outdated = run_quiet_diff(flags, ["@{u}", common_commit], path)
if outdated:
diverged = run_quiet_diff(flags, ["@{0}", common_commit], path)
- color = colors["diverged"] if diverged else colors["remote-ahead"]
+ situ = "diverged" if diverged else "remote_ahead"
else: # local is ahead of remote
- color = colors["local-ahead"]
- return dirty, staged, untracked, color
+ situ = "local_ahead"
+ return dirty, staged, untracked, situ
ALL_INFO_ITEMS = {