From 16bb0df9f9da39d32e3d2a25545200b26586debe Mon Sep 17 00:00:00 2001
From: Roshak Zarhoun
Date: Tue, 10 Dec 2019 14:57:32 +0100
Subject: [PATCH] add repositories to workspace from source (#804)
* make addworkspace clone multiple repositories into ws from list of URLs in a file
* extend usage
* check if source is file or URL
* update Commands.md
* checked allwedargcount function
* resolved merge conflicts and change requests
* update manuals
* change the order of error and usage in allwedargcount()
* improve URL matcher. include also SSH protocol
---
Commands.md | 17 ++++++++++++++++-
bin/git-bulk | 30 ++++++++++++++++++++----------
man/git-bulk.1 | 19 +++++++++++++++++--
man/git-bulk.html | 20 +++++++++++++++++---
man/git-bulk.md | 18 ++++++++++++++++--
5 files changed, 86 insertions(+), 18 deletions(-)
diff --git a/Commands.md b/Commands.md
index eb9b7c8..d9d501e 100644
--- a/Commands.md
+++ b/Commands.md
@@ -253,7 +253,7 @@ $ git effort bin/* lib/*
```bash
usage: git bulk [-g] ([-a]|[-w ])
- git bulk --addworkspace
+ git bulk --addworkspace (--from )
git bulk --removeworkspace
git bulk --addcurrent
git bulk --purge
@@ -264,6 +264,20 @@ usage: git bulk [-g] ([-a]|[-w ])
```bash
$ git bulk --addworkspace personal ~/workspaces/personal
+```
+ With option `--from` the URL to a single repository or a file containing multiple URLs can be added and they will be cloned diretly into the workspace. Suitable for the initial setup of a multi-repo project.
+
+```bash
+$ git bulk --addworkspace projectX ~/workspaces/projectx --from https://github.com/x/project-x.git
+
+# OR with a file containing many repositories on each line:
+$ git bulk --addworkspace projectX ~/workspaces/projectx --from ~/workspaces/repositories.txt
+```
+with `repositories.txt` be like:
+```
+https://github.com/x/project-x-1.git
+https://github.com/x/project-x-2.git
+https://github.com/x/project-x-3.git
```
Register the current directory as a workspace to `git bulk`
@@ -277,6 +291,7 @@ $ git bulk --addcurrent personal
```bash
$ git bulk --listall
bulkworkspaces.personal /Users/niklasschlimm/workspaces/personal
+
```
Run a git command on the repositories of the current workspace:
diff --git a/bin/git-bulk b/bin/git-bulk
index 5c0eecc..30e2736 100755
--- a/bin/git-bulk
+++ b/bin/git-bulk
@@ -14,7 +14,7 @@ allwsmode=false
#
usage() {
echo 1>&2 "usage: git bulk [-g] ([-a]|[-w ]) "
- echo 1>&2 " git bulk --addworkspace "
+ echo 1>&2 " git bulk --addworkspace (--from )"
echo 1>&2 " git bulk --removeworkspace "
echo 1>&2 " git bulk --addcurrent "
echo 1>&2 " git bulk --purge"
@@ -22,7 +22,17 @@ usage() {
}
# add another workspace to global git config
-function addworkspace { git config --global bulkworkspaces."$wsname" "$wsdir"; }
+function addworkspace {
+ git config --global bulkworkspaces."$wsname" "$wsdir";
+ if [ ! -z "$source" ]; then
+ if ! cd "$wsdir" 2>/dev/null; then echo "Path of workspace doesn't exist, make it first."; exit 1; fi
+ regex='http(s)?://|ssh://|(git@)?.*:.*/.*'
+ if [[ "$source" =~ $regex ]]; then git clone "$source";
+ elif [ -f "$source" ]; then while read line; do git clone "$line"; done < "$source";
+ else echo 1>&2 "format of URL or file unknown";
+ fi
+ fi
+}
# add current directory
function addcurrent { git config --global bulkworkspaces."$wsname" "$PWD"; }
@@ -94,12 +104,12 @@ function wsnameToCurrent () {
wslist="$(echo "$(listall)")" && echo "${wslist:-''}" && exit 1
}
-# helper to check number of arguments
-function allowedargcount {
- if test "$paramcount" -ne $1; then
- echo 1>&2 "error: wrong number of arguments" && usage
- exit 1;
- fi
+# helper to check number of arguments.
+function allowedargcount () {
+ if [ $paramcount -ne $1 ] && [ $paramcount -ne $2 ]; then
+ echo 1>&2 "error: wrong number of arguments" && usage;
+ exit 1;
+ fi
}
# execute the bulk operation
@@ -135,7 +145,7 @@ while [ "${#}" -ge 1 ] ; do
--listall|--purge)
butilcommand="${1:2}" && break ;;
--removeworkspace|--addcurrent|--addworkspace)
- butilcommand="${1:2}" && wsname="$2" && wsdir="$3" && break ;;
+ butilcommand="${1:2}" && wsname="$2" && wsdir="$3" && if [ "$4"=="--from" ]; then source="$5"; fi && break ;;
-a)
allwsmode=true ;;
-g)
@@ -161,7 +171,7 @@ if $singlemode; then echo "Selected single workspace mode in workspace: $wsname"
case $butilcommand in
listall|purge) allowedargcount 1;;
addcurrent|removeworkspace) allowedargcount 2;;
- addworkspace) allowedargcount 3;;
+ addworkspace) allowedargcount 3 5;;
esac
$butilcommand # run user command
diff --git a/man/git-bulk.1 b/man/git-bulk.1
index 955a0f2..523b652 100644
--- a/man/git-bulk.1
+++ b/man/git-bulk.1
@@ -10,7 +10,7 @@
git bulk [\-g] ([\-a]|[\-w ])
.
.br
-git bulk \-\-addworkspace
+git bulk \-\-addworkspace (\-\-from )
.
.br
git bulk \-\-removeworkspace
@@ -63,12 +63,15 @@ Run the git command on the specified workspace\. The workspace must be registere
Any git Command you wish to execute on the repositories\.
.
.P
-\-\-addworkspace
+\-\-addworkspace (\-\-from get registered under this workspace with the name \. must be absolute path\.
.
.P
+With option \'\-\-from\' the URL to a single repository or a file containing multiple URLs can be added and they will be cloned diretly into the workspace\. Suitable for the initial setup of a multi\-repo project\.
+.
+.P
\-\-removeworkspace
.
.P
@@ -100,6 +103,18 @@ Register a workspace so that git bulk knows about it:
$ git bulk \-\-addworkspace personal ~/workspaces/personal
+Use option \-\-from in order to directly clone a repository or multiple repositories
+
+$ git bulk \-\-addworkspace personal ~/workspaces/personal \-\-from https://github\.com/tj/git\-extras\.git
+$ git bulk \-\-addworkspace personal ~/workspaces/personal \-\-from ~/repositories\.txt
+
+repositories\.txt
+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
+https://host\-of\-git/repo\-1\.git
+https://host\-of\-git/repo\-2\.git
+https://host\-of\-git/repo\-3\.git
+
+
Register the current directory as a workspace to git bulk:
$ git bulk \-\-addcurrent personal
diff --git a/man/git-bulk.html b/man/git-bulk.html
index 541e1b3..51cd757 100644
--- a/man/git-bulk.html
+++ b/man/git-bulk.html
@@ -77,7 +77,7 @@
SYNOPSIS
git bulk [-g] ([-a]|[-w <ws-name>]) <git command>
-git bulk --addworkspace <ws-name> <ws-root-directory>
+git bulk --addworkspace <ws-name> <ws-root-directory> (--from <URL or file>)
git bulk --removeworkspace <ws-name>
git bulk --addcurrent <ws-name>
git bulk --purge
@@ -112,10 +112,12 @@ git bulk --listall
Any git Command you wish to execute on the repositories.
- --addworkspace <ws-name> <ws-root-directory>
+ --addworkspace <ws-name> <ws-root-directory> (--from <URL or file&rt;gt;)
Register a workspace for bulk operations. All repositories in the directories below <ws-root-directory> get registered under this workspace with the name <ws-name>. <ws-root-directory> must be absolute path.
+ With option '--from' the URL to a single repository or a file containing multiple URLs can be added and they will be cloned diretly into the workspace. Suitable for the initial setup of a multi-repo project.
+
--removeworkspace <ws-name>
Remove the workspace with the logical name <ws-name>.
@@ -138,6 +140,18 @@ git bulk --listall
$ git bulk --addworkspace personal ~/workspaces/personal
+Use option --from in order to directly clone a repository or multiple repositories
+
+$ git bulk --addworkspace personal ~/workspaces/personal --from https://github.com/tj/git-extras.git
+$ git bulk --addworkspace personal ~/workspaces/personal --from ~/repositories.txt
+
+repositories.txt
+----------------------------------
+https://host-of-git/repo-1.git
+https://host-of-git/repo-2.git
+https://host-of-git/repo-3.git
+
+
Register the current directory as a workspace to git bulk:
$ git bulk --addcurrent personal
@@ -169,7 +183,7 @@ $ git bulk --purge
AUTHOR
-Written by Niklas Schlimm <ns103@hotmail.de>
+Written by Niklas Schlimm <ns103@hotmail.de>
REPORTING BUGS
diff --git a/man/git-bulk.md b/man/git-bulk.md
index 0f64cf2..060f9e6 100644
--- a/man/git-bulk.md
+++ b/man/git-bulk.md
@@ -4,7 +4,7 @@ git-bulk(1) -- Run git commands on multiple repositories
## SYNOPSIS
git bulk [-g] ([-a]|[-w <ws-name>]) <git command>
-git bulk --addworkspace <ws-name> <ws-root-directory>
+git bulk --addworkspace <ws-name> <ws-root-directory> (--from <URL or file>)
git bulk --removeworkspace <ws-name>
git bulk --addcurrent <ws-name>
git bulk --purge
@@ -36,10 +36,12 @@ git bulk adds convenient support for operations that you want to execute on mult
Any git Command you wish to execute on the repositories.
- --addworkspace <ws-name> <ws-root-directory>
+ --addworkspace <ws-name> <ws-root-directory> (--from <URL or file&rt;gt;)
Register a workspace for bulk operations. All repositories in the directories below <ws-root-directory> get registered under this workspace with the name <ws-name>. <ws-root-directory> must be absolute path.
+ With option '--from' the URL to a single repository or a file containing multiple URLs can be added and they will be cloned diretly into the workspace. Suitable for the initial setup of a multi-repo project.
+
--removeworkspace <ws-name>
Remove the workspace with the logical name <ws-name>.
@@ -62,6 +64,18 @@ git bulk adds convenient support for operations that you want to execute on mult
$ git bulk --addworkspace personal ~/workspaces/personal
+ Use option --from in order to directly clone a repository or multiple repositories
+
+ $ git bulk --addworkspace personal ~/workspaces/personal --from https://github.com/tj/git-extras.git
+ $ git bulk --addworkspace personal ~/workspaces/personal --from ~/repositories.txt
+
+ repositories.txt
+ ----------------------------------
+ https://host-of-git/repo-1.git
+ https://host-of-git/repo-2.git
+ https://host-of-git/repo-3.git
+
+
Register the current directory as a workspace to git bulk:
$ git bulk --addcurrent personal