Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

A number of changes to push_all and pull_all:

* adding commands in "add" to populate the .gittrees file
* changing underscores to dashes (push_all -> push-all)
* changing commands to not be hardcoded to branch "master" from remote
* letting the user specify 0, 1, or 2 arguments to push and pull, like
normal "git push" and "git pull".  We'll try to look up missing
information from .gittrees, like git normally does from .git/config
  • Loading branch information...
commit 594606d7f804d34ecb9fb8fb3fd1543ae190be95 1 parent 3587568
mhoffman authored
Showing with 56 additions and 28 deletions.
  1. +2 −0  .gitignore
  2. +54 −28 git-subtree.sh
View
2  .gitignore
@@ -4,3 +4,5 @@ git-subtree.1
mainline
subproj
launchpad
+.gittrees
+
View
82 git-subtree.sh
@@ -8,11 +8,12 @@ if [ $# -eq 0 ]; then
set -- -h
fi
OPTS_SPEC="\
-git subtree add --prefix=<prefix> <commit>
+git subtree add --prefix=<prefix> <repository> <refspec>
git subtree merge --prefix=<prefix> <commit>
-git subtree pull --prefix=<prefix> <branch>
-git subtree pull_all
-git subtree push --prefix=<prefix> <branch>
+git subtree pull --prefix=<prefix> [<repository> [<refspec>...]]
+git subtree pull-all
+git subtree push-all
+git subtree push --prefix=<prefix> [<repository> [<refspec>...]]
git subtree split --prefix=<prefix> <commit...>
--
h,help show the help
@@ -101,18 +102,18 @@ done
command="$1"
shift
case "$command" in
- add|merge|pull|pull_all|push_all) default= ;;
+ add|merge|pull|pull-all|push-all) default= ;;
split|push) default="--default HEAD" ;;
*) die "Unknown command '$command'" ;;
esac
-if [ -z "$prefix" -a "$command" != "pull_all" -a "$command" != "push_all" ]; then
+if [ -z "$prefix" -a "$command" != "pull-all" -a "$command" != "push-all" ]; then
die "You must provide the --prefix option."
fi
case "$command" in
- pull_all);;
- push_all);;
+ pull-all);;
+ push-all);;
add) [ -e "$prefix" ] &&
die "prefix '$prefix' already exists." ;;
*) [ -e "$prefix" ] ||
@@ -121,7 +122,7 @@ esac
dir="$(dirname "$prefix/.")"
-if [ "$command" != "pull" -a "$command" != "add" -a "$command" != "push" -a "$command" != "pull_all" ]; then
+if [ "$command" != "pull" -a "$command" != "add" -a "$command" != "push" -a "$command" != "pull-all" ]; then
revs=$(git rev-parse $default --revs-only "$@") || exit $?
dirs="$(git rev-parse --no-revs --no-flags "$@")" || exit $?
if [ -n "$dirs" ]; then
@@ -506,7 +507,8 @@ cmd_add()
else
say "error: parameters were '$@'"
die "Provide either a refspec or a repository and refspec."
- fi
+ fi
+
}
cmd_add_repository()
@@ -518,6 +520,14 @@ cmd_add_repository()
revs=FETCH_HEAD
set -- $revs
cmd_add_commit "$@"
+
+ # now add it to our list of repos
+ git config -f .gittrees --unset subtree.$dir.url
+ git config -f .gittrees --add subtree.$dir.url $repository
+ git config -f .gittrees --unset subtree.$dir.path
+ git config -f .gittrees --add subtree.$dir.path $dir
+ git config -f .gittrees --unset subtree.$dir.branch
+ git config -f .gittrees --add subtree.$dir.branch $refspec
}
cmd_add_commit()
@@ -691,13 +701,21 @@ cmd_merge()
cmd_pull()
{
- if [ $# -ne 1 ]; then
- die "You must provide <branch>"
+ if [ $# -gt 2 ]; then
+ die "You should provide either <refspec> or <repository> <refspec>"
fi
if [ -e "$dir" ]; then
ensure_clean
- repository=$(git config -f .gittrees subtree.$prefix.url)
- refspec=$1
+ if [ $# -eq 1 ]; then
+ repository=$(git config -f .gittrees subtree.$prefix.url)
+ refspec=$1
+ elif [ $# -eq 2 ]; then
+ repository=$1
+ refspec=$2
+ else
+ repository=$(git config -f .gittrees subtree.$prefix.url)
+ refspec=$(git config -f .gittrees subtree.$prefix.branch)
+ fi
git fetch $repository $refspec || exit $?
echo "git fetch using: " $repository $refspec
revs=FETCH_HEAD
@@ -710,12 +728,20 @@ cmd_pull()
cmd_push()
{
- if [ $# -ne 1 ]; then
- die "You must provide <branch>"
+ if [ $# -gt 2 ]; then
+ die "You shold provide either <refspec> or <repository> <refspec>"
fi
if [ -e "$dir" ]; then
- repository=$(git config -f .gittrees subtree.$prefix.url)
- refspec=$1
+ if [ $# -eq 1 ]; then
+ repository=$(git config -f .gittrees subtree.$prefix.url)
+ refspec=$1
+ elif [ $# -eq 2 ]; then
+ repository=$1
+ refspec=$2
+ else
+ repository=$(git config -f .gittrees subtree.$prefix.url)
+ refspec=$(git config -f .gittrees subtree.$prefix.branch)
+ fi
echo "git push using: " $repository $refspec
git push $repository $(git subtree split --prefix=$prefix):refs/heads/$refspec
else
@@ -723,20 +749,20 @@ cmd_push()
fi
}
-cmd_pull_all()
+cmd_pull-all()
{
- git config -f .gittrees -l | grep subtree | grep path | grep -o '=.*' | grep -o '[^=].*' |
- while read path; do
- git subtree pull -P $path master || exit $?
- done
+ git config -f .gittrees -l | grep subtree | grep path | grep -o '=.*' | grep -o '[^=].*' |
+ while read path; do
+ git subtree pull -P $path $(git config -f .gittrees subtree.$path.url) $(git config -f .gittrees subtree.$path.branch) || exit $?
+ done
}
-cmd_push_all()
+cmd_push-all()
{
- git config -f .gittrees -l | grep subtree | grep path | grep -o '=.*' | grep -o '[^=].*' |
- while read path; do
- git subtree push -P $path master || exit $?
- done
+ git config -f .gittrees -l | grep subtree | grep path | grep -o '=.*' | grep -o '[^=].*' |
+ while read path; do
+ git subtree push -P $path $(git config -f .gittrees subtree.$path.url) $(git config -f .gittrees subtree.$path.branch) || exit $?
+ done
}
"cmd_$command" "$@"
Please sign in to comment.
Something went wrong with that request. Please try again.