diff --git a/Commands.md b/Commands.md index 39fd603..419525d 100644 --- a/Commands.md +++ b/Commands.md @@ -237,7 +237,7 @@ $ git effort bin/* lib/* ## git bulk -`git bulk` adds covenient support for operations that you want to execute on multiple git repositories. +`git bulk` adds convenient support for operations that you want to execute on multiple git repositories. * simply register workspaces that contain multiple git repos in their directory structure * run any git command on the repositories of the registered workspaces in one command to `git bulk` diff --git a/bin/git-bulk b/bin/git-bulk index 46672a6..692b62a 100755 --- a/bin/git-bulk +++ b/bin/git-bulk @@ -1,6 +1,6 @@ #!/usr/bin/env bash -invers=`tput rev` -reset=`tput sgr0` +invers=$(tput rev) +reset=$(tput sgr0) txtbld=$(tput bold) bldred=${txtbld}$(tput setaf 1) @@ -22,13 +22,13 @@ usage() { } # add another workspace to global git config -function addworkspace { git config --global bulkworkspaces.$wsname "$wsdir"; } +function addworkspace { git config --global bulkworkspaces."$wsname" "$wsdir"; } # add current directory -function addcurrent { git config --global bulkworkspaces.$wsname "$PWD"; } +function addcurrent { git config --global bulkworkspaces."$wsname" "$PWD"; } # remove workspace from global git config -function removeworkspace { checkWSName && git config --global --unset bulkworkspaces.$wsname; } +function removeworkspace { checkWSName && git config --global --unset bulkworkspaces."$wsname"; } # remove workspace from global git config function purge { git config --global --remove-section bulkworkspaces; } @@ -68,20 +68,26 @@ function checkGitCommand () { # check if workspace name is registered function checkWSName () { while read workspace; do - rwsname=$(echo $workspace | cut -f1 -d' ' | cut -f2 -d'.') - if [[ $rwsname == $wsname ]]; then return; fi + parseWsName "$workspace" + if [[ $rwsname == "$wsname" ]]; then return; fi done <<< "$(echo "$(listall)")" # when here the ws name was not found usage && echo "error: unknown workspace name: $wsname" && exit 1 } +# parse out wsname from workspacespec +function parseWsName () { + local wsspec="$1" + rwsdir=${wsspec#* } + rwsname=${wsspec#*.} && rwsname=${rwsname%% *} +} + # detects the wsname of the current directory function wsnameToCurrent () { while read workspace; do if [ -z "$workspace" ]; then continue; fi - rwsdir=${workspace#* } - rwsname=${workspace#*.} && rwsname=${rwsname% *} - if echo $PWD | grep -o -q $rwsdir; then wsname=$rwsname && return; fi + parseWsName "$workspace" + if echo "$PWD" | grep -o -q "$rwsdir"; then wsname="$rwsname" && return; fi done <<< "$(echo "$(listall)")" # when here then not in workspace dir echo "error: you are not in a workspace directory. your registered workspaces are:" && \ @@ -90,7 +96,7 @@ function wsnameToCurrent () { # helper to check number of arguments function allowedargcount () { - ( test $paramcount -ne $1 ) && ( usage && echo 1>&2 "error: wrong number of arguments" && exit 1 ) + ( test "$paramcount" -ne "$1" ) && ( usage && echo 1>&2 "error: wrong number of arguments" && exit 1 ) } # execute the bulk operation @@ -98,19 +104,18 @@ function executBulkOp () { checkGitCommand if ! $allwsmode && ! $singlemode; then wsnameToCurrent; fi # by default git bulk works within the 'current' workspace listall | while read workspacespec; do - cwsname=$(echo $workspacespec | cut -f1 -d' ' | cut -f2 -d'.') - if [[ -n $wsname ]] && [[ $cwsname != $wsname ]]; then continue; fi - wslocation=$(echo $workspacespec | cut -f2 -d' ') - eval cd "$wslocation" - actual=$(pwd) + parseWsName "$workspacespec" + if [[ -n $wsname ]] && [[ $rwsname != "$wsname" ]]; then continue; fi + eval cd "\"$rwsdir\"" + local actual=$(pwd) echo "Executing bulk operation in workspace ${invers}$actual${reset}" eval find . -name ".git" | while read line; do - 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 - curdir=$(pwd) + 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 + local curdir=$(pwd) echo "Current repository: ${actual#${curdir%/*}}/${bldred}${curdir##*/}${reset}" guardedExecution - eval cd "$wslocation" # back to origin location of last find command + eval cd "\"$rwsdir\"" # back to origin location of last find command done done } diff --git a/man/git-bulk.1 b/man/git-bulk.1 index e69de29..a4d2f8d 100644 --- a/man/git-bulk.1 +++ b/man/git-bulk.1 @@ -0,0 +1,125 @@ +.\" generated with Ronn/v0.7.3 +.\" http://github.com/rtomayko/ronn/tree/0.7.3 +. +.TH "GIT\-BULK" "1" "March 2017" "" "Git Extras" +. +.SH "NAME" +\fBgit\-bulk\fR \- Run git commands on multiple repositories +. +.SH "SYNOPSIS" +usage: usage: git bulk [\-g] ([\-a]|[\-w ]) git bulk \-\-addworkspace git bulk \-\-removeworkspace git bulk \-\-addcurrent git bulk \-\-purge git bulk \-\-listall +. +.SH "DESCRIPTION" +git bulk adds convenien support for operations that you want to execute on multiple git repositories\. +. +.IP "\(bu" 4 +simply register workspaces that contain multiple git repos in their directory structure +. +.IP "\(bu" 4 +run any git command on the repositories of the registered workspaces in one command to \fBgit bulk\fR +. +.IP "\(bu" 4 +use the "guarded mode" to check on each execution +. +.IP "" 0 +. +.SH "OPTIONS" +\-a +. +.P +Run a git command on all workspaces and their repositories\. +. +.P +\-g +. +.P +Ask the user for confirmation on every execution\. +. +.P +\-w +. +.P +Run the git command on the specified workspace\. The workspace must be registered\. +. +.P + +. +.P +Any git Command you wish to execute on the repositories\. +. +.P +\-\-addworkspace +. +.P +Register a workspace for bulk operations\. All repositories in the diretories below get registered under this workspace with the name \. +. +.P +\-\-removeworkspace +. +.P +Remove the workspace with the logical name \. +. +.P +\-\-addcurrent +. +.P +Adds the current directory as workspace to git bulk operations\. The workspace is referenced with its logical name \. +. +.P +git bulk \-\-purge +. +.P +Removes all defined repository locations\. +. +.P +git bulk \-\-listall +. +.P +List all registered repositories\. +. +.SH "EXAMPLES" +. +.nf + +Register a workspace so that git bulk knows about it: + +$ git bulk \-\-addworkspace personal ~/workspaces/personal + +Register the current directory as a workspace to git bulk: + +$ git bulk \-\-addcurrent personal + +List all registered workspaces: + +$ git bulk \-\-listall + +Run a git command on the repositories of the current workspace: + +$ git bulk fetch + +Run a git command on the specified workspace and its repositories: + +$ git bulk \-w personal fetch + +Run a git command but ask user for confirmation on every execution (guarded mode): + +$ git bulk \-g fetch + +Remove a registered workspace: + +$ git bulk \-\-removeworkspace personal + +Remove all registered workspaces: + +$ git bulk \-\-purge +. +.fi +. +.SH "AUTHOR" +Written by Niklas Schlimm <\fIns103@hotmail\.de\fR> +. +.SH "REPORTING BUGS" + +. +.SH "SEE ALSO" +<\fIhttps://github\.com/tj/git\-extras\fR> diff --git a/man/git-bulk.html b/man/git-bulk.html index e69de29..a5ac5ca 100644 --- a/man/git-bulk.html +++ b/man/git-bulk.html @@ -0,0 +1,191 @@ + + + + + + git-bulk(1) - Run git commands on multiple repositories + + + + +
+ + + +
    +
  1. git-bulk(1)
  2. +
  3. Git Extras
  4. +
  5. git-bulk(1)
  6. +
