Skip to content

Commit

Permalink
Merge pull request #83 from nosarthur/groups
Browse files Browse the repository at this point in the history
support group(s) for git commands
  • Loading branch information
nosarthur authored May 23, 2020
2 parents 946436a + bfa22cd commit b49d02a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ The bookkeeping sub-commands are
- `gita rm <repo-name(s)>`: remove repo(s) from `gita` (won't remove files from disk)
- `gita group`: show grouping of the repos
- `gita group <repo-name(s)>`: group repos
- `gita ungroup <repo-name(s)>`: remove grouping for repos
- `gita ll`: display the status of all repos
- `gita ll <group-name>`: display the status of repos in a group
- `gita ls`: display the names of all repos
Expand All @@ -64,8 +65,10 @@ Repo paths are saved in `$XDG_CONFIG_HOME/gita/repo_path` (most likely `~/.confi

The delegating sub-commands are of two formats

- `gita <sub-command> [repo-name(s)]`: optional repo input, and no input means all repos.
- `gita <sub-command> <repo-name(s)>`: required repo name(s) input
- `gita <sub-command> [repo-name(s) or group-name(s)]`:
optional repo or group input, and no input means all repos.
- `gita <sub-command> <repo-name(s) or groups-name(s)>`:
required repo name(s) or group name(s) input

By default, only `fetch` and `pull` take optional input.

Expand Down Expand Up @@ -139,10 +142,10 @@ The superman mode delegates any git command/alias.
Usage:

```
gita super [repo-name(s)] <any-git-command-with-or-without-options>
gita super [repo-name(s) or group-name(s)] <any-git-command-with-or-without-options>
```

Here `repo-name(s)` is optional, and absence means all repos.
Here `repo-name(s)` or `group-name(s)` are optional, and their absence means all repos.
For example,

- `gita super checkout master` puts all repos on the master branch
Expand Down
19 changes: 14 additions & 5 deletions gita/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,16 @@ def f_git_cmd(args: argparse.Namespace):
disabled for commands in the `args.async_blacklist`.
"""
repos = utils.get_repos()
if args.repo: # with user specified repo(s)
repos = {k: repos[k] for k in args.repo}
groups = utils.get_groups()
if args.repo: # with user specified repo(s) or group(s)
chosen = {}
for k in args.repo:
if k in repos:
chosen[k] = repos[k]
if k in groups:
for r in groups[k].split():
chosen[r] = repos[r]
repos = chosen
cmds = ['git'] + args.cmd
if len(repos) == 1 or cmds[1] in args.async_blacklist:
for path in repos.values():
Expand All @@ -136,8 +144,9 @@ def f_super(args):
"""
names = []
repos = utils.get_repos()
groups = utils.get_groups()
for i, word in enumerate(args.man):
if word in repos:
if word in repos or word in groups:
names.append(word)
else:
break
Expand Down Expand Up @@ -255,9 +264,9 @@ def main(argv=None):
nargs = '*'
help += ' for all repos or'
else:
choices = utils.get_repos()
choices = utils.get_repos().keys() | utils.get_groups().keys()
nargs = '+'
help += ' for the chosen repo(s)'
help += ' for the chosen repo(s) or group(s)'
sp = subparsers.add_parser(name, help=help)
sp.add_argument('repo', nargs=nargs, choices=choices, help=help)
sp.set_defaults(func=f_git_cmd, cmd=cmd.split())
Expand Down
10 changes: 6 additions & 4 deletions gita/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,17 @@ def get_groups() -> Dict[str, str]:

def get_choices() -> List[Union[str, None]]:
"""
Return all repo names and an additional empty list. This is a workaround of
Return all repo names, group names, and an additional empty list. The empty
list is added as a workaround of
argparse's problem with coexisting nargs='*' and choices.
See https://utcc.utoronto.ca/~cks/space/blog/python/ArgparseNargsChoicesLimitation
and
https://bugs.python.org/issue27227
"""
repos = list(get_repos())
repos.append([])
return repos
choices = list(get_repos())
choices.extend(get_groups())
choices.append([])
return choices


def is_git(path: str) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
setup(
name='gita',
packages=['gita'],
version='0.10.7',
version='0.10.8',
license='MIT',
description='Manage multiple git repos',
long_description=long_description,
Expand Down

0 comments on commit b49d02a

Please sign in to comment.