From: Techlive Zheng <techlivezheng@xxxxxxxxx> Use %B to format the commit message and body to avoid an extra newline if a commit only has a subject line. Author: Techlive Zheng <techlivezheng@xxxxxxxxx> Signed-off-by: David A. Greene <greened@xxxxxxxxxxxxx> --- contrib/subtree/git-subtree.sh | 5 +++ contrib/subtree/t/t7900-subtree.sh | 73 ++++++++++++++++++++++-------------- 2 files changed, 49 insertions(+), 29 deletions(-) diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index 920c664..f2b6d4a 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -296,7 +296,12 @@ copy_commit() # We're going to set some environment vars here, so # do it in a subshell to get rid of them safely later debug copy_commit "{$1}" "{$2}" "{$3}" + # Use %B rather than %s%n%n%b to handle the special case of a + # commit that only has a subject line. We don't want to + # introduce a newline after the subject, causing generation of + # a new hash. git log -1 --pretty=format:'%an%n%ae%n%ad%n%cn%n%ce%n%cd%n%s%n%n%b' "$1" | +# git log -1 --pretty=format:'%an%n%ae%n%ad%n%cn%n%ce%n%cd%n%B' "$1" | ( read GIT_AUTHOR_NAME read GIT_AUTHOR_EMAIL diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh index bc2eeb0..93eeb09 100755 --- a/contrib/subtree/t/t7900-subtree.sh +++ b/contrib/subtree/t/t7900-subtree.sh @@ -76,6 +76,10 @@ test_expect_success 'add sub1' ' git branch -m master subproj ' +# Save this hash for testing later. + +subdir_hash=`git rev-parse HEAD` + # 3 test_expect_success 'add sub2' ' create sub2 && @@ -155,7 +159,6 @@ test_expect_success 'add main-sub5' ' create subdir/main-sub5 && git commit -m "main-sub5" ' - # 15 test_expect_success 'add main6' ' create main6 && @@ -235,7 +238,19 @@ test_expect_success 'check split with --branch' ' check_equal ''"$(git rev-parse splitbr1)"'' "$spl1" ' -# 25 +#25 +test_expect_success 'check hash of split' ' + spl1=$(git subtree split --prefix subdir) && + undo && + git subtree split --prefix subdir --branch splitbr1test && + check_equal ''"$(git rev-parse splitbr1test)"'' "$spl1" + git checkout splitbr1test && + new_hash=$(git rev-parse HEAD~2) && + git checkout mainline && + check_equal ''"$new_hash"'' "$subdir_hash" +' + +# 26 test_expect_success 'check split with --branch for an existing branch' ' spl1=''"$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"'' && undo && @@ -244,13 +259,13 @@ test_expect_success 'check split with --branch for an existing branch' ' check_equal ''"$(git rev-parse splitbr2)"'' "$spl1" ' -# 26 +# 27 test_expect_success 'check split with --branch for an incompatible branch' ' test_must_fail git subtree split --prefix subdir --onto FETCH_HEAD --branch subdir ' -# 27 +# 28 test_expect_success 'check split+rejoin' ' spl1=''"$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"'' && undo && @@ -258,7 +273,7 @@ test_expect_success 'check split+rejoin' ' check_equal ''"$(last_commit_message)"'' "Split '"'"'subdir/'"'"' into commit '"'"'"$spl1"'"'"'" ' -# 28 +# 29 test_expect_success 'add main-sub8' ' create subdir/main-sub8 && git commit -m "main-sub8" @@ -267,14 +282,14 @@ test_expect_success 'add main-sub8' ' # To the subproject! cd ./subproj -# 29 +# 30 test_expect_success 'merge split into subproj' ' git fetch .. spl1 && git branch spl1 FETCH_HEAD && git merge FETCH_HEAD ' -# 30 +# 31 test_expect_success 'add sub9' ' create sub9 && git commit -m "sub9" @@ -283,19 +298,19 @@ test_expect_success 'add sub9' ' # Back to mainline cd .. -# 31 +# 32 test_expect_success 'split for sub8' ' split2=''"$(git subtree split --annotate='"'*'"' --prefix subdir/ --rejoin)"'' git branch split2 "$split2" ' -# 32 +# 33 test_expect_success 'add main-sub10' ' create subdir/main-sub10 && git commit -m "main-sub10" ' -# 33 +# 34 test_expect_success 'split for sub10' ' spl3=''"$(git subtree split --annotate='"'*'"' --prefix subdir --rejoin)"'' && git branch spl3 "$spl3" @@ -304,7 +319,7 @@ test_expect_success 'split for sub10' ' # To the subproject! cd ./subproj -# 34 +# 35 test_expect_success 'merge split into subproj' ' git fetch .. spl3 && git branch spl3 FETCH_HEAD && @@ -318,13 +333,13 @@ chkms_sub=$(echo $chkms | multiline | sed 's,^,subdir/,' | fixnl) chks="sub1 sub2 sub3 sub9" chks_sub=$(echo $chks | multiline | sed 's,^,subdir/,' | fixnl) -# 35 +# 36 test_expect_success 'make sure exactly the right set of files ends up in the subproj' ' subfiles=''"$(git ls-files | fixnl)"'' && check_equal "$subfiles" "$chkms $chks" ' -# 36 +# 37 test_expect_success 'make sure the subproj history *only* contains commits that affect the subdir' ' allchanges=''"$(git log --name-only --pretty=format:'"''"' | sort | fixnl)"'' && check_equal "$allchanges" "$chkms $chks" @@ -333,20 +348,20 @@ test_expect_success 'make sure the subproj history *only* contains commits that # Back to mainline cd .. -# 37 +# 38 test_expect_success 'pull from subproj' ' git fetch ./subproj subproj-merge-spl3 && git branch subproj-merge-spl3 FETCH_HEAD && git subtree pull --prefix=subdir ./subproj subproj-merge-spl3 ' -# 38 +# 39 test_expect_success 'make sure exactly the right set of files ends up in the mainline' ' mainfiles=''"$(git ls-files | fixnl)"'' && check_equal "$mainfiles" "$chkm $chkms_sub $chks_sub" ' -# 39 +# 40 test_expect_success 'make sure each filename changed exactly once in the entire history' ' # main-sub?? and /subdir/main-sub?? both change, because those are the # changes that were split into their own history. And subdir/sub?? never @@ -355,12 +370,12 @@ test_expect_success 'make sure each filename changed exactly once in the entire check_equal "$allchanges" ''"$(echo $chkms $chkm $chks $chkms_sub | multiline | sort | fixnl)"'' ' -# 40 +# 41 test_expect_success 'make sure the --rejoin commits never make it into subproj' ' check_equal ''"$(git log --pretty=format:'"'%s'"' HEAD^2 | grep -i split)"'' "" ' -# 41 +# 42 test_expect_success 'make sure no "git subtree" tagged commits make it into subproj' ' # They are meaningless to subproj since one side of the merge refers to the mainline check_equal ''"$(git log --pretty=format:'"'%s%n%b'"' HEAD^2 | grep "git-subtree.*:")"'' "" @@ -370,14 +385,14 @@ test_expect_success 'make sure no "git subtree" tagged commits make it into subp mkdir test2 cd test2 -# 42 +# 43 test_expect_success 'init main' ' test_create_repo main ' cd main -# 43 +# 44 test_expect_success 'add main1' ' create main1 && git commit -m "main1" @@ -385,14 +400,14 @@ test_expect_success 'add main1' ' cd .. -# 44 +# 45 test_expect_success 'init sub' ' test_create_repo sub ' cd sub -# 45 +# 46 test_expect_success 'add sub2' ' create sub2 && git commit -m "sub2" @@ -402,7 +417,7 @@ cd ../main # check if split can find proper base without --onto -# 46 +# 47 test_expect_success 'add sub as subdir in main' ' git fetch ../sub master && git branch sub2 FETCH_HEAD && @@ -411,7 +426,7 @@ test_expect_success 'add sub as subdir in main' ' cd ../sub -# 47 +# 48 test_expect_success 'add sub3' ' create sub3 && git commit -m "sub3" @@ -419,20 +434,20 @@ test_expect_success 'add sub3' ' cd ../main -# 48 +# 49 test_expect_success 'merge from sub' ' git fetch ../sub master && git branch sub3 FETCH_HEAD && git subtree merge --prefix subdir sub3 ' -# 49 +# 50 test_expect_success 'add main-sub4' ' create subdir/main-sub4 && git commit -m "main-sub4" ' -# 50 +# 51 test_expect_success 'split for main-sub4 without --onto' ' git subtree split --prefix subdir --branch mainsub4 ' @@ -442,12 +457,12 @@ test_expect_success 'split for main-sub4 without --onto' ' # have been sub3, but it was not, because its cache was not set to # itself) -# 51 +# 52 test_expect_success 'check that the commit parent is sub3' ' check_equal ''"$(git log --pretty=format:%P -1 mainsub4)"'' ''"$(git rev-parse sub3)"'' ' -# 52 +# 53 test_expect_success 'add main-sub5' ' mkdir subdir2 && create subdir2/main-sub5 && -- 1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html