+ +

NAME

+

+ git-bulk - Run git commands on multiple repositories +

+ +

SYNOPSIS

+ +

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> + git bulk --purge + git bulk --listall

+ +

DESCRIPTION

+ +

git bulk adds convenien support for operations that you want to execute on multiple git repositories.

+ +
    +
  • simply register workspaces that contain multiple git repos in their directory structure
  • +
  • run any git command on the repositories of the registered workspaces in one command to git bulk
  • +
  • use the "guarded mode" to check on each execution
  • +
+ + +

OPTIONS

+ +

-a

+ +

Run a git command on all workspaces and their repositories.

+ +

-g

+ +

Ask the user for confirmation on every execution.

+ +

-w <ws-name>

+ +

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

+ +

<git command>

+ +

Any git Command you wish to execute on the repositories.

+ +

--addworkspace <ws-name> <ws-root-directory>

+ +

Register a workspace for bulk operations. All repositories in the diretories below <ws-root-directory> get registered under this workspace with the name <ws-name>.

+ +

--removeworkspace <ws-name>

+ +

Remove the workspace with the logical name <ws-name>.

+ +

--addcurrent <ws-name>

+ +

Adds the current directory as workspace to git bulk operations. The workspace is referenced with its logical name <ws-name>.

+ +

git bulk --purge

+ +

Removes all defined repository locations.

+ +

git bulk --listall

+ +

List all registered repositories.

+ +

EXAMPLES

+ +
Register a workspace so that git bulk knows about it:
+
+$ git bulk --addworkspace personal ~/workspaces/personal
+
+Register the current directory as a workspace to git bulk:
+
+$ git bulk --addcurrent personal
+
+List all registered workspaces:
+
+$ git bulk --listall
+
+Run a git command on the repositories of the current workspace:
+
+$ git bulk fetch
+
+Run a git command on the specified workspace and its repositories:
+
+$ git bulk -w personal fetch
+
+Run a git command but ask user for confirmation on every execution (guarded mode):
+
+$ git bulk -g fetch
+
+Remove a registered workspace:
+
+$ git bulk --removeworkspace personal
+
+Remove all registered workspaces:
+
+$ git bulk --purge
+
+ +

AUTHOR

+ +

Written by Niklas Schlimm <ns103@hotmail.de>

+ +

REPORTING BUGS

+ +

<https://github.com/nschlimm/git-bulk>

+ +

SEE ALSO

+ +

<https://github.com/tj/git-extras>

+ + +
    +
  1. +
  2. March 2017
  3. +
  4. git-bulk(1)
  5. +
+ +
+ + diff --git a/man/git-bulk.md b/man/git-bulk.md index 45e97b2..5b61feb 100644 --- a/man/git-bulk.md +++ b/man/git-bulk.md @@ -12,7 +12,7 @@ usage: usage: git bulk [-g] ([-a]|[-w <ws-name>]) <git command> ## DESCRIPTION -git bulk adds covenien support for operations that you want to execute on multiple git repositories. +git bulk adds convenien support for operations that you want to execute on multiple git repositories. - simply register workspaces that contain multiple git repos in their directory structure - run any git command on the repositories of the registered workspaces in one command to `git bulk`