Skip to content
Merged
13 changes: 10 additions & 3 deletions bin/git-bulk
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we exit 1 when $rwsdir is expanded to ""?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right! Fixed in 145ecdd. :)

fi
rwsname=${wsspec#*.} && rwsname=${rwsname%% *}
}

Expand Down Expand Up @@ -142,19 +149,19 @@ function executBulkOp () {
listall | while read -r workspacespec; do
parseWsName "$workspacespec"
if [[ -n $wsname ]] && [[ $rwsname != "$wsname" ]]; then continue; fi
eval cd "\"$rwsdir\""
cd "$rwsdir" || exit 1
local actual=$PWD
[ "${quiet?}" != "true" ] && echo 1>&2 "Executing bulk operation in workspace ${inverse}$actual${reset}"

allGitFolders=( $(eval find -L . -name ".git") )

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
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
cd "$rwsdir" || exit 1 # back to origin location of last find command
done
done
}
Expand Down
Loading