From 448e71e2637e0d7546fb0a2b386e74bc7aa93be8 Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Fri, 7 May 2010 21:21:25 +0200 Subject: [PATCH 1/2] Use 'git merge -Xsubtree' when git version >= 1.7.0. It's possible to specify the subdir of a subtree since Git 1.7.0 - adding support for that functionality to make the merge more stable. Also checking for git version - now only uses the new subtree subdir option when on at least 1.7. --- git-subtree.sh | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index 501c6dc2f1..b7c350107e 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -634,11 +634,20 @@ cmd_merge() debug "New squash commit: $new" rev="$new" fi - - if [ -n "$message" ]; then - git merge -s subtree --message="$message" $rev + + version=$(git version) + if [ "$version" \< "git version 1.7" ]; then + if [ -n "$message" ]; then + git merge -s subtree --message="$message" $rev + else + git merge -s subtree $rev + fi else - git merge -s subtree $rev + if [ -n "$message" ]; then + git merge -Xsubtree="$prefix" --message="$message" $rev + else + git merge -Xsubtree="$prefix" $rev + fi fi } From 39f5fff0d53bcc68f5c698150d2d3b35eececc27 Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Thu, 20 May 2010 22:40:09 +0200 Subject: [PATCH 2/2] Fixed regression with splitting out new subtree A folder in a repository that wasn't initially imported as a subtree could no longer be splitted into an entirely new subtree with no parent. A fix and a new test to fix that regression is added here. --- git-subtree.sh | 5 ++++- test.sh | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/git-subtree.sh b/git-subtree.sh index b7c350107e..a86cfd8b9f 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -253,6 +253,7 @@ find_existing_splits() if [ -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 @@ -569,7 +570,9 @@ cmd_split() # ugly. is there no better way to tell if this is a subtree # vs. a mainline commit? Does it matter? if [ -z $tree ]; then - cache_set $rev $rev + if [ -n "$newparents" ]; then + cache_set $rev $rev + fi continue fi diff --git a/test.sh b/test.sh index 8c1f1ea6bd..45237c3374 100755 --- a/test.sh +++ b/test.sh @@ -294,6 +294,15 @@ git subtree split --prefix subdir --branch mainsub4 # but it wasn't, because it's cache was not set to itself) check_equal "$(git log --pretty=format:%P -1 mainsub4)" "$(git rev-parse sub3)" +mkdir subdir2 +create subdir2/main-sub5 +git commit -m "main-sub5" +git subtree split --prefix subdir2 --branch mainsub5 + +# also test that we still can split out an entirely new subtree +# if the parent of the first commit in the tree isn't empty, +# then the new subtree has accidently been attached to something +check_equal "$(git log --pretty=format:%P -1 mainsub5)" "" # make sure no patch changes more than one file. The original set of commits