mirror of
https://github.com/tj/git-extras.git
synced 2026-09-10 07:26:17 -04:00
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
This commit is contained in:
parent
bb7d389084
commit
16bb0df9f9
17
Commands.md
17
Commands.md
|
|
@ -253,7 +253,7 @@ $ git effort bin/* lib/*
|
|||
|
||||
```bash
|
||||
usage: 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
|
||||
|
|
@ -264,6 +264,20 @@ usage: git bulk [-g] ([-a]|[-w <ws-name>]) <git command>
|
|||
|
||||
```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:
|
||||
|
|
|
|||
30
bin/git-bulk
30
bin/git-bulk
|
|
@ -14,7 +14,7 @@ allwsmode=false
|
|||
#
|
||||
usage() {
|
||||
echo 1>&2 "usage: git bulk [-g] ([-a]|[-w <ws-name>]) <git command>"
|
||||
echo 1>&2 " git bulk --addworkspace <ws-name> <ws-root-directory>"
|
||||
echo 1>&2 " git bulk --addworkspace <ws-name> <ws-root-directory> (--from <URL or file>)"
|
||||
echo 1>&2 " git bulk --removeworkspace <ws-name>"
|
||||
echo 1>&2 " git bulk --addcurrent <ws-name>"
|
||||
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:-'<no workspaces defined yet>'}" && 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
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
git bulk [\-g] ([\-a]|[\-w <ws\-name>]) <git command>
|
||||
.
|
||||
.br
|
||||
git bulk \-\-addworkspace <ws\-name> <ws\-root\-directory>
|
||||
git bulk \-\-addworkspace <ws\-name> <ws\-root\-directory> (\-\-from <URL or file>)
|
||||
.
|
||||
.br
|
||||
git bulk \-\-removeworkspace <ws\-name>
|
||||
|
|
@ -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 <ws\-name> <ws\-root\-directory>
|
||||
\-\-addworkspace <ws\-name> <ws\-root\-directory> (\-\-from <URL or file&rt;gt;)
|
||||
.
|
||||
.P
|
||||
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\.
|
||||
.
|
||||
.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 <ws\-name>
|
||||
.
|
||||
.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
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@
|
|||
<h2 id="SYNOPSIS">SYNOPSIS</h2>
|
||||
|
||||
<p>git bulk [-g] ([-a]|[-w <ws-name>]) <git command> <br />
|
||||
git bulk --addworkspace <ws-name> <ws-root-directory> <br />
|
||||
git bulk --addworkspace <ws-name> <ws-root-directory> (--from <URL or file>) <br />
|
||||
git bulk --removeworkspace <ws-name> <br />
|
||||
git bulk --addcurrent <ws-name> <br />
|
||||
git bulk --purge <br />
|
||||
|
|
@ -112,10 +112,12 @@ git bulk --listall</p>
|
|||
|
||||
<p> Any git Command you wish to execute on the repositories.</p>
|
||||
|
||||
<p> --addworkspace <ws-name> <ws-root-directory></p>
|
||||
<p> --addworkspace <ws-name> <ws-root-directory> (--from <URL or file&rt;gt;)</p>
|
||||
|
||||
<p> 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.</p>
|
||||
|
||||
<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>
|
||||
|
||||
<p> --removeworkspace <ws-name></p>
|
||||
|
||||
<p> Remove the workspace with the logical name <ws-name>.</p>
|
||||
|
|
@ -138,6 +140,18 @@ git bulk --listall</p>
|
|||
|
||||
$ 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
|
|||
|
||||
<h2 id="AUTHOR">AUTHOR</h2>
|
||||
|
||||
<p>Written by Niklas Schlimm <<a href="mailto:ns103@hotmail.de" data-bare-link="true">ns103@hotmail.de</a>></p>
|
||||
<p>Written by Niklas Schlimm <<a href="mailto:ns103@hotmail.de" data-bare-link="true">ns103@hotmail.de</a>></p>
|
||||
|
||||
<h2 id="REPORTING-BUGS">REPORTING BUGS</h2>
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ git-bulk(1) -- Run git commands on multiple repositories
|
|||
## SYNOPSIS
|
||||
|
||||
git bulk [-g] ([-a]|[-w <ws-name>]) <git command> <br/>
|
||||
git bulk --addworkspace <ws-name> <ws-root-directory> <br/>
|
||||
git bulk --addworkspace <ws-name> <ws-root-directory> (--from <URL or file>) <br/>
|
||||
git bulk --removeworkspace <ws-name> <br/>
|
||||
git bulk --addcurrent <ws-name> <br/>
|
||||
git bulk --purge <br/>
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue