From 433c488df46655339a340a6fcea7481ef94bebdf Mon Sep 17 00:00:00 2001 From: Pierre Ayoub Date: Sat, 15 Feb 2025 22:03:14 +0100 Subject: [PATCH 1/9] fix(git-bulk): fix workspace selection when cd fails `cd` may fails for multiple reasons: - mistake when editing `.gitconfig` manually - previously existing workspace that have been removed - ... Currently, if `cd` fails, the `BulkOp` continue its execution ... in the workspace defined in a higher directory that where the user, despite the user specified a specific workspace (`-w`). The user should be noticed of a failed `cd` (this is really not expected for a valid configuration) and the operations should stop to not execute something unexpected. --- bin/git-bulk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/git-bulk b/bin/git-bulk index e3bdd66d6..830ad875c 100755 --- a/bin/git-bulk +++ b/bin/git-bulk @@ -142,7 +142,7 @@ function executBulkOp () { listall | while read -r workspacespec; do parseWsName "$workspacespec" if [[ -n $wsname ]] && [[ $rwsname != "$wsname" ]]; then continue; fi - eval cd "\"$rwsdir\"" + eval cd "\"$rwsdir\"" || exit 1 local actual=$PWD [ "${quiet?}" != "true" ] && echo 1>&2 "Executing bulk operation in workspace ${inverse}$actual${reset}" @@ -150,11 +150,11 @@ function executBulkOp () { for line in "${allGitFolders[@]}"; do local gitrepodir=${line::${#line}-5} # cut the .git part of find results to have the root git directory of that repository - eval cd "\"$gitrepodir\"" # into git repo location + eval cd "\"$gitrepodir\"" || exit 1 # into git repo location local curdir=$PWD local leadingpath=${curdir#"${actual}"} guardedExecution "$@" - eval cd "\"$rwsdir\"" # back to origin location of last find command + eval cd "\"$rwsdir\"" || exit 1 # back to origin location of last find command done done } From 7daedfd169f4a247cbdf7f6d8e9e0d60ac316ff3 Mon Sep 17 00:00:00 2001 From: Pierre Ayoub Date: Thu, 20 Feb 2025 16:17:44 +0100 Subject: [PATCH 2/9] fix(git-bulk): replace weak eval for better variable substitution Get rid of poor `eval` syntax because they are vulnerable to command injection, which may have unexpected side effects. However, they enabled a useful feature: using environment variable (*e.g.*, defined in a `.bashrc`) inside the `.gitconfig` to use dynamic paths as `bulk` workspaces. As such, I keep this feature possible by using the Bash's ${!VAR} syntax, which allows to get the value of one variable using the name of a another variable. However, arbitrary command injection is not possible anymore. --- bin/git-bulk | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/bin/git-bulk b/bin/git-bulk index 830ad875c..8d6d9db99 100755 --- a/bin/git-bulk +++ b/bin/git-bulk @@ -111,7 +111,14 @@ function checkWSName () { # parse out wsname from workspacespec function parseWsName () { local wsspec="$1" + # Get the workspace value from its specification in the `.gitconfig`. + # May be an absolute path or a variable name of the form: `$VARNAME` rwsdir=${wsspec#* } + if [[ ${rwsdir:0:1} == '$' ]]; then + # Dereference the `rwsdir` value which is a variable name. + rwsdir=${rwsdir:1} + rwsdir=${!rwsdir} + fi rwsname=${wsspec#*.} && rwsname=${rwsname%% *} } @@ -142,7 +149,7 @@ function executBulkOp () { listall | while read -r workspacespec; do parseWsName "$workspacespec" if [[ -n $wsname ]] && [[ $rwsname != "$wsname" ]]; then continue; fi - eval cd "\"$rwsdir\"" || exit 1 + cd "$rwsdir" || exit 1 local actual=$PWD [ "${quiet?}" != "true" ] && echo 1>&2 "Executing bulk operation in workspace ${inverse}$actual${reset}" @@ -150,11 +157,11 @@ function executBulkOp () { for line in "${allGitFolders[@]}"; do local gitrepodir=${line::${#line}-5} # cut the .git part of find results to have the root git directory of that repository - eval cd "\"$gitrepodir\"" || exit 1 # into git repo location + cd "$gitrepodir" || exit 1 # into git repo location local curdir=$PWD local leadingpath=${curdir#"${actual}"} guardedExecution "$@" - eval cd "\"$rwsdir\"" || exit 1 # back to origin location of last find command + cd "$rwsdir" || exit 1 # back to origin location of last find command done done } From 145ecdd8fac31f907e78433191eac07dd45e063c Mon Sep 17 00:00:00 2001 From: Pierre Ayoub Date: Mon, 24 Feb 2025 17:02:22 +0100 Subject: [PATCH 3/9] fix(git-bulk): missing check about empty environnement variable --- bin/git-bulk | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bin/git-bulk b/bin/git-bulk index 8d6d9db99..23c8abf81 100755 --- a/bin/git-bulk +++ b/bin/git-bulk @@ -116,8 +116,11 @@ function parseWsName () { rwsdir=${wsspec#* } if [[ ${rwsdir:0:1} == '$' ]]; then # Dereference the `rwsdir` value which is a variable name. - rwsdir=${rwsdir:1} - rwsdir=${!rwsdir} + rwsdir_varname=${rwsdir:1} + rwsdir=${!rwsdir_varname} + if [[ -z "${rwsdir}" ]]; then + echo 1>&2 "error: bad environnement variable: $rwsdir_varname" && exit 1 + fi fi rwsname=${wsspec#*.} && rwsname=${rwsname%% *} } From b6e359d92d87c9c378ada8f5a3d1fde26f849eae Mon Sep 17 00:00:00 2001 From: Pierre Ayoub Date: Mon, 24 Feb 2025 17:04:14 +0100 Subject: [PATCH 4/9] style(git-bulk): typo --- bin/git-bulk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/git-bulk b/bin/git-bulk index 23c8abf81..0a596542f 100755 --- a/bin/git-bulk +++ b/bin/git-bulk @@ -119,7 +119,7 @@ function parseWsName () { rwsdir_varname=${rwsdir:1} rwsdir=${!rwsdir_varname} if [[ -z "${rwsdir}" ]]; then - echo 1>&2 "error: bad environnement variable: $rwsdir_varname" && exit 1 + echo 1>&2 "error: bad environment variable: $rwsdir_varname" && exit 1 fi fi rwsname=${wsspec#*.} && rwsname=${rwsname%% *} From ebb6d37c1563557bd54524a9aba71ad68b4cb299 Mon Sep 17 00:00:00 2001 From: Pierre Ayoub Date: Mon, 24 Feb 2025 17:33:10 +0100 Subject: [PATCH 5/9] docs(Commands.md): git-bulk env var feature --- Commands.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Commands.md b/Commands.md index de98cef4c..1085ba7ba 100644 --- a/Commands.md +++ b/Commands.md @@ -280,11 +280,20 @@ usage: git bulk [-g] ([-a]|[-w ]) git bulk --listall ``` - Register a workspace so that `git bulk` knows about it (notice that must be absolute path): + Register a workspace so that `git bulk` knows about it (it will be registered in your `.gitconfig`): ```bash $ git bulk --addworkspace personal ~/workspaces/personal ``` + + Notice that `` must be an absolute path (or an environment variable pointing to an absolute path). + In the case of a **single quoted environment variable**, it will be dereferenced at `git-bulk` runtime, suitable for dynamic workspaces (*e.g.*, defined in your `.bashrc`). + As an illustration: + +```bash +$ git bulk --addworkspace personal '$PERSONAL_WORKSPACE' +``` + With option `--from` the URL to a single repository or a file containing multiple URLs can be added and they will be cloned directly into the workspace. Suitable for the initial setup of a multi-repo project. ```bash From 4054cb3451b0d91faa69b44358dc15b32c7108ba Mon Sep 17 00:00:00 2001 From: Pierre Ayoub Date: Mon, 24 Feb 2025 17:33:52 +0100 Subject: [PATCH 6/9] docs(man/git-bulk): git-bulk env var feature --- man/git-bulk.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/man/git-bulk.md b/man/git-bulk.md index 80edda485..293c25a6f 100644 --- a/man/git-bulk.md +++ b/man/git-bulk.md @@ -60,10 +60,14 @@ git bulk adds convenient support for operations that you want to execute on mult ## EXAMPLES - Register a workspace so that git bulk knows about it: + Register a workspace so that git bulk knows about it using an absolute path: $ git bulk --addworkspace personal ~/workspaces/personal + Or register a workspace using an environement variable pointing to an absolute path: + + $ git bulk --addworkspace personal '$PERSONAL_WORKSPACE' + Use option --from in order to directly clone a repository or multiple repositories $ git bulk --addworkspace personal ~/workspaces/personal --from https://github.com/tj/git-extras.git From 0e4b6c419705bd6a2e301b2ed6a065335a07cc96 Mon Sep 17 00:00:00 2001 From: Pierre Ayoub Date: Mon, 24 Feb 2025 17:34:02 +0100 Subject: [PATCH 7/9] docs(man/git-bulk): mention .gitconfig for config storage --- man/git-bulk.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/man/git-bulk.md b/man/git-bulk.md index 293c25a6f..ca50e3ebf 100644 --- a/man/git-bulk.md +++ b/man/git-bulk.md @@ -108,6 +108,10 @@ git bulk adds convenient support for operations that you want to execute on mult $ git bulk --purge +## FILES + +- `.gitconfig`: Store the `git-bulk` registered workspaces under the `bulkworkspaces` key. + ## AUTHOR Written by Niklas Schlimm <> From b2c7a9c77d5460c01b4181bba7a8dad9eae0fa03 Mon Sep 17 00:00:00 2001 From: Pierre Ayoub Date: Mon, 24 Feb 2025 17:38:01 +0100 Subject: [PATCH 8/9] style(man/git-bulk): typo --- man/git-bulk.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/git-bulk.md b/man/git-bulk.md index ca50e3ebf..4dca4d32e 100644 --- a/man/git-bulk.md +++ b/man/git-bulk.md @@ -64,7 +64,7 @@ git bulk adds convenient support for operations that you want to execute on mult $ git bulk --addworkspace personal ~/workspaces/personal - Or register a workspace using an environement variable pointing to an absolute path: + Or register a workspace using an environment variable pointing to an absolute path: $ git bulk --addworkspace personal '$PERSONAL_WORKSPACE' From 9a731a8a72721646b14e800f78032efd137e7e85 Mon Sep 17 00:00:00 2001 From: Pierre Ayoub Date: Mon, 24 Feb 2025 17:57:25 +0100 Subject: [PATCH 9/9] docs(man/git-bulk): run make/ronn for .1 and .html --- man/git-bulk.1 | 12 ++++++++++-- man/git-bulk.html | 16 ++++++++++++++-- man/index.txt | 2 +- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/man/git-bulk.1 b/man/git-bulk.1 index 1266608c0..69a6a38c8 100644 --- a/man/git-bulk.1 +++ b/man/git-bulk.1 @@ -1,6 +1,6 @@ .\" generated with Ronn-NG/v0.9.1 .\" http://github.com/apjanke/ronn-ng/tree/0.9.1 -.TH "GIT\-BULK" "1" "September 2024" "" "Git Extras" +.TH "GIT\-BULK" "1" "February 2025" "" "Git Extras" .SH "NAME" \fBgit\-bulk\fR \- Run git commands on multiple repositories .SH "SYNOPSIS" @@ -64,10 +64,14 @@ git bulk \-\-listall List all registered repositories\. .SH "EXAMPLES" .nf -Register a workspace so that git bulk knows about it: +Register a workspace so that git bulk knows about it using an absolute path: $ git bulk \-\-addworkspace personal ~/workspaces/personal +Or register a workspace using an environment variable pointing to an absolute path: + +$ git bulk \-\-addworkspace personal '$PERSONAL_WORKSPACE' + Use option \-\-from in order to directly clone a repository or multiple repositories $ git bulk \-\-addworkspace personal ~/workspaces/personal \-\-from https://github\.com/tj/git\-extras\.git @@ -108,6 +112,10 @@ Remove all registered workspaces: $ git bulk \-\-purge .fi +.SH "FILES" +.IP "\[ci]" 4 +\fB\.gitconfig\fR: Store the \fBgit\-bulk\fR registered workspaces under the \fBbulkworkspaces\fR key\. +.IP "" 0 .SH "AUTHOR" Written by Niklas Schlimm <\fIns103@hotmail\.de\fR> .SH "REPORTING BUGS" diff --git a/man/git-bulk.html b/man/git-bulk.html index de121b149..7fe768905 100644 --- a/man/git-bulk.html +++ b/man/git-bulk.html @@ -58,6 +58,7 @@ DESCRIPTION OPTIONS EXAMPLES + FILES AUTHOR REPORTING BUGS SEE ALSO @@ -137,10 +138,14 @@

OPTIONS

EXAMPLES

-
Register a workspace so that git bulk knows about it:
+
Register a workspace so that git bulk knows about it using an absolute path:
 
 $ git bulk --addworkspace personal ~/workspaces/personal
 
+Or register a workspace using an environment variable pointing to an absolute path:
+
+$ git bulk --addworkspace personal '$PERSONAL_WORKSPACE'
+
 Use option --from in order to directly clone a repository or multiple repositories 
 
 $ git bulk --addworkspace personal ~/workspaces/personal --from https://github.com/tj/git-extras.git
@@ -182,6 +187,13 @@ 

EXAMPLES

$ git bulk --purge
+

FILES

+ +
    +
  • +.gitconfig: Store the git-bulk registered workspaces under the bulkworkspaces key.
  • +
+

AUTHOR

Written by Niklas Schlimm <ns103@hotmail.de>

@@ -196,7 +208,7 @@

SEE ALSO

  1. -
  2. September 2024
  3. +
  4. February 2025
  5. git-bulk(1)
diff --git a/man/index.txt b/man/index.txt index c4c716814..5e98b173c 100644 --- a/man/index.txt +++ b/man/index.txt @@ -12,8 +12,8 @@ git-clear-soft(1) git-clear-soft git-clear(1) git-clear git-coauthor(1) git-coauthor git-commits-since(1) git-commits-since -git-contrib(1) git-contrib git-continue(1) git-continue +git-contrib(1) git-contrib git-count(1) git-count git-cp(1) git-cp git-create-branch(1) git-create-branch