From d3cccebbd26bfb9952b24a94812635a9996d0d04 Mon Sep 17 00:00:00 2001 From: Niklas Schlimm Date: Fri, 17 Mar 2017 17:13:15 +0100 Subject: [PATCH] Current workspace is default target of bulk operations --- Commands.md | 12 ++++++++--- bin/git-bulk | 53 ++++++++++++++++++++++++++++++++++++------------- man/git-bulk.md | 16 +++++++++------ 3 files changed, 58 insertions(+), 23 deletions(-) diff --git a/Commands.md b/Commands.md index e8e6975..d271665 100644 --- a/Commands.md +++ b/Commands.md @@ -244,7 +244,7 @@ $ git effort bin/* lib/* * use the "guarded mode" to check on each execution ```bash -usage: git bulk [-g] [-w ] +usage: git bulk [-g] ([-a]|[-w ]) git bulk --addworkspace git bulk --removeworkspace git bulk --addcurrent @@ -271,7 +271,7 @@ $ git bulk --listall bulkworkspaces.personal /Users/niklasschlimm/workspaces/personal ``` - Run a git command on the repositories: + Run a git command on the repositories of the current workspace: ```bash $ git bulk fetch @@ -279,7 +279,13 @@ $ git bulk fetch ![fetchdemo](https://cloud.githubusercontent.com/assets/876604/23709805/e8178406-041a-11e7-9a0c-01de5fbf8944.png) - Run a git command on only one workspace ans its repositories: + Run a git command on one specific workspace and its repositories: + +```bash +$ git bulk -w personal fetch +``` + + Run a git command on all workspaces and their repositories: ```bash $ git bulk -w personal fetch diff --git a/bin/git-bulk b/bin/git-bulk index a135dc5..82ad630 100755 --- a/bin/git-bulk +++ b/bin/git-bulk @@ -3,15 +3,17 @@ invers=`tput rev` reset=`tput sgr0` txtbld=$(tput bold) bldred=${txtbld}$(tput setaf 1) -shopt -s extglob -guarded=false + +# default option settings +guardedmode=false singlemode=false +allwsmode=false # # print usage message # usage() { - echo 1>&2 "usage: git bulk [-g] [-w ] " + echo 1>&2 "usage: git bulk [-g] ([-a]|[-w ]) " echo 1>&2 " git bulk --addworkspace " echo 1>&2 " git bulk --removeworkspace " echo 1>&2 " git bulk --addcurrent " @@ -36,10 +38,10 @@ function listall { git config --global --get-regexp bulkworkspaces; } # guarded execution of a git command in one specific repository function guardedExecution () { - if $guarded; then + if $guardedmode; then echo -n "${invers}git $gitcommand${reset} -> execute here (y/n)? " read -n 1 -r '} +} + # helper to check number of arguments function allowedargcount () { ( test $initialcount -ne $1 ) && ( usage && echo 1>&2 "error: wrong number of arguments" && exit 1 ) @@ -81,11 +96,11 @@ function allowedargcount () { # execute the bulk operation function executBulkOp () { + if ! $allwsmode && ! $singlemode; then wsnameToCurrent; fi # by default git bulk works within the 'current' workspace checkGitCommand - ( [[ $singlemode ]] ) && ( echo "Selected single workspace mode in workspace: $wsname" && checkWSName ) listall | while read workspacespec; do cwsname=$(echo $workspacespec | cut -f1 -d' ' | cut -f2 -d'.') - if $singlemode && [[ $cwsname != $wsname ]]; then continue; fi + if [[ -n $wsname ]] && [[ $cwsname != $wsname ]]; then continue; fi wslocation=$(echo $workspacespec | cut -f2 -d' ') eval cd "$wslocation" actual=$(pwd) @@ -104,15 +119,19 @@ function executBulkOp () { initialcount="${#}" # if no arguments show usage -( [[ $initialcount -le 0 ]] ) && usage +if [[ $initialcount -le 0 ]]; then usage; fi # parse command parameters while [ "${#}" -ge 1 ] ; do case "$1" in - --listall|--purge|--removeworkspace|--addcurrent|--addworkspace) + --listall|--purge) + butilcommand="${1:2}" && break ;; + --removeworkspace|--addcurrent|--addworkspace) butilcommand="${1:2}" && shift && wsname="$1" && shift && wsdir="$1" && break ;; + -a) + allwsmode=true ;; -g) - guarded=true ;; + guardedmode=true ;; -w) singlemode=true && shift && wsname="$1" && checkWSName ;; -*) @@ -124,10 +143,16 @@ while [ "${#}" -ge 1 ] ; do esac && shift done +# check option compatability +if $allwsmode && $singlemode; then echo 1>&2 "error: options -w and -a are incompatible" && exit 1; fi + +# if single mode check the supplied workspace name +if $singlemode; then echo "Selected single workspace mode in workspace: $wsname" && checkWSName; fi + # check right number of arguments case $butilcommand in - @(listall|purge) ) allowedargcount 1;; - @(addcurrent|removeworkspace)) allowedargcount 2;; + listall|purge) allowedargcount 1;; + addcurrent|removeworkspace) allowedargcount 2;; addworkspace) allowedargcount 3;; esac diff --git a/man/git-bulk.md b/man/git-bulk.md index 0539b2b..8688926 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 -usage: git bulk [-g] [-w <ws-name>] <git command> +usage: usage: git bulk [-g] ([-a]|[-w <ws-name>]) <git command> git bulk --addworkspace <ws-name> <ws-root-directory> git bulk --removeworkspace <ws-name> git bulk --addcurrent <ws-name> @@ -20,17 +20,21 @@ git bulk adds covenien support for operations that you want to execute on multip ## OPTIONS + -a + + Run a GIT command on all workspaces and their repositories. + -g Ask the user for confitmation on every execution. - -w + -w <ws-name> - Run the GIT command only on the specified workspace. The workspace must be registered. + Run the GIT command on the specified workspace. The workspace must be registered. <git command> - Any GIT Command you wish to execute on all the Repositories. + Any GIT Command you wish to execute on the repositories. --addworkspace <ws-name> <ws-root-directory> @@ -66,11 +70,11 @@ git bulk adds covenien support for operations that you want to execute on multip $ git bulk --listall - Run a git command on the repositories: + Run a git command on the repositories of the current workspace: $ git bulk fetch - Run a git command on only one workspace and its repositories: + Run a git command on the specified workspace and its repositories: $ git bulk -w personal fetch