If you can come up with how to show branch name and repo's status
The idea is to:
First, chose any config key name you want.
For example: "list.repos
"
Reinitialize the list, using git config --unset-all
(in the global config file):
git config --global --unset-all list.repos
Then use either:
Redirect the result in a file 'list-repos.txt', then register those repositories, reading each line of the file:
while IFS="" read -r repo || [ -n "${repo}" ]
do
git config --global --add list.repos ${repo}
done < list-repos.txt
Once your repositories are registered (as global git config values), it is trivial to loop over them using the new command git for-each-repo
, executing any command you need.
With Git 2.30 (Q4 2020), a new command is introduced, initially to manage parts of "git maintenance
"(man) and to ease writing crontab entries (and other scheduling system configuration) for it.
See commit 0016b61, commit 61f7a38, commit a4cb1a2 (15 Oct 2020), commit 2fec604, commit 0c18b70, commit 4950b2a, commit b08ff1f (11 Sep 2020), and commit 1942d48 (28 Aug 2020) by Derrick Stolee (derrickstolee
).
(Merged by Junio C Hamano -- gitster
-- in commit 7660da1, 18 Nov 2020)
for-each-repo
: run subcommands on configured repos
Signed-off-by: Derrick Stolee
It can be helpful to store a list of repositories in global or system config and then iterate Git commands on that list.
Create a new builtin that makes this process simple for experts.
We will use this builtin to run scheduled maintenance on all configured repositories in a future change.
The test is very simple, but does highlight that the "--
" argument is optional.
git for-each-repo
now includes in its man page:
git-for-each-repo(1)
NAME
git-for-each-repo
- Run a Git command on a list of repositories
SYNOPSIS
[verse]
'git for-each-repo' --config=<config> [--] <arguments>
DESCRIPTION
Run a Git command on a list of repositories. The arguments after the
known options or --
indicator are used as the arguments for the Git
subprocess.
THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE.
For example, we could run maintenance on each of a list of repositories
stored in a maintenance.repo
config variable using
git for-each-repo --config=maintenance.repo maintenance run
This will run git -C <repo> maintenance run
for each value <repo>
in the multi-valued config variable maintenance.repo
.
OPTIONS
--config=<config>
Use the given config variable as a multi-valued list storing
absolute path names. Iterate on that list of paths to run
the given arguments.
These config values are loaded from system, global, and local Git config,
as available. If git for-each-repo
is run in a directory that is not a
Git repository, then only the system and global config is used.
SUBPROCESS BEHAVIOR
If any git -C <repo> <arguments>
subprocess returns a non-zero exit code,
then the git for-each-repo
process returns that exit code without running
more subprocesses.
Each git -C <repo> <arguments>
subprocess inherits the standard file
descriptors stdin
, stdout
, and stderr
.
With Git 2.30.1 (Q1 2021), "git for-each-repo --config=<var> <cmd>
"(man) should not run <cmd>
for any repository when the configuration variable <var>
is not defined even once.
See commit 6c62f01 (08 Jan 2021) by Derrick Stolee (derrickstolee
).
(Merged by Junio C Hamano -- gitster
-- in commit aa08688, 15 Jan 2021)
for-each-repo
: do nothing on empty config
Reported-by: Andreas Bühmann
Helped-by: Eric Sunshine
Helped-by: Junio C Hamano
Signed-off-by: Derrick Stolee
'git for-each-repo --config=X
'(man) should return success without calling any subcommands when the config key 'X
' has no value.
The current implementation instead segfaults.
A user could run into this issue if they used 'git maintenance start
'(man) to initialize their cron schedule using 'git for-each-repo --config=maintenance.repo ...
'(man) but then using 'git maintenance unregister
'(man) to remove the config option.
(Note: 'git maintenance stop
'(man) would remove the config and remove the cron schedule.)
Add a simple test to ensure this works.
Use 'git help --no-such-option
'(man) as the potential subcommand to ensure that we will hit a failure if the subcommand is ever run.