From 8eed5f49ad8e7fbed7c72b11cc27afadd6fee91d Mon Sep 17 00:00:00 2001 From: Pierre Ayoub Date: Thu, 27 Feb 2025 07:18:16 +0100 Subject: [PATCH] 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` --- bin/git-bulk | 15 +++++++++++++-- man/git-bulk.1 | 6 +++++- man/git-bulk.html | 6 +++++- man/git-bulk.md | 6 +++++- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/bin/git-bulk b/bin/git-bulk index ab5898e..fe58e48 100755 --- a/bin/git-bulk +++ b/bin/git-bulk @@ -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 ]) " + echo 1>&2 "usage: git bulk [--no-follow-symlinks] [-q|--quiet] [-g] ([-a]|[-w ]) " echo 1>&2 " git bulk --addworkspace (--from )" echo 1>&2 " git bulk --removeworkspace " echo 1>&2 " git bulk --addcurrent " @@ -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) diff --git a/man/git-bulk.1 b/man/git-bulk.1 index 69a6a38..0ed0a14 100644 --- a/man/git-bulk.1 +++ b/man/git-bulk.1 @@ -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 .P Run the git command on the specified workspace\. The workspace must be registered\. diff --git a/man/git-bulk.html b/man/git-bulk.html index 7fe7689..66b0e17 100644 --- a/man/git-bulk.html +++ b/man/git-bulk.html @@ -78,7 +78,7 @@

SYNOPSIS

-

git-bulk [-g] ([-a]|[-w ])
+

git-bulk [-g] [--no-follow-symlinks] ([-a]|[-w ])
git-bulk --addworkspace (--from )
git-bulk --removeworkspace <ws-name>
git-bulk --addcurrent <ws-name>
@@ -106,6 +106,10 @@

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 <ws-name>

Run the git command on the specified workspace. The workspace must be registered.

diff --git a/man/git-bulk.md b/man/git-bulk.md index 4dca4d3..f5550d5 100644 --- a/man/git-bulk.md +++ b/man/git-bulk.md @@ -3,7 +3,7 @@ git-bulk(1) -- Run git commands on multiple repositories ## SYNOPSIS -`git-bulk` [-g] ([-a]|[-w <ws-name>]) <git command>
+`git-bulk` [-g] [--no-follow-symlinks] ([-a]|[-w <ws-name>]) <git command>
`git-bulk` --addworkspace <ws-name> <ws-root-directory> (--from <URL or file>)
`git-bulk` --removeworkspace <ws-name>
`git-bulk` --addcurrent <ws-name>
@@ -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 <ws-name> Run the git command on the specified workspace. The workspace must be registered.