2013-05-20 22:24:34 +02:00
|
|
|
#!/bin/sh
|
2009-04-24 20:13:34 +02:00
|
|
|
#
|
|
|
|
# git-subtree.sh: split/join git repositories in subdirectories of this one
|
|
|
|
#
|
2009-04-24 21:48:41 +02:00
|
|
|
# Copyright (C) 2009 Avery Pennarun <apenwarr@gmail.com>
|
2009-04-24 20:13:34 +02:00
|
|
|
#
|
2016-07-28 02:16:49 +02:00
|
|
|
if test $# -eq 0
|
|
|
|
then
|
|
|
|
set -- -h
|
2009-04-25 04:36:06 +02:00
|
|
|
fi
|
2009-04-24 20:13:34 +02:00
|
|
|
OPTS_SPEC="\
|
2009-05-30 07:10:14 +02:00
|
|
|
git subtree add --prefix=<prefix> <commit>
|
2013-11-27 19:34:09 +01:00
|
|
|
git subtree add --prefix=<prefix> <repository> <ref>
|
2009-04-25 05:41:19 +02:00
|
|
|
git subtree merge --prefix=<prefix> <commit>
|
2013-11-27 19:34:09 +01:00
|
|
|
git subtree pull --prefix=<prefix> <repository> <ref>
|
|
|
|
git subtree push --prefix=<prefix> <repository> <ref>
|
2009-05-30 07:10:14 +02:00
|
|
|
git subtree split --prefix=<prefix> <commit...>
|
2009-04-24 20:13:34 +02:00
|
|
|
--
|
2009-04-25 04:36:06 +02:00
|
|
|
h,help show the help
|
|
|
|
q quiet
|
2009-04-27 00:06:08 +02:00
|
|
|
d show debug messages
|
2010-01-12 22:38:21 +01:00
|
|
|
P,prefix= the name of the subdir to split out
|
2010-01-09 19:55:35 +01:00
|
|
|
m,message= use the given message as the commit message for the merge commit
|
2009-04-25 05:41:19 +02:00
|
|
|
options for 'split'
|
2009-04-26 14:59:12 +02:00
|
|
|
annotate= add a prefix to commit message of new commits
|
2009-05-30 07:05:43 +02:00
|
|
|
b,branch= create a new branch from the split subtree
|
|
|
|
ignore-joins ignore prior --rejoin commits
|
2009-04-25 04:36:06 +02:00
|
|
|
onto= try connecting new tree to an existing one
|
|
|
|
rejoin merge the new branch back into HEAD
|
2015-05-07 09:52:33 +02:00
|
|
|
options for 'add', 'merge', and 'pull'
|
2009-05-30 06:48:07 +02:00
|
|
|
squash merge subtree changes as a single commit
|
2009-04-24 20:13:34 +02:00
|
|
|
"
|
2010-09-13 21:16:57 +02:00
|
|
|
eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)"
|
2010-06-24 07:53:05 +02:00
|
|
|
|
2010-06-24 22:57:58 +02:00
|
|
|
PATH=$PATH:$(git --exec-path)
|
2009-08-26 16:41:03 +02:00
|
|
|
. git-sh-setup
|
2010-06-24 07:53:05 +02:00
|
|
|
|
2009-04-24 20:13:34 +02:00
|
|
|
require_work_tree
|
|
|
|
|
|
|
|
quiet=
|
2009-05-30 07:05:43 +02:00
|
|
|
branch=
|
2009-04-27 00:06:08 +02:00
|
|
|
debug=
|
2009-04-24 20:13:34 +02:00
|
|
|
command=
|
2009-04-24 21:48:41 +02:00
|
|
|
onto=
|
|
|
|
rejoin=
|
2009-04-25 04:36:06 +02:00
|
|
|
ignore_joins=
|
2009-04-26 14:59:12 +02:00
|
|
|
annotate=
|
2009-05-30 06:48:07 +02:00
|
|
|
squash=
|
2010-01-09 19:55:35 +01:00
|
|
|
message=
|
2014-03-17 20:59:47 +01:00
|
|
|
prefix=
|
2009-04-24 20:13:34 +02:00
|
|
|
|
2016-07-28 02:16:50 +02:00
|
|
|
debug () {
|
2016-07-28 02:16:49 +02:00
|
|
|
if test -n "$debug"
|
|
|
|
then
|
2015-05-08 02:56:59 +02:00
|
|
|
printf "%s\n" "$*" >&2
|
2009-04-27 00:06:08 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-07-28 02:16:50 +02:00
|
|
|
say () {
|
2016-07-28 02:16:49 +02:00
|
|
|
if test -z "$quiet"
|
|
|
|
then
|
2015-05-08 02:56:59 +02:00
|
|
|
printf "%s\n" "$*" >&2
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-07-28 02:16:50 +02:00
|
|
|
progress () {
|
2016-07-28 02:16:49 +02:00
|
|
|
if test -z "$quiet"
|
|
|
|
then
|
2015-05-08 02:56:59 +02:00
|
|
|
printf "%s\r" "$*" >&2
|
2009-04-24 20:13:34 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-07-28 02:16:50 +02:00
|
|
|
assert () {
|
2016-07-28 02:16:49 +02:00
|
|
|
if ! "$@"
|
|
|
|
then
|
2009-04-24 20:24:38 +02:00
|
|
|
die "assertion failed: " "$@"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-28 02:16:49 +02:00
|
|
|
while test $# -gt 0
|
|
|
|
do
|
2009-04-24 20:13:34 +02:00
|
|
|
opt="$1"
|
|
|
|
shift
|
2016-07-28 02:16:49 +02:00
|
|
|
|
2009-04-24 20:13:34 +02:00
|
|
|
case "$opt" in
|
2016-07-28 02:16:49 +02:00
|
|
|
-q)
|
|
|
|
quiet=1
|
|
|
|
;;
|
|
|
|
-d)
|
|
|
|
debug=1
|
|
|
|
;;
|
|
|
|
--annotate)
|
|
|
|
annotate="$1"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--no-annotate)
|
|
|
|
annotate=
|
|
|
|
;;
|
|
|
|
-b)
|
|
|
|
branch="$1"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-P)
|
|
|
|
prefix="${1%/}"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-m)
|
|
|
|
message="$1"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--no-prefix)
|
|
|
|
prefix=
|
|
|
|
;;
|
|
|
|
--onto)
|
|
|
|
onto="$1"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--no-onto)
|
|
|
|
onto=
|
|
|
|
;;
|
|
|
|
--rejoin)
|
|
|
|
rejoin=1
|
|
|
|
;;
|
|
|
|
--no-rejoin)
|
|
|
|
rejoin=
|
|
|
|
;;
|
|
|
|
--ignore-joins)
|
|
|
|
ignore_joins=1
|
|
|
|
;;
|
|
|
|
--no-ignore-joins)
|
|
|
|
ignore_joins=
|
|
|
|
;;
|
|
|
|
--squash)
|
|
|
|
squash=1
|
|
|
|
;;
|
|
|
|
--no-squash)
|
|
|
|
squash=
|
|
|
|
;;
|
|
|
|
--)
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
die "Unexpected option: $opt"
|
|
|
|
;;
|
2009-04-24 20:13:34 +02:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
command="$1"
|
|
|
|
shift
|
2016-07-28 02:16:49 +02:00
|
|
|
|
2009-04-24 20:13:34 +02:00
|
|
|
case "$command" in
|
2016-07-28 02:16:49 +02:00
|
|
|
add|merge|pull)
|
|
|
|
default=
|
|
|
|
;;
|
|
|
|
split|push)
|
|
|
|
default="--default HEAD"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
die "Unknown command '$command'"
|
|
|
|
;;
|
2009-04-24 20:13:34 +02:00
|
|
|
esac
|
|
|
|
|
2016-07-28 02:16:49 +02:00
|
|
|
if test -z "$prefix"
|
|
|
|
then
|
2009-04-25 04:57:14 +02:00
|
|
|
die "You must provide the --prefix option."
|
|
|
|
fi
|
2010-02-06 04:02:43 +01:00
|
|
|
|
2010-02-08 21:00:42 +01:00
|
|
|
case "$command" in
|
2016-07-28 02:16:49 +02:00
|
|
|
add)
|
|
|
|
test -e "$prefix" &&
|
|
|
|
die "prefix '$prefix' already exists."
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
test -e "$prefix" ||
|
|
|
|
die "'$prefix' does not exist; use 'git subtree add'"
|
|
|
|
;;
|
2010-02-08 21:00:42 +01:00
|
|
|
esac
|
2010-02-06 04:02:43 +01:00
|
|
|
|
2009-10-02 21:22:15 +02:00
|
|
|
dir="$(dirname "$prefix/.")"
|
2009-04-25 04:57:14 +02:00
|
|
|
|
2016-07-28 02:16:49 +02:00
|
|
|
if test "$command" != "pull" &&
|
|
|
|
test "$command" != "add" &&
|
|
|
|
test "$command" != "push"
|
|
|
|
then
|
2009-04-25 05:41:19 +02:00
|
|
|
revs=$(git rev-parse $default --revs-only "$@") || exit $?
|
2016-07-28 02:16:49 +02:00
|
|
|
dirs=$(git rev-parse --no-revs --no-flags "$@") || exit $?
|
|
|
|
if test -n "$dirs"
|
|
|
|
then
|
2009-04-25 05:41:19 +02:00
|
|
|
die "Error: Use --prefix instead of bare filenames."
|
|
|
|
fi
|
2009-04-24 20:13:34 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
debug "command: {$command}"
|
|
|
|
debug "quiet: {$quiet}"
|
|
|
|
debug "revs: {$revs}"
|
|
|
|
debug "dir: {$dir}"
|
2009-04-25 05:41:19 +02:00
|
|
|
debug "opts: {$*}"
|
2009-04-25 05:28:30 +02:00
|
|
|
debug
|
2009-04-24 20:13:34 +02:00
|
|
|
|
2016-07-28 02:16:50 +02:00
|
|
|
cache_setup () {
|
2009-04-24 20:24:38 +02:00
|
|
|
cachedir="$GIT_DIR/subtree-cache/$$"
|
2016-07-28 02:16:49 +02:00
|
|
|
rm -rf "$cachedir" ||
|
|
|
|
die "Can't delete old cachedir: $cachedir"
|
|
|
|
mkdir -p "$cachedir" ||
|
|
|
|
die "Can't create new cachedir: $cachedir"
|
|
|
|
mkdir -p "$cachedir/notree" ||
|
|
|
|
die "Can't create new cachedir: $cachedir/notree"
|
2009-04-24 20:13:34 +02:00
|
|
|
debug "Using cachedir: $cachedir" >&2
|
|
|
|
}
|
|
|
|
|
2016-07-28 02:16:50 +02:00
|
|
|
cache_get () {
|
2016-07-28 02:16:49 +02:00
|
|
|
for oldrev in "$@"
|
|
|
|
do
|
|
|
|
if test -r "$cachedir/$oldrev"
|
|
|
|
then
|
2009-04-24 20:13:34 +02:00
|
|
|
read newrev <"$cachedir/$oldrev"
|
|
|
|
echo $newrev
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2016-07-28 02:16:50 +02:00
|
|
|
cache_miss () {
|
2016-07-28 02:16:49 +02:00
|
|
|
for oldrev in "$@"
|
|
|
|
do
|
|
|
|
if ! test -r "$cachedir/$oldrev"
|
|
|
|
then
|
2010-11-10 05:18:36 +01:00
|
|
|
echo $oldrev
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2016-07-28 02:16:50 +02:00
|
|
|
check_parents () {
|
2016-07-28 02:16:49 +02:00
|
|
|
missed=$(cache_miss "$@")
|
|
|
|
for miss in $missed
|
|
|
|
do
|
|
|
|
if ! test -r "$cachedir/notree/$miss"
|
|
|
|
then
|
2010-11-10 05:18:36 +01:00
|
|
|
debug " incorrect order: $miss"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2016-07-28 02:16:50 +02:00
|
|
|
set_notree () {
|
2010-11-10 05:18:36 +01:00
|
|
|
echo "1" > "$cachedir/notree/$1"
|
|
|
|
}
|
|
|
|
|
2016-07-28 02:16:50 +02:00
|
|
|
cache_set () {
|
2009-04-24 20:13:34 +02:00
|
|
|
oldrev="$1"
|
|
|
|
newrev="$2"
|
2016-07-28 02:16:49 +02:00
|
|
|
if test "$oldrev" != "latest_old" &&
|
|
|
|
test "$oldrev" != "latest_new" &&
|
|
|
|
test -e "$cachedir/$oldrev"
|
|
|
|
then
|
2009-04-24 20:13:34 +02:00
|
|
|
die "cache for $oldrev already exists!"
|
|
|
|
fi
|
|
|
|
echo "$newrev" >"$cachedir/$oldrev"
|
|
|
|
}
|
|
|
|
|
2016-07-28 02:16:50 +02:00
|
|
|
rev_exists () {
|
2016-07-28 02:16:49 +02:00
|
|
|
if git rev-parse "$1" >/dev/null 2>&1
|
|
|
|
then
|
2009-05-30 07:05:43 +02:00
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-07-28 02:16:50 +02:00
|
|
|
rev_is_descendant_of_branch () {
|
2010-01-09 19:56:05 +01:00
|
|
|
newrev="$1"
|
|
|
|
branch="$2"
|
2016-07-28 02:16:49 +02:00
|
|
|
branch_hash=$(git rev-parse "$branch")
|
|
|
|
match=$(git rev-list -1 "$branch_hash" "^$newrev")
|
2010-01-09 19:56:05 +01:00
|
|
|
|
2016-07-28 02:16:49 +02:00
|
|
|
if test -z "$match"
|
|
|
|
then
|
2010-01-09 19:56:05 +01:00
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2009-04-25 06:06:45 +02:00
|
|
|
# if a commit doesn't have a parent, this might not work. But we only want
|
|
|
|
# to remove the parent from the rev-list, and since it doesn't exist, it won't
|
|
|
|
# be there anyway, so do nothing in that case.
|
2016-07-28 02:16:50 +02:00
|
|
|
try_remove_previous () {
|
2016-07-28 02:16:49 +02:00
|
|
|
if rev_exists "$1^"
|
|
|
|
then
|
2009-04-25 06:06:45 +02:00
|
|
|
echo "^$1^"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-07-28 02:16:50 +02:00
|
|
|
find_latest_squash () {
|
2009-05-30 10:11:43 +02:00
|
|
|
debug "Looking for latest squash ($dir)..."
|
2009-05-30 09:18:27 +02:00
|
|
|
dir="$1"
|
2009-05-30 10:11:43 +02:00
|
|
|
sq=
|
|
|
|
main=
|
|
|
|
sub=
|
2009-10-02 21:22:15 +02:00
|
|
|
git log --grep="^git-subtree-dir: $dir/*\$" \
|
2018-02-23 21:41:25 +01:00
|
|
|
--no-show-signature --pretty=format:'START %H%n%s%n%n%b%nEND%n' HEAD |
|
2016-07-28 02:16:49 +02:00
|
|
|
while read a b junk
|
|
|
|
do
|
2009-05-30 10:11:43 +02:00
|
|
|
debug "$a $b $junk"
|
|
|
|
debug "{{$sq/$main/$sub}}"
|
2009-05-30 09:18:27 +02:00
|
|
|
case "$a" in
|
2016-07-28 02:16:49 +02:00
|
|
|
START)
|
|
|
|
sq="$b"
|
|
|
|
;;
|
|
|
|
git-subtree-mainline:)
|
|
|
|
main="$b"
|
|
|
|
;;
|
|
|
|
git-subtree-split:)
|
|
|
|
sub="$(git rev-parse "$b^0")" ||
|
|
|
|
die "could not rev-parse split hash $b from commit $sq"
|
|
|
|
;;
|
|
|
|
END)
|
|
|
|
if test -n "$sub"
|
|
|
|
then
|
|
|
|
if test -n "$main"
|
|
|
|
then
|
|
|
|
# a rejoin commit?
|
|
|
|
# Pretend its sub was a squash.
|
|
|
|
sq="$sub"
|
2009-05-30 09:18:27 +02:00
|
|
|
fi
|
2016-07-28 02:16:49 +02:00
|
|
|
debug "Squash found: $sq $sub"
|
|
|
|
echo "$sq" "$sub"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
sq=
|
|
|
|
main=
|
|
|
|
sub=
|
|
|
|
;;
|
2009-05-30 09:18:27 +02:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2016-07-28 02:16:50 +02:00
|
|
|
find_existing_splits () {
|
2009-04-24 22:48:08 +02:00
|
|
|
debug "Looking for prior splits..."
|
|
|
|
dir="$1"
|
|
|
|
revs="$2"
|
2009-05-30 10:11:43 +02:00
|
|
|
main=
|
|
|
|
sub=
|
2009-10-02 21:22:15 +02:00
|
|
|
git log --grep="^git-subtree-dir: $dir/*\$" \
|
2018-02-23 21:41:25 +01:00
|
|
|
--no-show-signature --pretty=format:'START %H%n%s%n%n%b%nEND%n' $revs |
|
2016-07-28 02:16:49 +02:00
|
|
|
while read a b junk
|
|
|
|
do
|
2009-04-24 22:48:08 +02:00
|
|
|
case "$a" in
|
2016-07-28 02:16:49 +02:00
|
|
|
START)
|
|
|
|
sq="$b"
|
|
|
|
;;
|
|
|
|
git-subtree-mainline:)
|
|
|
|
main="$b"
|
|
|
|
;;
|
|
|
|
git-subtree-split:)
|
|
|
|
sub="$(git rev-parse "$b^0")" ||
|
|
|
|
die "could not rev-parse split hash $b from commit $sq"
|
|
|
|
;;
|
|
|
|
END)
|
|
|
|
debug " Main is: '$main'"
|
|
|
|
if test -z "$main" -a -n "$sub"
|
|
|
|
then
|
|
|
|
# squash commits refer to a subtree
|
|
|
|
debug " Squash: $sq from $sub"
|
|
|
|
cache_set "$sq" "$sub"
|
|
|
|
fi
|
|
|
|
if test -n "$main" -a -n "$sub"
|
|
|
|
then
|
|
|
|
debug " Prior: $main -> $sub"
|
|
|
|
cache_set $main $sub
|
|
|
|
cache_set $sub $sub
|
|
|
|
try_remove_previous "$main"
|
|
|
|
try_remove_previous "$sub"
|
|
|
|
fi
|
|
|
|
main=
|
|
|
|
sub=
|
|
|
|
;;
|
2009-04-24 22:48:08 +02:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2016-07-28 02:16:50 +02:00
|
|
|
copy_commit () {
|
2009-05-30 06:47:59 +02:00
|
|
|
# We're going to set some environment vars here, so
|
2009-04-24 20:45:02 +02:00
|
|
|
# do it in a subshell to get rid of them safely later
|
2009-04-26 22:53:57 +02:00
|
|
|
debug copy_commit "{$1}" "{$2}" "{$3}"
|
2018-02-23 21:41:25 +01:00
|
|
|
git log -1 --no-show-signature --pretty=format:'%an%n%ae%n%aD%n%cn%n%ce%n%cD%n%B' "$1" |
|
2009-04-24 20:45:02 +02:00
|
|
|
(
|
|
|
|
read GIT_AUTHOR_NAME
|
|
|
|
read GIT_AUTHOR_EMAIL
|
|
|
|
read GIT_AUTHOR_DATE
|
|
|
|
read GIT_COMMITTER_NAME
|
|
|
|
read GIT_COMMITTER_EMAIL
|
|
|
|
read GIT_COMMITTER_DATE
|
2009-04-24 21:48:41 +02:00
|
|
|
export GIT_AUTHOR_NAME \
|
|
|
|
GIT_AUTHOR_EMAIL \
|
|
|
|
GIT_AUTHOR_DATE \
|
|
|
|
GIT_COMMITTER_NAME \
|
|
|
|
GIT_COMMITTER_EMAIL \
|
|
|
|
GIT_COMMITTER_DATE
|
2016-07-28 02:16:49 +02:00
|
|
|
(
|
|
|
|
printf "%s" "$annotate"
|
|
|
|
cat
|
|
|
|
) |
|
2009-04-24 20:45:02 +02:00
|
|
|
git commit-tree "$2" $3 # reads the rest of stdin
|
|
|
|
) || die "Can't copy commit $1"
|
|
|
|
}
|
|
|
|
|
2016-07-28 02:16:50 +02:00
|
|
|
add_msg () {
|
2009-04-25 05:28:30 +02:00
|
|
|
dir="$1"
|
|
|
|
latest_old="$2"
|
|
|
|
latest_new="$3"
|
2016-07-28 02:16:49 +02:00
|
|
|
if test -n "$message"
|
|
|
|
then
|
2010-01-09 19:55:35 +01:00
|
|
|
commit_message="$message"
|
|
|
|
else
|
|
|
|
commit_message="Add '$dir/' from commit '$latest_new'"
|
|
|
|
fi
|
2009-04-25 05:28:30 +02:00
|
|
|
cat <<-EOF
|
2010-01-09 19:55:35 +01:00
|
|
|
$commit_message
|
2016-07-28 02:16:49 +02:00
|
|
|
|
2009-04-25 05:28:30 +02:00
|
|
|
git-subtree-dir: $dir
|
|
|
|
git-subtree-mainline: $latest_old
|
|
|
|
git-subtree-split: $latest_new
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2016-07-28 02:16:50 +02:00
|
|
|
add_squashed_msg () {
|
2016-07-28 02:16:49 +02:00
|
|
|
if test -n "$message"
|
|
|
|
then
|
2010-01-09 19:55:35 +01:00
|
|
|
echo "$message"
|
|
|
|
else
|
|
|
|
echo "Merge commit '$1' as '$2'"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-07-28 02:16:50 +02:00
|
|
|
rejoin_msg () {
|
2009-04-24 21:48:41 +02:00
|
|
|
dir="$1"
|
|
|
|
latest_old="$2"
|
|
|
|
latest_new="$3"
|
2016-07-28 02:16:49 +02:00
|
|
|
if test -n "$message"
|
|
|
|
then
|
2010-01-09 19:55:35 +01:00
|
|
|
commit_message="$message"
|
|
|
|
else
|
|
|
|
commit_message="Split '$dir/' into commit '$latest_new'"
|
|
|
|
fi
|
2009-04-24 21:48:41 +02:00
|
|
|
cat <<-EOF
|
2010-01-12 22:38:34 +01:00
|
|
|
$commit_message
|
2016-07-28 02:16:49 +02:00
|
|
|
|
2009-04-24 21:48:41 +02:00
|
|
|
git-subtree-dir: $dir
|
2009-04-24 22:48:08 +02:00
|
|
|
git-subtree-mainline: $latest_old
|
|
|
|
git-subtree-split: $latest_new
|
2009-04-24 21:48:41 +02:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2016-07-28 02:16:50 +02:00
|
|
|
squash_msg () {
|
2009-05-30 09:18:27 +02:00
|
|
|
dir="$1"
|
|
|
|
oldsub="$2"
|
|
|
|
newsub="$3"
|
|
|
|
newsub_short=$(git rev-parse --short "$newsub")
|
2016-07-28 02:16:49 +02:00
|
|
|
|
|
|
|
if test -n "$oldsub"
|
|
|
|
then
|
2009-05-30 10:11:43 +02:00
|
|
|
oldsub_short=$(git rev-parse --short "$oldsub")
|
|
|
|
echo "Squashed '$dir/' changes from $oldsub_short..$newsub_short"
|
|
|
|
echo
|
2018-02-23 21:41:25 +01:00
|
|
|
git log --no-show-signature --pretty=tformat:'%h %s' "$oldsub..$newsub"
|
|
|
|
git log --no-show-signature --pretty=tformat:'REVERT: %h %s' "$newsub..$oldsub"
|
2009-05-30 10:11:43 +02:00
|
|
|
else
|
|
|
|
echo "Squashed '$dir/' content from commit $newsub_short"
|
|
|
|
fi
|
2016-07-28 02:16:49 +02:00
|
|
|
|
2009-05-30 10:11:43 +02:00
|
|
|
echo
|
|
|
|
echo "git-subtree-dir: $dir"
|
|
|
|
echo "git-subtree-split: $newsub"
|
2009-05-30 09:18:27 +02:00
|
|
|
}
|
|
|
|
|
2016-07-28 02:16:50 +02:00
|
|
|
toptree_for_commit () {
|
2009-04-25 03:49:19 +02:00
|
|
|
commit="$1"
|
2018-02-23 21:41:25 +01:00
|
|
|
git rev-parse --verify "$commit^{tree}" || exit $?
|
2009-04-25 03:49:19 +02:00
|
|
|
}
|
|
|
|
|
2016-07-28 02:16:50 +02:00
|
|
|
subtree_for_commit () {
|
2009-04-25 03:49:19 +02:00
|
|
|
commit="$1"
|
|
|
|
dir="$2"
|
|
|
|
git ls-tree "$commit" -- "$dir" |
|
2016-07-28 02:16:49 +02:00
|
|
|
while read mode type tree name
|
|
|
|
do
|
|
|
|
assert test "$name" = "$dir"
|
|
|
|
assert test "$type" = "tree" -o "$type" = "commit"
|
|
|
|
test "$type" = "commit" && continue # ignore submodules
|
2009-04-24 23:53:10 +02:00
|
|
|
echo $tree
|
|
|
|
break
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2016-07-28 02:16:50 +02:00
|
|
|
tree_changed () {
|
2009-04-24 23:53:10 +02:00
|
|
|
tree=$1
|
|
|
|
shift
|
2016-07-28 02:16:49 +02:00
|
|
|
if test $# -ne 1
|
|
|
|
then
|
2009-04-24 23:53:10 +02:00
|
|
|
return 0 # weird parents, consider it changed
|
|
|
|
else
|
2009-04-25 03:49:19 +02:00
|
|
|
ptree=$(toptree_for_commit $1)
|
2016-07-28 02:16:49 +02:00
|
|
|
if test "$ptree" != "$tree"
|
|
|
|
then
|
2009-04-24 23:53:10 +02:00
|
|
|
return 0 # changed
|
|
|
|
else
|
|
|
|
return 1 # not changed
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-07-28 02:16:50 +02:00
|
|
|
new_squash_commit () {
|
2009-05-30 09:18:27 +02:00
|
|
|
old="$1"
|
|
|
|
oldsub="$2"
|
|
|
|
newsub="$3"
|
|
|
|
tree=$(toptree_for_commit $newsub) || exit $?
|
2016-07-28 02:16:49 +02:00
|
|
|
if test -n "$old"
|
|
|
|
then
|
|
|
|
squash_msg "$dir" "$oldsub" "$newsub" |
|
|
|
|
git commit-tree "$tree" -p "$old" || exit $?
|
2009-05-30 10:11:43 +02:00
|
|
|
else
|
|
|
|
squash_msg "$dir" "" "$newsub" |
|
2016-07-28 02:16:49 +02:00
|
|
|
git commit-tree "$tree" || exit $?
|
2009-05-30 10:11:43 +02:00
|
|
|
fi
|
2009-05-30 09:18:27 +02:00
|
|
|
}
|
|
|
|
|
2016-07-28 02:16:50 +02:00
|
|
|
copy_or_skip () {
|
2009-04-25 04:05:30 +02:00
|
|
|
rev="$1"
|
|
|
|
tree="$2"
|
|
|
|
newparents="$3"
|
2016-07-28 02:16:49 +02:00
|
|
|
assert test -n "$tree"
|
2009-04-25 04:05:30 +02:00
|
|
|
|
2009-04-25 04:36:06 +02:00
|
|
|
identical=
|
2009-04-26 23:07:16 +02:00
|
|
|
nonidentical=
|
2009-04-25 04:36:06 +02:00
|
|
|
p=
|
2009-04-26 22:53:57 +02:00
|
|
|
gotparents=
|
2016-07-28 02:16:49 +02:00
|
|
|
for parent in $newparents
|
|
|
|
do
|
2009-04-25 04:05:30 +02:00
|
|
|
ptree=$(toptree_for_commit $parent) || exit $?
|
2016-07-28 02:16:49 +02:00
|
|
|
test -z "$ptree" && continue
|
|
|
|
if test "$ptree" = "$tree"
|
|
|
|
then
|
2009-04-25 04:36:06 +02:00
|
|
|
# an identical parent could be used in place of this rev.
|
|
|
|
identical="$parent"
|
2009-04-26 23:07:16 +02:00
|
|
|
else
|
|
|
|
nonidentical="$parent"
|
2009-04-25 04:36:06 +02:00
|
|
|
fi
|
2016-07-28 02:16:49 +02:00
|
|
|
|
2009-04-26 22:53:57 +02:00
|
|
|
# sometimes both old parents map to the same newparent;
|
|
|
|
# eliminate duplicates
|
|
|
|
is_new=1
|
2016-07-28 02:16:49 +02:00
|
|
|
for gp in $gotparents
|
|
|
|
do
|
|
|
|
if test "$gp" = "$parent"
|
|
|
|
then
|
2009-04-26 22:53:57 +02:00
|
|
|
is_new=
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
2016-07-28 02:16:49 +02:00
|
|
|
if test -n "$is_new"
|
|
|
|
then
|
2009-04-26 22:53:57 +02:00
|
|
|
gotparents="$gotparents $parent"
|
2009-04-25 04:05:30 +02:00
|
|
|
p="$p -p $parent"
|
|
|
|
fi
|
|
|
|
done
|
2016-01-15 01:41:43 +01:00
|
|
|
|
|
|
|
copycommit=
|
2016-07-28 02:16:49 +02:00
|
|
|
if test -n "$identical" && test -n "$nonidentical"
|
|
|
|
then
|
2016-01-15 01:41:43 +01:00
|
|
|
extras=$(git rev-list --count $identical..$nonidentical)
|
2016-07-28 02:16:49 +02:00
|
|
|
if test "$extras" -ne 0
|
|
|
|
then
|
2016-01-15 01:41:43 +01:00
|
|
|
# we need to preserve history along the other branch
|
|
|
|
copycommit=1
|
|
|
|
fi
|
|
|
|
fi
|
2016-07-28 02:16:49 +02:00
|
|
|
if test -n "$identical" && test -z "$copycommit"
|
|
|
|
then
|
2009-04-25 04:36:06 +02:00
|
|
|
echo $identical
|
|
|
|
else
|
2016-07-28 02:16:49 +02:00
|
|
|
copy_commit "$rev" "$tree" "$p" || exit $?
|
2009-04-25 04:36:06 +02:00
|
|
|
fi
|
2009-04-25 04:05:30 +02:00
|
|
|
}
|
|
|
|
|
2016-07-28 02:16:50 +02:00
|
|
|
ensure_clean () {
|
2016-07-28 02:16:49 +02:00
|
|
|
if ! git diff-index HEAD --exit-code --quiet 2>&1
|
|
|
|
then
|
2009-04-25 05:28:30 +02:00
|
|
|
die "Working tree has modifications. Cannot add."
|
|
|
|
fi
|
2016-07-28 02:16:49 +02:00
|
|
|
if ! git diff-index --cached HEAD --exit-code --quiet 2>&1
|
|
|
|
then
|
2009-04-25 05:28:30 +02:00
|
|
|
die "Index has modifications. Cannot add."
|
|
|
|
fi
|
2009-04-25 05:41:19 +02:00
|
|
|
}
|
|
|
|
|
2016-07-28 02:16:50 +02:00
|
|
|
ensure_valid_ref_format () {
|
2013-11-27 19:34:09 +01:00
|
|
|
git check-ref-format "refs/heads/$1" ||
|
2016-07-28 02:16:49 +02:00
|
|
|
die "'$1' does not look like a ref"
|
2013-11-27 19:34:09 +01:00
|
|
|
}
|
|
|
|
|
2016-07-28 02:16:50 +02:00
|
|
|
cmd_add () {
|
2016-07-28 02:16:49 +02:00
|
|
|
if test -e "$dir"
|
|
|
|
then
|
2009-04-25 05:41:19 +02:00
|
|
|
die "'$dir' already exists. Cannot add."
|
|
|
|
fi
|
2010-02-13 20:32:21 +01:00
|
|
|
|
2009-04-25 05:41:19 +02:00
|
|
|
ensure_clean
|
2016-07-28 02:16:49 +02:00
|
|
|
|
|
|
|
if test $# -eq 1
|
|
|
|
then
|
|
|
|
git rev-parse -q --verify "$1^{commit}" >/dev/null ||
|
|
|
|
die "'$1' does not refer to a commit"
|
|
|
|
|
|
|
|
cmd_add_commit "$@"
|
|
|
|
|
|
|
|
elif test $# -eq 2
|
|
|
|
then
|
|
|
|
# Technically we could accept a refspec here but we're
|
|
|
|
# just going to turn around and add FETCH_HEAD under the
|
|
|
|
# specified directory. Allowing a refspec might be
|
|
|
|
# misleading because we won't do anything with any other
|
|
|
|
# branches fetched via the refspec.
|
|
|
|
ensure_valid_ref_format "$2"
|
|
|
|
|
|
|
|
cmd_add_repository "$@"
|
2010-02-13 20:32:21 +01:00
|
|
|
else
|
2016-07-28 02:16:49 +02:00
|
|
|
say "error: parameters were '$@'"
|
|
|
|
die "Provide either a commit or a repository and commit."
|
2009-04-25 05:28:30 +02:00
|
|
|
fi
|
2010-02-13 20:32:21 +01:00
|
|
|
}
|
|
|
|
|
2016-07-28 02:16:50 +02:00
|
|
|
cmd_add_repository () {
|
2010-02-13 20:32:21 +01:00
|
|
|
echo "git fetch" "$@"
|
|
|
|
repository=$1
|
|
|
|
refspec=$2
|
|
|
|
git fetch "$@" || exit $?
|
|
|
|
revs=FETCH_HEAD
|
|
|
|
set -- $revs
|
|
|
|
cmd_add_commit "$@"
|
|
|
|
}
|
|
|
|
|
2016-07-28 02:16:50 +02:00
|
|
|
cmd_add_commit () {
|
2010-02-13 20:32:21 +01:00
|
|
|
revs=$(git rev-parse $default --revs-only "$@") || exit $?
|
|
|
|
set -- $revs
|
2009-04-25 05:28:30 +02:00
|
|
|
rev="$1"
|
2016-07-28 02:16:49 +02:00
|
|
|
|
2009-04-25 05:28:30 +02:00
|
|
|
debug "Adding $dir as '$rev'..."
|
|
|
|
git read-tree --prefix="$dir" $rev || exit $?
|
2009-08-26 16:43:43 +02:00
|
|
|
git checkout -- "$dir" || exit $?
|
2009-04-25 05:28:30 +02:00
|
|
|
tree=$(git write-tree) || exit $?
|
2016-07-28 02:16:49 +02:00
|
|
|
|
2009-04-25 05:28:30 +02:00
|
|
|
headrev=$(git rev-parse HEAD) || exit $?
|
2016-07-28 02:16:49 +02:00
|
|
|
if test -n "$headrev" && test "$headrev" != "$rev"
|
|
|
|
then
|
2009-04-25 05:28:30 +02:00
|
|
|
headp="-p $headrev"
|
|
|
|
else
|
|
|
|
headp=
|
|
|
|
fi
|
2016-07-28 02:16:49 +02:00
|
|
|
|
|
|
|
if test -n "$squash"
|
|
|
|
then
|
2009-05-30 10:11:43 +02:00
|
|
|
rev=$(new_squash_commit "" "" "$rev") || exit $?
|
2010-01-09 19:55:35 +01:00
|
|
|
commit=$(add_squashed_msg "$rev" "$dir" |
|
2016-07-28 02:16:49 +02:00
|
|
|
git commit-tree "$tree" $headp -p "$rev") || exit $?
|
2009-05-30 10:11:43 +02:00
|
|
|
else
|
2014-05-13 06:08:58 +02:00
|
|
|
revp=$(peel_committish "$rev") &&
|
2016-07-28 02:16:49 +02:00
|
|
|
commit=$(add_msg "$dir" $headrev "$rev" |
|
|
|
|
git commit-tree "$tree" $headp -p "$revp") || exit $?
|
2009-05-30 10:11:43 +02:00
|
|
|
fi
|
2009-04-25 05:28:30 +02:00
|
|
|
git reset "$commit" || exit $?
|
2016-07-28 02:16:49 +02:00
|
|
|
|
2009-05-30 10:11:43 +02:00
|
|
|
say "Added dir '$dir'"
|
2009-04-25 05:28:30 +02:00
|
|
|
}
|
|
|
|
|
2016-07-28 02:16:50 +02:00
|
|
|
cmd_split () {
|
2009-04-24 20:13:34 +02:00
|
|
|
debug "Splitting $dir..."
|
|
|
|
cache_setup || exit $?
|
2016-07-28 02:16:49 +02:00
|
|
|
|
|
|
|
if test -n "$onto"
|
|
|
|
then
|
2009-04-25 03:35:50 +02:00
|
|
|
debug "Reading history for --onto=$onto..."
|
2009-04-24 23:05:14 +02:00
|
|
|
git rev-list $onto |
|
2016-07-28 02:16:49 +02:00
|
|
|
while read rev
|
|
|
|
do
|
2009-04-24 23:05:14 +02:00
|
|
|
# the 'onto' history is already just the subdir, so
|
|
|
|
# any parent we find there can be used verbatim
|
2009-04-24 23:42:33 +02:00
|
|
|
debug " cache: $rev"
|
2016-07-28 02:16:49 +02:00
|
|
|
cache_set "$rev" "$rev"
|
2009-04-24 23:05:14 +02:00
|
|
|
done
|
|
|
|
fi
|
2016-07-28 02:16:49 +02:00
|
|
|
|
|
|
|
if test -n "$ignore_joins"
|
|
|
|
then
|
2009-04-25 04:36:06 +02:00
|
|
|
unrevs=
|
|
|
|
else
|
|
|
|
unrevs="$(find_existing_splits "$dir" "$revs")"
|
|
|
|
fi
|
2016-07-28 02:16:49 +02:00
|
|
|
|
2009-04-26 21:54:42 +02:00
|
|
|
# We can't restrict rev-list to only $dir here, because some of our
|
|
|
|
# parents have the $dir contents the root, and those won't match.
|
|
|
|
# (and rev-list --follow doesn't seem to solve this)
|
2010-11-09 15:34:49 +01:00
|
|
|
grl='git rev-list --topo-order --reverse --parents $revs $unrevs'
|
2009-04-27 00:06:08 +02:00
|
|
|
revmax=$(eval "$grl" | wc -l)
|
|
|
|
revcount=0
|
|
|
|
createcount=0
|
|
|
|
eval "$grl" |
|
2016-07-28 02:16:49 +02:00
|
|
|
while read rev parents
|
|
|
|
do
|
2009-04-27 00:06:08 +02:00
|
|
|
revcount=$(($revcount + 1))
|
2015-05-08 02:56:59 +02:00
|
|
|
progress "$revcount/$revmax ($createcount)"
|
2009-04-24 23:42:33 +02:00
|
|
|
debug "Processing commit: $rev"
|
2016-07-28 02:16:49 +02:00
|
|
|
exists=$(cache_get "$rev")
|
|
|
|
if test -n "$exists"
|
|
|
|
then
|
2009-04-24 22:48:08 +02:00
|
|
|
debug " prior: $exists"
|
|
|
|
continue
|
|
|
|
fi
|
2009-04-27 00:06:08 +02:00
|
|
|
createcount=$(($createcount + 1))
|
2009-04-24 23:42:33 +02:00
|
|
|
debug " parents: $parents"
|
|
|
|
newparents=$(cache_get $parents)
|
|
|
|
debug " newparents: $newparents"
|
2016-07-28 02:16:49 +02:00
|
|
|
|
|
|
|
tree=$(subtree_for_commit "$rev" "$dir")
|
2009-04-24 23:53:10 +02:00
|
|
|
debug " tree is: $tree"
|
2010-11-10 05:18:36 +01:00
|
|
|
|
|
|
|
check_parents $parents
|
2016-07-28 02:16:49 +02:00
|
|
|
|
2009-05-30 07:28:20 +02:00
|
|
|
# ugly. is there no better way to tell if this is a subtree
|
|
|
|
# vs. a mainline commit? Does it matter?
|
2016-07-28 02:16:49 +02:00
|
|
|
if test -z "$tree"
|
|
|
|
then
|
|
|
|
set_notree "$rev"
|
|
|
|
if test -n "$newparents"
|
|
|
|
then
|
|
|
|
cache_set "$rev" "$rev"
|
2010-05-20 22:40:09 +02:00
|
|
|
fi
|
2010-01-09 23:01:39 +01:00
|
|
|
continue
|
|
|
|
fi
|
2009-04-24 23:53:10 +02:00
|
|
|
|
2009-04-25 04:05:30 +02:00
|
|
|
newrev=$(copy_or_skip "$rev" "$tree" "$newparents") || exit $?
|
2009-04-24 23:53:10 +02:00
|
|
|
debug " newrev is: $newrev"
|
2016-07-28 02:16:49 +02:00
|
|
|
cache_set "$rev" "$newrev"
|
|
|
|
cache_set latest_new "$newrev"
|
|
|
|
cache_set latest_old "$rev"
|
2009-04-24 20:24:38 +02:00
|
|
|
done || exit $?
|
2016-07-28 02:16:49 +02:00
|
|
|
|
2009-04-24 21:48:41 +02:00
|
|
|
latest_new=$(cache_get latest_new)
|
2016-07-28 02:16:49 +02:00
|
|
|
if test -z "$latest_new"
|
|
|
|
then
|
2009-04-24 20:52:27 +02:00
|
|
|
die "No new revisions were found"
|
|
|
|
fi
|
2016-07-28 02:16:49 +02:00
|
|
|
|
|
|
|
if test -n "$rejoin"
|
|
|
|
then
|
2009-04-24 21:48:41 +02:00
|
|
|
debug "Merging split branch into HEAD..."
|
|
|
|
latest_old=$(cache_get latest_old)
|
|
|
|
git merge -s ours \
|
2016-07-26 06:14:15 +02:00
|
|
|
--allow-unrelated-histories \
|
2016-07-28 02:16:49 +02:00
|
|
|
-m "$(rejoin_msg "$dir" "$latest_old" "$latest_new")" \
|
|
|
|
"$latest_new" >&2 || exit $?
|
|
|
|
fi
|
|
|
|
if test -n "$branch"
|
|
|
|
then
|
|
|
|
if rev_exists "refs/heads/$branch"
|
|
|
|
then
|
|
|
|
if ! rev_is_descendant_of_branch "$latest_new" "$branch"
|
|
|
|
then
|
2010-01-09 19:56:05 +01:00
|
|
|
die "Branch '$branch' is not an ancestor of commit '$latest_new'."
|
|
|
|
fi
|
|
|
|
action='Updated'
|
|
|
|
else
|
|
|
|
action='Created'
|
|
|
|
fi
|
2016-07-28 02:16:49 +02:00
|
|
|
git update-ref -m 'subtree split' \
|
|
|
|
"refs/heads/$branch" "$latest_new" || exit $?
|
2010-01-09 19:56:05 +01:00
|
|
|
say "$action branch '$branch'"
|
2009-05-30 07:05:43 +02:00
|
|
|
fi
|
2016-07-28 02:16:49 +02:00
|
|
|
echo "$latest_new"
|
2009-04-24 20:13:34 +02:00
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
2016-07-28 02:16:50 +02:00
|
|
|
cmd_merge () {
|
2010-02-13 20:32:21 +01:00
|
|
|
revs=$(git rev-parse $default --revs-only "$@") || exit $?
|
2009-04-25 05:41:19 +02:00
|
|
|
ensure_clean
|
2016-07-28 02:16:49 +02:00
|
|
|
|
2009-04-25 05:41:19 +02:00
|
|
|
set -- $revs
|
2016-07-28 02:16:49 +02:00
|
|
|
if test $# -ne 1
|
|
|
|
then
|
2009-04-25 05:41:19 +02:00
|
|
|
die "You must provide exactly one revision. Got: '$revs'"
|
|
|
|
fi
|
|
|
|
rev="$1"
|
2016-07-28 02:16:49 +02:00
|
|
|
|
|
|
|
if test -n "$squash"
|
|
|
|
then
|
2009-05-30 09:18:27 +02:00
|
|
|
first_split="$(find_latest_squash "$dir")"
|
2016-07-28 02:16:49 +02:00
|
|
|
if test -z "$first_split"
|
|
|
|
then
|
2009-05-30 09:18:27 +02:00
|
|
|
die "Can't squash-merge: '$dir' was never added."
|
|
|
|
fi
|
|
|
|
set $first_split
|
|
|
|
old=$1
|
|
|
|
sub=$2
|
2016-07-28 02:16:49 +02:00
|
|
|
if test "$sub" = "$rev"
|
|
|
|
then
|
2009-05-30 09:33:17 +02:00
|
|
|
say "Subtree is already at commit $rev."
|
|
|
|
exit 0
|
|
|
|
fi
|
2009-05-30 09:18:27 +02:00
|
|
|
new=$(new_squash_commit "$old" "$sub" "$rev") || exit $?
|
|
|
|
debug "New squash commit: $new"
|
|
|
|
rev="$new"
|
|
|
|
fi
|
2010-05-07 21:21:25 +02:00
|
|
|
|
|
|
|
version=$(git version)
|
2016-07-28 02:16:49 +02:00
|
|
|
if test "$version" \< "git version 1.7"
|
|
|
|
then
|
|
|
|
if test -n "$message"
|
|
|
|
then
|
|
|
|
git merge -s subtree --message="$message" "$rev"
|
2010-05-07 21:21:25 +02:00
|
|
|
else
|
2016-07-28 02:16:49 +02:00
|
|
|
git merge -s subtree "$rev"
|
2010-05-07 21:21:25 +02:00
|
|
|
fi
|
2010-02-06 21:05:17 +01:00
|
|
|
else
|
2016-07-28 02:16:49 +02:00
|
|
|
if test -n "$message"
|
|
|
|
then
|
|
|
|
git merge -Xsubtree="$prefix" \
|
|
|
|
--message="$message" "$rev"
|
2010-05-07 21:21:25 +02:00
|
|
|
else
|
|
|
|
git merge -Xsubtree="$prefix" $rev
|
|
|
|
fi
|
2010-02-06 21:05:17 +01:00
|
|
|
fi
|
2009-04-25 05:41:19 +02:00
|
|
|
}
|
|
|
|
|
2016-07-28 02:16:50 +02:00
|
|
|
cmd_pull () {
|
2016-07-28 02:16:49 +02:00
|
|
|
if test $# -ne 2
|
|
|
|
then
|
|
|
|
die "You must provide <repository> <ref>"
|
2013-11-27 19:34:09 +01:00
|
|
|
fi
|
2009-04-25 05:41:19 +02:00
|
|
|
ensure_clean
|
2013-11-27 19:34:09 +01:00
|
|
|
ensure_valid_ref_format "$2"
|
2009-10-03 00:23:54 +02:00
|
|
|
git fetch "$@" || exit $?
|
|
|
|
revs=FETCH_HEAD
|
2010-02-13 20:32:21 +01:00
|
|
|
set -- $revs
|
|
|
|
cmd_merge "$@"
|
|
|
|
}
|
|
|
|
|
2016-07-28 02:16:50 +02:00
|
|
|
cmd_push () {
|
2016-07-28 02:16:49 +02:00
|
|
|
if test $# -ne 2
|
|
|
|
then
|
|
|
|
die "You must provide <repository> <ref>"
|
2010-02-13 20:32:21 +01:00
|
|
|
fi
|
2013-11-27 19:34:09 +01:00
|
|
|
ensure_valid_ref_format "$2"
|
2016-07-28 02:16:49 +02:00
|
|
|
if test -e "$dir"
|
|
|
|
then
|
|
|
|
repository=$1
|
|
|
|
refspec=$2
|
|
|
|
echo "git push using: " "$repository" "$refspec"
|
|
|
|
localrev=$(git subtree split --prefix="$prefix") || die
|
|
|
|
git push "$repository" "$localrev":"refs/heads/$refspec"
|
2010-02-13 20:32:21 +01:00
|
|
|
else
|
2016-07-28 02:16:49 +02:00
|
|
|
die "'$dir' must already exist. Try 'git subtree add'."
|
2010-02-13 20:32:21 +01:00
|
|
|
fi
|
2009-04-24 20:13:34 +02:00
|
|
|
}
|
|
|
|
|
2009-04-25 05:41:19 +02:00
|
|
|
"cmd_$command" "$@"
|