feat(git-bulk): add new option to no follow symlinks (#1194)

* feat(git-bulk): add --no-follow-symlinks flag

* docs(git-bulk): add --no-follow-symlinks description

* docs(man): make ronn

* docs(git-bulk): put --no-follow-symlinks at right place in usage()

* fix(git-bulk): use readarray for find command

1. Use `readarray` such that we can handle paths with spaces
2. Remove the unnecessary `eval`
This commit is contained in:
Pierre Ayoub 2025-02-27 07:18:16 +01:00 committed by GitHub
parent 64687599ae
commit 8eed5f49ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 28 additions and 5 deletions

View file

@ -9,12 +9,13 @@ guardedmode=false
singlemode=false
allwsmode=false
quiet=false
no_follow_symlinks=false
#
# print usage message
#
usage() {
echo 1>&2 "usage: git bulk [-q|--quiet] [-g] ([-a]|[-w <ws-name>]) <git command>"
echo 1>&2 "usage: git bulk [--no-follow-symlinks] [-q|--quiet] [-g] ([-a]|[-w <ws-name>]) <git command>"
echo 1>&2 " git bulk --addworkspace <ws-name> <ws-root-directory> (--from <URL or file>)"
echo 1>&2 " git bulk --removeworkspace <ws-name>"
echo 1>&2 " git bulk --addcurrent <ws-name>"
@ -156,7 +157,15 @@ function executBulkOp () {
local actual=$PWD
[ "${quiet?}" != "true" ] && echo 1>&2 "Executing bulk operation in workspace ${inverse}$actual${reset}"
allGitFolders=( $(eval find -L . -name ".git" 2>/dev/null) )
# build `find` flags depending on command-line options
local find_flags=()
if [[ "$no_follow_symlinks" == true ]]; then
find_flags+=(-P)
else
find_flags+=(-L)
fi
# find all git repositories under the workspace on which we want to operate
readarray allGitFolders < <(find "${find_flags[@]}" . -name ".git" 2>/dev/null)
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
@ -182,6 +191,8 @@ while [ "${#}" -ge 1 ] ; do
butilcommand="${1:2}" && break ;;
--removeworkspace|--addcurrent|--addworkspace)
butilcommand="${1:2}" && wsname="$2" && wsdir="$3" && if [ "$4" == "--from" ]; then source="$5"; fi && break ;;
--no-follow-symlinks)
no_follow_symlinks=true ;;
-a)
allwsmode=true ;;
-g)

View file

@ -4,7 +4,7 @@
.SH "NAME"
\fBgit\-bulk\fR \- Run git commands on multiple repositories
.SH "SYNOPSIS"
\fBgit\-bulk\fR [\-g] ([\-a]|[\-w
\fBgit\-bulk\fR [\-g] [\-\-no\-follow\-symlinks] ([\-a]|[\-w
.br
\fBgit\-bulk\fR \-\-addworkspace
.br
@ -33,6 +33,10 @@ Run a git command on all workspaces and their repositories\.
.P
Ask the user for confirmation on every execution\.
.P
\-\-no\-follow\-symlinks
.P
Do not traverse symbolic links under the workspace when searching for git repositories\.
.P
\-w <ws\-name>
.P
Run the git command on the specified workspace\. The workspace must be registered\.

View file

@ -78,7 +78,7 @@
</p>
<h2 id="SYNOPSIS">SYNOPSIS</h2>
<p><code>git-bulk</code> [-g] ([-a]|[-w <ws-name>]) <git command> </git></ws-name><br>
<p><code>git-bulk</code> [-g] [--no-follow-symlinks] ([-a]|[-w <ws-name>]) <git command> </git></ws-name><br>
<code>git-bulk</code> --addworkspace <ws-name> <ws-root-directory> (--from <url or file>) </url></ws-root-directory></ws-name><br>
<code>git-bulk</code> --removeworkspace &lt;ws-name&gt; <br>
<code>git-bulk</code> --addcurrent &lt;ws-name&gt; <br>
@ -106,6 +106,10 @@
<p>Ask the user for confirmation on every execution.</p>
<p>--no-follow-symlinks</p>
<p>Do not traverse symbolic links under the workspace when searching for git repositories.</p>
<p>-w &lt;ws-name&gt;</p>
<p>Run the git command on the specified workspace. The workspace must be registered.</p>

View file

@ -3,7 +3,7 @@ git-bulk(1) -- Run git commands on multiple repositories
## SYNOPSIS
`git-bulk` [-g] ([-a]|[-w &lt;ws-name&gt;]) &lt;git command&gt; <br/>
`git-bulk` [-g] [--no-follow-symlinks] ([-a]|[-w &lt;ws-name&gt;]) &lt;git command&gt; <br/>
`git-bulk` --addworkspace &lt;ws-name&gt; &lt;ws-root-directory&gt; (--from &lt;URL or file&gt;) <br/>
`git-bulk` --removeworkspace &lt;ws-name&gt; <br/>
`git-bulk` --addcurrent &lt;ws-name&gt; <br/>
@ -28,6 +28,10 @@ git bulk adds convenient support for operations that you want to execute on mult
Ask the user for confirmation on every execution.
--no-follow-symlinks
Do not traverse symbolic links under the workspace when searching for git repositories.
-w &lt;ws-name&gt;
Run the git command on the specified workspace. The workspace must be registered.