summaryrefslogtreecommitdiff
path: root/contrib/subtree/git-subtree.sh
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@datawire.io>2021-04-27 21:17:45 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-04-28 07:47:19 (GMT)
commitcb6551447b8e0c35408b766ad605ba357f720a0d (patch)
tree97a2b36766fb94568733ab4be4e35982b06df9d4 /contrib/subtree/git-subtree.sh
parent6468784dd2ca3ea2408f9915ab9b7ce136f0b024 (diff)
downloadgit-cb6551447b8e0c35408b766ad605ba357f720a0d.zip
git-cb6551447b8e0c35408b766ad605ba357f720a0d.tar.gz
git-cb6551447b8e0c35408b766ad605ba357f720a0d.tar.bz2
subtree: allow --squash to be used with --rejoin
Besides being a genuinely useful thing to do, this also just makes sense and harmonizes which flags may be used when. `git subtree split --rejoin` amounts to "automatically go ahead and do a `git subtree merge` after doing the main `git subtree split`", so it's weird and arbitrary that you can't pass `--squash` to `git subtree split --rejoin` like you can `git subtree merge`. It's weird that `git subtree split --rejoin` inherits `git subtree merge`'s `--message` but not `--squash`. Reconcile the situation by just having `split --rejoin` actually just call `merge` internally (or call `add` instead, as appropriate), so it can get access to the full `merge` behavior, including `--squash`. Signed-off-by: Luke Shumaker <lukeshu@datawire.io> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'contrib/subtree/git-subtree.sh')
-rwxr-xr-xcontrib/subtree/git-subtree.sh37
1 files changed, 29 insertions, 8 deletions
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 3bffddf..25d69d7 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -33,15 +33,15 @@ h,help show the help
q quiet
d show debug messages
P,prefix= the name of the subdir to split out
-m,message= use the given message as the commit message for the merge commit
options for 'split'
annotate= add a prefix to commit message of new commits
b,branch= create a new branch from the split subtree
ignore-joins ignore prior --rejoin commits
onto= try connecting new tree to an existing one
rejoin merge the new branch back into HEAD
- options for 'add' and 'merge' (also: 'pull')
+ options for 'add' and 'merge' (also: 'pull' and 'split --rejoin')
squash merge subtree changes as a single commit
+m,message= use the given message as the commit message for the merge commit
"
arg_debug=
@@ -346,7 +346,8 @@ find_latest_squash () {
then
# a rejoin commit?
# Pretend its sub was a squash.
- sq="$sub"
+ sq=$(git rev-parse --verify "$sq^2") ||
+ die
fi
debug "Squash found: $sq $sub"
echo "$sq" "$sub"
@@ -453,6 +454,13 @@ add_msg () {
else
commit_message="Add '$dir/' from commit '$latest_new'"
fi
+ if test -n "$arg_split_rejoin"
+ then
+ # If this is from a --rejoin, then rejoin_msg has
+ # already inserted the `git-subtree-xxx:` tags
+ echo "$commit_message"
+ return
+ fi
cat <<-EOF
$commit_message
@@ -775,7 +783,12 @@ cmd_add_commit () {
rev=$(git rev-parse --verify "$1^{commit}") || exit $?
debug "Adding $dir as '$rev'..."
- git read-tree --prefix="$dir" $rev || exit $?
+ if test -z "$arg_split_rejoin"
+ then
+ # Only bother doing this if this is a genuine 'add',
+ # not a synthetic 'add' from '--rejoin'.
+ git read-tree --prefix="$dir" $rev || exit $?
+ fi
git checkout -- "$dir" || exit $?
tree=$(git write-tree) || exit $?
@@ -815,6 +828,11 @@ cmd_split () {
die "You must provide exactly one revision. Got: '$*'"
fi
+ if test -n "$arg_split_rejoin"
+ then
+ ensure_clean
+ fi
+
debug "Splitting $dir..."
cache_setup || exit $?
@@ -857,10 +875,13 @@ cmd_split () {
then
debug "Merging split branch into HEAD..."
latest_old=$(cache_get latest_old) || exit $?
- git merge -s ours \
- --allow-unrelated-histories \
- -m "$(rejoin_msg "$dir" "$latest_old" "$latest_new")" \
- "$latest_new" >&2 || exit $?
+ arg_addmerge_message="$(rejoin_msg "$dir" "$latest_old" "$latest_new")" || exit $?
+ if test -z "$(find_latest_squash "$dir")"
+ then
+ cmd_add "$latest_new" >&2 || exit $?
+ else
+ cmd_merge "$latest_new" >&2 || exit $?
+ fi
fi
if test -n "$arg_split_branch"
then