Add 'git subtree merge' and 'git subtree pull'.
These are simple shortcuts for 'git merge -s subtree' and 'git pull -s subtree', but it makes sense to have it all in one command.maint
parent
eb7b590c8c
commit
13648af5ee
|
@ -8,13 +8,15 @@ if [ $# -eq 0 ]; then
|
||||||
set -- -h
|
set -- -h
|
||||||
fi
|
fi
|
||||||
OPTS_SPEC="\
|
OPTS_SPEC="\
|
||||||
git subtree add <--prefix=prefix <commit>
|
git subtree add --prefix=<prefix> <commit>
|
||||||
git subtree split [options...] <--prefix=prefix> <commit...>
|
git subtree split [options...] --prefix=<prefix> <commit...>
|
||||||
git subtree merge
|
git subtree merge --prefix=<prefix> <commit>
|
||||||
|
git subtree pull --prefix=<prefix> <repository> <refspec...>
|
||||||
--
|
--
|
||||||
h,help show the help
|
h,help show the help
|
||||||
q quiet
|
q quiet
|
||||||
prefix= the name of the subdir to split out
|
prefix= the name of the subdir to split out
|
||||||
|
options for 'split'
|
||||||
onto= try connecting new tree to an existing one
|
onto= try connecting new tree to an existing one
|
||||||
rejoin merge the new branch back into HEAD
|
rejoin merge the new branch back into HEAD
|
||||||
ignore-joins ignore prior --rejoin commits
|
ignore-joins ignore prior --rejoin commits
|
||||||
|
@ -68,27 +70,29 @@ done
|
||||||
command="$1"
|
command="$1"
|
||||||
shift
|
shift
|
||||||
case "$command" in
|
case "$command" in
|
||||||
add|merge) default= ;;
|
add|merge|pull) default= ;;
|
||||||
split) default="--default HEAD" ;;
|
split) default="--default HEAD" ;;
|
||||||
*) die "Unknown command '$command'" ;;
|
*) die "Unknown command '$command'" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
revs=$(git rev-parse $default --revs-only "$@") || exit $?
|
|
||||||
|
|
||||||
if [ -z "$prefix" ]; then
|
if [ -z "$prefix" ]; then
|
||||||
die "You must provide the --prefix option."
|
die "You must provide the --prefix option."
|
||||||
fi
|
fi
|
||||||
dir="$prefix"
|
dir="$prefix"
|
||||||
|
|
||||||
dirs="$(git rev-parse --no-revs --no-flags "$@")" || exit $?
|
if [ "$command" != "pull" ]; then
|
||||||
if [ -n "$dirs" ]; then
|
revs=$(git rev-parse $default --revs-only "$@") || exit $?
|
||||||
die "Error: Use --prefix instead of bare filenames."
|
dirs="$(git rev-parse --no-revs --no-flags "$@")" || exit $?
|
||||||
|
if [ -n "$dirs" ]; then
|
||||||
|
die "Error: Use --prefix instead of bare filenames."
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
debug "command: {$command}"
|
debug "command: {$command}"
|
||||||
debug "quiet: {$quiet}"
|
debug "quiet: {$quiet}"
|
||||||
debug "revs: {$revs}"
|
debug "revs: {$revs}"
|
||||||
debug "dir: {$dir}"
|
debug "dir: {$dir}"
|
||||||
|
debug "opts: {$*}"
|
||||||
debug
|
debug
|
||||||
|
|
||||||
cache_setup()
|
cache_setup()
|
||||||
|
@ -258,17 +262,23 @@ copy_or_skip()
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd_add()
|
ensure_clean()
|
||||||
{
|
{
|
||||||
if [ -e "$dir" ]; then
|
|
||||||
die "'$dir' already exists. Cannot add."
|
|
||||||
fi
|
|
||||||
if ! git diff-index HEAD --exit-code --quiet; then
|
if ! git diff-index HEAD --exit-code --quiet; then
|
||||||
die "Working tree has modifications. Cannot add."
|
die "Working tree has modifications. Cannot add."
|
||||||
fi
|
fi
|
||||||
if ! git diff-index --cached HEAD --exit-code --quiet; then
|
if ! git diff-index --cached HEAD --exit-code --quiet; then
|
||||||
die "Index has modifications. Cannot add."
|
die "Index has modifications. Cannot add."
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd_add()
|
||||||
|
{
|
||||||
|
if [ -e "$dir" ]; then
|
||||||
|
die "'$dir' already exists. Cannot add."
|
||||||
|
fi
|
||||||
|
ensure_clean
|
||||||
|
|
||||||
set -- $revs
|
set -- $revs
|
||||||
if [ $# -ne 1 ]; then
|
if [ $# -ne 1 ]; then
|
||||||
die "You must provide exactly one revision. Got: '$revs'"
|
die "You must provide exactly one revision. Got: '$revs'"
|
||||||
|
@ -357,7 +367,22 @@ cmd_split()
|
||||||
|
|
||||||
cmd_merge()
|
cmd_merge()
|
||||||
{
|
{
|
||||||
die "merge command not implemented yet"
|
ensure_clean
|
||||||
|
|
||||||
|
set -- $revs
|
||||||
|
if [ $# -ne 1 ]; then
|
||||||
|
die "You must provide exactly one revision. Got: '$revs'"
|
||||||
|
fi
|
||||||
|
rev="$1"
|
||||||
|
|
||||||
|
git merge -s subtree $rev
|
||||||
}
|
}
|
||||||
|
|
||||||
"cmd_$command"
|
cmd_pull()
|
||||||
|
{
|
||||||
|
ensure_clean
|
||||||
|
set -x
|
||||||
|
git pull -s subtree "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
"cmd_$command" "$@"
|
||||||
|
|
Loading…
Reference in New Issue