Skip to content

Commit

Permalink
A number of changes to push_all and pull_all:
Browse files Browse the repository at this point in the history
* 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
mhoffman committed Sep 13, 2011
1 parent 3587568 commit 594606d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -4,3 +4,5 @@ git-subtree.1
mainline
subproj
launchpad
.gittrees

82 changes: 54 additions & 28 deletions git-subtree.sh
Expand Up @@ -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
Expand Down Expand Up @@ -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" ] ||
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -710,33 +728,41 @@ 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
die "'$dir' must already exist. Try 'git subtree add'."
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" "$@"

0 comments on commit 594606d

Please sign in to comment.