git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH/RFC 0/7] mutiple improvements
@ 2013-01-13  1:52 Techlive Zheng
  2013-01-13  1:52 ` [PATCH/RFC 1/7] contrib/subtree: Add vim modeline Techlive Zheng
                   ` (7 more replies)
  0 siblings, 8 replies; 18+ messages in thread
From: Techlive Zheng @ 2013-01-13  1:52 UTC (permalink / raw
  To: git, gitster; +Cc: apenwarr, greened, Techlive Zheng

* refactor tests for 'git subtree'
  * rearrange some tests
  * clean up unnecessary quotes
  * make each test self-contained
* keep commit intact after the split by using '%B'
* handle '--prefix' argument with slash appended correctly

David A. Greene (1):
  contrib/subtree: Remove test number comments

Techlive Zheng (6):
  contrib/subtree: Add vim modeline
  contrib/subtree: Ignore testing directory
  contrib/subtree: Code cleaning and refactoring
  contrib/subtree: Make each test self-contained
  contrib/subtree: Use %B for the split commit message
  contrib/subtree: Handle '--prefix' argument with a slash appended

 contrib/subtree/.gitignore         |    5 +-
 contrib/subtree/git-subtree.sh     |   83 ++-
 contrib/subtree/git-subtree.txt    |   13 +
 contrib/subtree/t/t7900-subtree.sh | 1233 +++++++++++++++++++++++-------------
 4 files changed, 872 insertions(+), 462 deletions(-)

-- 
1.8.1

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH/RFC 1/7] contrib/subtree: Add vim modeline
  2013-01-13  1:52 [PATCH/RFC 0/7] mutiple improvements Techlive Zheng
@ 2013-01-13  1:52 ` Techlive Zheng
  2013-01-13  1:52 ` [PATCH/RFC 2/7] contrib/subtree: Ignore testing directory Techlive Zheng
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 18+ messages in thread
From: Techlive Zheng @ 2013-01-13  1:52 UTC (permalink / raw
  To: git, gitster; +Cc: apenwarr, greened, Techlive Zheng

Signed-off-by: Techlive Zheng <techlivezheng@gmail.com>
---
 contrib/subtree/git-subtree.sh     | 2 ++
 contrib/subtree/t/t7900-subtree.sh | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 920c664..138e1e0 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -710,3 +710,5 @@ cmd_push()
 }
 
 "cmd_$command" "$@"
+
+# vim: set ts=4 sw=4 noet
diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh
index bc2eeb0..3e02aeb 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -506,3 +506,5 @@ test_expect_success 'verify one file change per commit' '
 '
 
 test_done
+
+# vim: set et ts=4 sw=4
-- 
1.8.1

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH/RFC 2/7] contrib/subtree: Ignore testing directory
  2013-01-13  1:52 [PATCH/RFC 0/7] mutiple improvements Techlive Zheng
  2013-01-13  1:52 ` [PATCH/RFC 1/7] contrib/subtree: Add vim modeline Techlive Zheng
@ 2013-01-13  1:52 ` Techlive Zheng
  2013-01-13  1:52 ` [PATCH/RFC 3/7] contrib/subtree: Remove test number comments Techlive Zheng
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 18+ messages in thread
From: Techlive Zheng @ 2013-01-13  1:52 UTC (permalink / raw
  To: git, gitster; +Cc: apenwarr, greened, Techlive Zheng

Signed-off-by: Techlive Zheng <techlivezheng@gmail.com>
---
 contrib/subtree/.gitignore | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/contrib/subtree/.gitignore b/contrib/subtree/.gitignore
index 91360a3..59aeeb4 100644
--- a/contrib/subtree/.gitignore
+++ b/contrib/subtree/.gitignore
@@ -1,6 +1,5 @@
 *~
 git-subtree
-git-subtree.xml
 git-subtree.1
-mainline
-subproj
+git-subtree.xml
+t/trash\ directory.*
-- 
1.8.1

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH/RFC 3/7] contrib/subtree: Remove test number comments
  2013-01-13  1:52 [PATCH/RFC 0/7] mutiple improvements Techlive Zheng
  2013-01-13  1:52 ` [PATCH/RFC 1/7] contrib/subtree: Add vim modeline Techlive Zheng
  2013-01-13  1:52 ` [PATCH/RFC 2/7] contrib/subtree: Ignore testing directory Techlive Zheng
@ 2013-01-13  1:52 ` Techlive Zheng
  2013-01-13  1:52 ` [PATCH/RFC 4/7] contrib/subtree: Code cleaning and refactoring Techlive Zheng
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 18+ messages in thread
From: Techlive Zheng @ 2013-01-13  1:52 UTC (permalink / raw
  To: git, gitster; +Cc: apenwarr, greened, Techlive Zheng

From: "David A. Greene" <greened@obbligato.org>

Delete the comments indicating test numbers as it causes maintenance
headaches.  t*.sh -i will help us find any broken tests.

Signed-off-by: David A. Greene <greened@obbligato.org>
Signed-off-by: Techlive Zheng <techlivezheng@gmail.com>
---
 contrib/subtree/t/t7900-subtree.sh | 55 --------------------------------------
 1 file changed, 55 deletions(-)

diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh
index 3e02aeb..abdcddb 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -60,7 +60,6 @@ last_commit_message()
 	git log --pretty=format:%s -1
 }
 
-# 1
 test_expect_success 'init subproj' '
         test_create_repo subproj
 '
@@ -68,7 +67,6 @@ test_expect_success 'init subproj' '
 # To the subproject!
 cd subproj
 
-# 2
 test_expect_success 'add sub1' '
         create sub1 &&
         git commit -m "sub1" &&
@@ -76,14 +74,12 @@ test_expect_success 'add sub1' '
         git branch -m master subproj
 '
 
-# 3
 test_expect_success 'add sub2' '
         create sub2 &&
         git commit -m "sub2" &&
         git branch sub2
 '
 
-# 4
 test_expect_success 'add sub3' '
         create sub3 &&
         git commit -m "sub3" &&
@@ -93,7 +89,6 @@ test_expect_success 'add sub3' '
 # Back to mainline
 cd ..
 
-# 5
 test_expect_success 'add main4' '
         create main4 &&
         git commit -m "main4" &&
@@ -101,101 +96,85 @@ test_expect_success 'add main4' '
         git branch subdir
 '
 
-# 6
 test_expect_success 'fetch subproj history' '
         git fetch ./subproj sub1 &&
         git branch sub1 FETCH_HEAD
 '
 
-# 7
 test_expect_success 'no subtree exists in main tree' '
         test_must_fail git subtree merge --prefix=subdir sub1
 '
 
-# 8
 test_expect_success 'no pull from non-existant subtree' '
         test_must_fail git subtree pull --prefix=subdir ./subproj sub1
 '
 
-# 9
 test_expect_success 'check if --message works for add' '
         git subtree add --prefix=subdir --message="Added subproject" sub1 &&
         check_equal ''"$(last_commit_message)"'' "Added subproject" &&
         undo
 '
 
-# 10
 test_expect_success 'check if --message works as -m and --prefix as -P' '
         git subtree add -P subdir -m "Added subproject using git subtree" sub1 &&
         check_equal ''"$(last_commit_message)"'' "Added subproject using git subtree" &&
         undo
 '
 
-# 11
 test_expect_success 'check if --message works with squash too' '
         git subtree add -P subdir -m "Added subproject with squash" --squash sub1 &&
         check_equal ''"$(last_commit_message)"'' "Added subproject with squash" &&
         undo
 '
 
-# 12
 test_expect_success 'add subproj to mainline' '
         git subtree add --prefix=subdir/ FETCH_HEAD &&
         check_equal ''"$(last_commit_message)"'' "Add '"'subdir/'"' from commit '"'"'''"$(git rev-parse sub1)"'''"'"'"
 '
 
-# 13
 # this shouldn't actually do anything, since FETCH_HEAD is already a parent
 test_expect_success 'merge fetched subproj' '
         git merge -m "merge -s -ours" -s ours FETCH_HEAD
 '
 
-# 14
 test_expect_success 'add main-sub5' '
         create subdir/main-sub5 &&
         git commit -m "main-sub5"
 '
 
-# 15
 test_expect_success 'add main6' '
         create main6 &&
         git commit -m "main6 boring"
 '
 
-# 16
 test_expect_success 'add main-sub7' '
         create subdir/main-sub7 &&
         git commit -m "main-sub7"
 '
 
-# 17
 test_expect_success 'fetch new subproj history' '
         git fetch ./subproj sub2 &&
         git branch sub2 FETCH_HEAD
 '
 
-# 18
 test_expect_success 'check if --message works for merge' '
         git subtree merge --prefix=subdir -m "Merged changes from subproject" sub2 &&
         check_equal ''"$(last_commit_message)"'' "Merged changes from subproject" &&
         undo
 '
 
-# 19
 test_expect_success 'check if --message for merge works with squash too' '
         git subtree merge --prefix subdir -m "Merged changes from subproject using squash" --squash sub2 &&
         check_equal ''"$(last_commit_message)"'' "Merged changes from subproject using squash" &&
         undo
 '
 
-# 20
 test_expect_success 'merge new subproj history into subdir' '
         git subtree merge --prefix=subdir FETCH_HEAD &&
         git branch pre-split &&
         check_equal ''"$(last_commit_message)"'' "Merge commit '"'"'"$(git rev-parse sub2)"'"'"' into mainline"
 '
 
-# 21
 test_expect_success 'Check that prefix argument is required for split' '
         echo "You must provide the --prefix option." > expected &&
         test_must_fail git subtree split > actual 2>&1 &&
@@ -207,7 +186,6 @@ test_expect_success 'Check that prefix argument is required for split' '
         rm -f expected actual
 '
 
-# 22
 test_expect_success 'Check that the <prefix> exists for a split' '
         echo "'"'"'non-existent-directory'"'"'" does not exist\; use "'"'"'git subtree add'"'"'" > expected &&
         test_must_fail git subtree split --prefix=non-existent-directory > actual 2>&1 &&
@@ -219,7 +197,6 @@ test_expect_success 'Check that the <prefix> exists for a split' '
 #        rm -f expected actual
 '
 
-# 23
 test_expect_success 'check if --message works for split+rejoin' '
         spl1=''"$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"'' &&
         git branch spl1 "$spl1" &&
@@ -227,7 +204,6 @@ test_expect_success 'check if --message works for split+rejoin' '
         undo
 '
 
-# 24
 test_expect_success 'check split with --branch' '
         spl1=$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin) &&
         undo &&
@@ -235,7 +211,6 @@ test_expect_success 'check split with --branch' '
         check_equal ''"$(git rev-parse splitbr1)"'' "$spl1"
 '
 
-# 25
 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 +219,10 @@ test_expect_success 'check split with --branch for an existing branch' '
         check_equal ''"$(git rev-parse splitbr2)"'' "$spl1"
 '
 
-# 26
 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
 test_expect_success 'check split+rejoin' '
         spl1=''"$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"'' &&
         undo &&
@@ -258,7 +230,6 @@ test_expect_success 'check split+rejoin' '
         check_equal ''"$(last_commit_message)"'' "Split '"'"'subdir/'"'"' into commit '"'"'"$spl1"'"'"'"
 '
 
-# 28
 test_expect_success 'add main-sub8' '
         create subdir/main-sub8 &&
         git commit -m "main-sub8"
@@ -267,14 +238,12 @@ test_expect_success 'add main-sub8' '
 # To the subproject!
 cd ./subproj
 
-# 29
 test_expect_success 'merge split into subproj' '
         git fetch .. spl1 &&
         git branch spl1 FETCH_HEAD &&
         git merge FETCH_HEAD
 '
 
-# 30
 test_expect_success 'add sub9' '
         create sub9 &&
         git commit -m "sub9"
@@ -283,19 +252,16 @@ test_expect_success 'add sub9' '
 # Back to mainline
 cd ..
 
-# 31
 test_expect_success 'split for sub8' '
         split2=''"$(git subtree split --annotate='"'*'"' --prefix subdir/ --rejoin)"''
         git branch split2 "$split2"
 '
 
-# 32
 test_expect_success 'add main-sub10' '
         create subdir/main-sub10 &&
         git commit -m "main-sub10"
 '
 
-# 33
 test_expect_success 'split for sub10' '
         spl3=''"$(git subtree split --annotate='"'*'"' --prefix subdir --rejoin)"'' &&
         git branch spl3 "$spl3"
@@ -304,7 +270,6 @@ test_expect_success 'split for sub10' '
 # To the subproject!
 cd ./subproj
 
-# 34
 test_expect_success 'merge split into subproj' '
         git fetch .. spl3 &&
         git branch spl3 FETCH_HEAD &&
@@ -318,13 +283,11 @@ chkms_sub=$(echo $chkms | multiline | sed 's,^,subdir/,' | fixnl)
 chks="sub1 sub2 sub3 sub9"
 chks_sub=$(echo $chks | multiline | sed 's,^,subdir/,' | fixnl)
 
-# 35
 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
 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 +296,17 @@ test_expect_success 'make sure the subproj history *only* contains commits that
 # Back to mainline
 cd ..
 
-# 37
 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
 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
 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 +315,10 @@ 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
 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
 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 +328,12 @@ test_expect_success 'make sure no "git subtree" tagged commits make it into subp
 mkdir test2
 cd test2
 
-# 42
 test_expect_success 'init main' '
         test_create_repo main
 '
 
 cd main
 
-# 43
 test_expect_success 'add main1' '
         create main1 &&
         git commit -m "main1"
@@ -385,14 +341,12 @@ test_expect_success 'add main1' '
 
 cd ..
 
-# 44
 test_expect_success 'init sub' '
         test_create_repo sub
 '
 
 cd sub
 
-# 45
 test_expect_success 'add sub2' '
         create sub2 &&
         git commit -m "sub2"
@@ -402,7 +356,6 @@ cd ../main
 
 # check if split can find proper base without --onto
 
-# 46
 test_expect_success 'add sub as subdir in main' '
         git fetch ../sub master &&
         git branch sub2 FETCH_HEAD &&
@@ -411,7 +364,6 @@ test_expect_success 'add sub as subdir in main' '
 
 cd ../sub
 
-# 47
 test_expect_success 'add sub3' '
         create sub3 &&
         git commit -m "sub3"
@@ -419,20 +371,17 @@ test_expect_success 'add sub3' '
 
 cd ../main
 
-# 48
 test_expect_success 'merge from sub' '
         git fetch ../sub master &&
         git branch sub3 FETCH_HEAD &&
         git subtree merge --prefix subdir sub3
 '
 
-# 49
 test_expect_success 'add main-sub4' '
         create subdir/main-sub4 &&
         git commit -m "main-sub4"
 '
 
-# 50
 test_expect_success 'split for main-sub4 without --onto' '
         git subtree split --prefix subdir --branch mainsub4
 '
@@ -442,19 +391,16 @@ 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
 test_expect_success 'check that the commit parent is sub3' '
         check_equal ''"$(git log --pretty=format:%P -1 mainsub4)"'' ''"$(git rev-parse sub3)"''
 '
 
-# 52
 test_expect_success 'add main-sub5' '
         mkdir subdir2 &&
         create subdir2/main-sub5 &&
         git commit -m "main-sub5"
 '
 
-# 53
 test_expect_success 'split for main-sub5 without --onto' '
         # also test that we still can split out an entirely new subtree
         # if the parent of the first commit in the tree is not empty,
@@ -487,7 +433,6 @@ joincommits()
 	echo "$commit $all"
 }
 
-# 54
 test_expect_success 'verify one file change per commit' '
         x= &&
         list=''"$(git log --pretty=format:'"'commit: %H'"' | joincommits)"'' &&
-- 
1.8.1

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH/RFC 4/7] contrib/subtree: Code cleaning and refactoring
  2013-01-13  1:52 [PATCH/RFC 0/7] mutiple improvements Techlive Zheng
                   ` (2 preceding siblings ...)
  2013-01-13  1:52 ` [PATCH/RFC 3/7] contrib/subtree: Remove test number comments Techlive Zheng
@ 2013-01-13  1:52 ` Techlive Zheng
  2013-01-14  3:30   ` 郑文辉(Techlive Zheng)
  2013-01-13  1:52 ` [PATCH/RFC 5/7] contrib/subtree: Make each test self-contained Techlive Zheng
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 18+ messages in thread
From: Techlive Zheng @ 2013-01-13  1:52 UTC (permalink / raw
  To: git, gitster; +Cc: apenwarr, greened, Techlive Zheng

Mostly prepare for the later tests refactoring.

Signed-off-by: Techlive Zheng <techlivezheng@gmail.com>
---
 contrib/subtree/git-subtree.sh     |  66 ++++-----
 contrib/subtree/t/t7900-subtree.sh | 283 +++++++++++++++++++------------------
 2 files changed, 179 insertions(+), 170 deletions(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 138e1e0..91e6e87 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -5,7 +5,7 @@
 # Copyright (C) 2009 Avery Pennarun <apenwarr@gmail.com>
 #
 if [ $# -eq 0 ]; then
-    set -- -h
+	set -- -h
 fi
 OPTS_SPEC="\
 git subtree add   --prefix=<prefix> <commit>
@@ -110,9 +110,9 @@ if [ -z "$prefix" ]; then
 fi
 
 case "$command" in
-	add) [ -e "$prefix" ] && 
+	add) [ -e "$prefix" ] &&
 		die "prefix '$prefix' already exists." ;;
-	*)   [ -e "$prefix" ] || 
+	*)   [ -e "$prefix" ] ||
 		die "'$prefix' does not exist; use 'git subtree add'" ;;
 esac
 
@@ -181,8 +181,8 @@ cache_set()
 	oldrev="$1"
 	newrev="$2"
 	if [ "$oldrev" != "latest_old" \
-	     -a "$oldrev" != "latest_new" \
-	     -a -e "$cachedir/$oldrev" ]; then
+		-a "$oldrev" != "latest_new" \
+		-a -e "$cachedir/$oldrev" ]; then
 		die "cache for $oldrev already exists!"
 	fi
 	echo "$newrev" >"$cachedir/$oldrev"
@@ -327,7 +327,7 @@ add_msg()
 	fi
 	cat <<-EOF
 		$commit_message
-		
+
 		git-subtree-dir: $dir
 		git-subtree-mainline: $latest_old
 		git-subtree-split: $latest_new
@@ -355,7 +355,7 @@ rejoin_msg()
 	fi
 	cat <<-EOF
 		$commit_message
-		
+
 		git-subtree-dir: $dir
 		git-subtree-mainline: $latest_old
 		git-subtree-split: $latest_new
@@ -368,7 +368,7 @@ squash_msg()
 	oldsub="$2"
 	newsub="$3"
 	newsub_short=$(git rev-parse --short "$newsub")
-	
+
 	if [ -n "$oldsub" ]; then
 		oldsub_short=$(git rev-parse --short "$oldsub")
 		echo "Squashed '$dir/' changes from $oldsub_short..$newsub_short"
@@ -378,7 +378,7 @@ squash_msg()
 	else
 		echo "Squashed '$dir/' content from commit $newsub_short"
 	fi
-	
+
 	echo
 	echo "git-subtree-dir: $dir"
 	echo "git-subtree-split: $newsub"
@@ -427,7 +427,7 @@ new_squash_commit()
 	newsub="$3"
 	tree=$(toptree_for_commit $newsub) || exit $?
 	if [ -n "$old" ]; then
-		squash_msg "$dir" "$oldsub" "$newsub" | 
+		squash_msg "$dir" "$oldsub" "$newsub" |
 			git commit-tree "$tree" -p "$old" || exit $?
 	else
 		squash_msg "$dir" "" "$newsub" |
@@ -455,7 +455,7 @@ copy_or_skip()
 		else
 			nonidentical="$parent"
 		fi
-		
+
 		# sometimes both old parents map to the same newparent;
 		# eliminate duplicates
 		is_new=1
@@ -470,7 +470,7 @@ copy_or_skip()
 			p="$p -p $parent"
 		fi
 	done
-	
+
 	if [ -n "$identical" ]; then
 		echo $identical
 	else
@@ -495,14 +495,14 @@ cmd_add()
 	fi
 
 	ensure_clean
-	
+
 	if [ $# -eq 1 ]; then
 		"cmd_add_commit" "$@"
 	elif [ $# -eq 2 ]; then
 		"cmd_add_repository" "$@"
 	else
-	    say "error: parameters were '$@'"
-	    die "Provide either a refspec or a repository and refspec."
+		say "error: parameters were '$@'"
+		die "Provide either a refspec or a repository and refspec."
 	fi
 }
 
@@ -522,19 +522,19 @@ cmd_add_commit()
 	revs=$(git rev-parse $default --revs-only "$@") || exit $?
 	set -- $revs
 	rev="$1"
-	
+
 	debug "Adding $dir as '$rev'..."
 	git read-tree --prefix="$dir" $rev || exit $?
 	git checkout -- "$dir" || exit $?
 	tree=$(git write-tree) || exit $?
-	
+
 	headrev=$(git rev-parse HEAD) || exit $?
 	if [ -n "$headrev" -a "$headrev" != "$rev" ]; then
 		headp="-p $headrev"
 	else
 		headp=
 	fi
-	
+
 	if [ -n "$squash" ]; then
 		rev=$(new_squash_commit "" "" "$rev") || exit $?
 		commit=$(add_squashed_msg "$rev" "$dir" |
@@ -544,7 +544,7 @@ cmd_add_commit()
 			 git commit-tree $tree $headp -p "$rev") || exit $?
 	fi
 	git reset "$commit" || exit $?
-	
+
 	say "Added dir '$dir'"
 }
 
@@ -552,7 +552,7 @@ cmd_split()
 {
 	debug "Splitting $dir..."
 	cache_setup || exit $?
-	
+
 	if [ -n "$onto" ]; then
 		debug "Reading history for --onto=$onto..."
 		git rev-list $onto |
@@ -563,13 +563,13 @@ cmd_split()
 			cache_set $rev $rev
 		done
 	fi
-	
+
 	if [ -n "$ignore_joins" ]; then
 		unrevs=
 	else
 		unrevs="$(find_existing_splits "$dir" "$revs")"
 	fi
-	
+
 	# 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)
@@ -591,12 +591,12 @@ cmd_split()
 		debug "  parents: $parents"
 		newparents=$(cache_get $parents)
 		debug "  newparents: $newparents"
-		
+
 		tree=$(subtree_for_commit $rev "$dir")
 		debug "  tree is: $tree"
 
 		check_parents $parents
-		
+
 		# ugly.  is there no better way to tell if this is a subtree
 		# vs. a mainline commit?  Does it matter?
 		if [ -z $tree ]; then
@@ -617,7 +617,7 @@ cmd_split()
 	if [ -z "$latest_new" ]; then
 		die "No new revisions were found"
 	fi
-	
+
 	if [ -n "$rejoin" ]; then
 		debug "Merging split branch into HEAD..."
 		latest_old=$(cache_get latest_old)
@@ -645,13 +645,13 @@ cmd_merge()
 {
 	revs=$(git rev-parse $default --revs-only "$@") || exit $?
 	ensure_clean
-	
+
 	set -- $revs
 	if [ $# -ne 1 ]; then
 		die "You must provide exactly one revision.  Got: '$revs'"
 	fi
 	rev="$1"
-	
+
 	if [ -n "$squash" ]; then
 		first_split="$(find_latest_squash "$dir")"
 		if [ -z "$first_split" ]; then
@@ -697,15 +697,15 @@ cmd_pull()
 cmd_push()
 {
 	if [ $# -ne 2 ]; then
-	    die "You must provide <repository> <refspec>"
+		die "You must provide <repository> <refspec>"
 	fi
 	if [ -e "$dir" ]; then
-	    repository=$1
-	    refspec=$2
-	    echo "git push using: " $repository $refspec
-	    git push $repository $(git subtree split --prefix=$prefix):refs/heads/$refspec
+		repository=$1
+		refspec=$2
+		echo "git push using: " $repository $refspec
+		git push $repository $(git subtree split --prefix=$prefix):refs/heads/$refspec
 	else
-	    die "'$dir' must already exist. Try 'git subtree add'."
+		die "'$dir' must already exist. Try 'git subtree add'."
 	fi
 }
 
diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh
index abdcddb..bb4fd1f 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -4,7 +4,7 @@
 #
 test_description='Basic porcelain support for subtrees
 
-This test verifies the basic operation of the merge, pull, add
+This test verifies the basic operation of the add, pull, merge
 and split subcommands of git subtree.
 '
 
@@ -14,50 +14,73 @@ export TEST_DIRECTORY=$(pwd)/../../../t
 
 create()
 {
-	echo "$1" >"$1"
-	git add "$1"
+    echo "$1" >"$1"
+    git add "$1"
 }
 
+fixnl()
+{
+    t=""
+    while read x; do
+        t="$t$x "
+    done
+    echo $t
+}
 
-check_equal()
+multiline()
 {
-	test_debug 'echo'
-	test_debug "echo \"check a:\" \"{$1}\""
-	test_debug "echo \"      b:\" \"{$2}\""
-	if [ "$1" = "$2" ]; then
-		return 0
-	else
-		return 1
-	fi
+    while read x; do
+        set -- $x
+        for d in "$@"; do
+            echo "$d"
+        done
+    done
 }
 
-fixnl()
+undo()
 {
-	t=""
-	while read x; do
-		t="$t$x "
-	done
-	echo $t
+    git reset --hard HEAD~
 }
 
-multiline()
+test_equal()
 {
-	while read x; do
-		set -- $x
-		for d in "$@"; do
-			echo "$d"
-		done
-	done
+    test_debug 'echo'
+    test_debug "echo \"check a:\" \"{$1}\""
+    test_debug "echo \"      b:\" \"{$2}\""
+    if [ "$1" = "$2" ]; then
+        return 0
+    else
+        return 1
+    fi
 }
 
-undo()
+# Make sure no patch changes more than one file.
+# The original set of commits changed only one file each.
+# A multi-file change would imply that we pruned commits
+# too aggressively.
+join_commits()
 {
-	git reset --hard HEAD~
+    commit=
+    all=
+    while read x y; do
+        if [ -z "$x" ]; then
+            continue
+        elif [ "$x" = "commit:" ]; then
+            if [ -n "$commit" ]; then
+                echo "$commit $all"
+                all=
+            fi
+            commit="$y"
+        else
+            all="$all $y"
+        fi
+    done
+    echo "$commit $all"
 }
 
 last_commit_message()
 {
-	git log --pretty=format:%s -1
+    git log --pretty=format:%s -1
 }
 
 test_expect_success 'init subproj' '
@@ -93,7 +116,7 @@ test_expect_success 'add main4' '
         create main4 &&
         git commit -m "main4" &&
         git branch -m master mainline &&
-        git branch subdir
+        git branch init
 '
 
 test_expect_success 'fetch subproj history' '
@@ -101,40 +124,43 @@ test_expect_success 'fetch subproj history' '
         git branch sub1 FETCH_HEAD
 '
 
-test_expect_success 'no subtree exists in main tree' '
-        test_must_fail git subtree merge --prefix=subdir sub1
-'
-
 test_expect_success 'no pull from non-existant subtree' '
         test_must_fail git subtree pull --prefix=subdir ./subproj sub1
 '
 
-test_expect_success 'check if --message works for add' '
-        git subtree add --prefix=subdir --message="Added subproject" sub1 &&
-        check_equal ''"$(last_commit_message)"'' "Added subproject" &&
+test_expect_success 'no merge from non-existant subtree' '
+        test_must_fail git subtree merge --prefix=subdir FETCH_HEAD
+'
+
+test_expect_success 'add subproj as subtree into subdir/ with --prefix' '
+        git subtree add --prefix=subdir FETCH_HEAD &&
+        test_equal "$(last_commit_message)" "Add '\''subdir/'\'' from commit '\''$(git rev-parse FETCH_HEAD)'\''" &&
         undo
 '
 
-test_expect_success 'check if --message works as -m and --prefix as -P' '
-        git subtree add -P subdir -m "Added subproject using git subtree" sub1 &&
-        check_equal ''"$(last_commit_message)"'' "Added subproject using git subtree" &&
+test_expect_success 'add subproj as subtree into subdir/ with --prefix and --message' '
+        git subtree add --prefix=subdir --message="Added subproject" FETCH_HEAD &&
+        test_equal "$(last_commit_message)" "Added subproject" &&
         undo
 '
 
-test_expect_success 'check if --message works with squash too' '
-        git subtree add -P subdir -m "Added subproject with squash" --squash sub1 &&
-        check_equal ''"$(last_commit_message)"'' "Added subproject with squash" &&
+test_expect_success 'add subproj as subtree into subdir/ with --prefix as -P and --message as -m' '
+        git subtree add -P subdir -m "Added subproject" FETCH_HEAD &&
+        test_equal "$(last_commit_message)" "Added subproject" &&
         undo
 '
 
-test_expect_success 'add subproj to mainline' '
-        git subtree add --prefix=subdir/ FETCH_HEAD &&
-        check_equal ''"$(last_commit_message)"'' "Add '"'subdir/'"' from commit '"'"'''"$(git rev-parse sub1)"'''"'"'"
+test_expect_success 'add subproj as subtree into subdir/ with --squash and --prefix and --message' '
+        git subtree add --prefix=subdir --message="Added subproject with squash" --squash FETCH_HEAD &&
+        test_equal "$(last_commit_message)" "Added subproject with squash" &&
+        undo
 '
 
-# this shouldn't actually do anything, since FETCH_HEAD is already a parent
-test_expect_success 'merge fetched subproj' '
-        git merge -m "merge -s -ours" -s ours FETCH_HEAD
+test_expect_success 'merge the added subproj again, should do nothing' '
+        git subtree add --prefix=subdir FETCH_HEAD &&
+        # this shouldn not actually do anything, since FETCH_HEAD
+        # is already a parent
+        git merge -s ours -m "merge -s -ours" FETCH_HEAD
 '
 
 test_expect_success 'add main-sub5' '
@@ -157,25 +183,30 @@ test_expect_success 'fetch new subproj history' '
         git branch sub2 FETCH_HEAD
 '
 
-test_expect_success 'check if --message works for merge' '
-        git subtree merge --prefix=subdir -m "Merged changes from subproject" sub2 &&
-        check_equal ''"$(last_commit_message)"'' "Merged changes from subproject" &&
+test_expect_success 'merge new subproj history into subdir/ with --prefix' '
+        git subtree merge --prefix=subdir FETCH_HEAD &&
+        test_equal "$(last_commit_message)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\'' into mainline" &&
+        undo
+'
+
+test_expect_success 'merge new subproj history into subdir/ with --prefix and --message' '
+        git subtree merge --prefix=subdir --message="Merged changes from subproject" FETCH_HEAD &&
+        test_equal "$(last_commit_message)" "Merged changes from subproject" &&
         undo
 '
 
-test_expect_success 'check if --message for merge works with squash too' '
-        git subtree merge --prefix subdir -m "Merged changes from subproject using squash" --squash sub2 &&
-        check_equal ''"$(last_commit_message)"'' "Merged changes from subproject using squash" &&
+test_expect_success 'merge new subproj history into subdir/ with --squash and --prefix and --message' '
+        git subtree merge --prefix=subdir --message="Merged changes from subproject using squash" --squash FETCH_HEAD &&
+        test_equal "$(last_commit_message)" "Merged changes from subproject using squash" &&
         undo
 '
 
-test_expect_success 'merge new subproj history into subdir' '
+test_expect_success 'merge new subproj history into subdir/' '
         git subtree merge --prefix=subdir FETCH_HEAD &&
-        git branch pre-split &&
-        check_equal ''"$(last_commit_message)"'' "Merge commit '"'"'"$(git rev-parse sub2)"'"'"' into mainline"
+        git branch pre-split
 '
 
-test_expect_success 'Check that prefix argument is required for split' '
+test_expect_success 'split requires option --prefix' '
         echo "You must provide the --prefix option." > expected &&
         test_must_fail git subtree split > actual 2>&1 &&
         test_debug "echo -n expected: " &&
@@ -186,48 +217,52 @@ test_expect_success 'Check that prefix argument is required for split' '
         rm -f expected actual
 '
 
-test_expect_success 'Check that the <prefix> exists for a split' '
-        echo "'"'"'non-existent-directory'"'"'" does not exist\; use "'"'"'git subtree add'"'"'" > expected &&
+test_expect_success 'split requires path given by option --prefix must exist' '
+        echo "'\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" > expected &&
         test_must_fail git subtree split --prefix=non-existent-directory > actual 2>&1 &&
         test_debug "echo -n expected: " &&
         test_debug "cat expected" &&
         test_debug "echo -n actual: " &&
         test_debug "cat actual" &&
-        test_cmp expected actual
-#        rm -f expected actual
+        test_cmp expected actual &&
+        rm -f expected actual
 '
 
-test_expect_success 'check if --message works for split+rejoin' '
-        spl1=''"$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"'' &&
+test_expect_success 'split subdir/ with --rejoin' '
+        spl1=$(git subtree split --prefix=subdir --annotate="*") &&
         git branch spl1 "$spl1" &&
-        check_equal ''"$(last_commit_message)"'' "Split & rejoin" &&
+        git subtree split --prefix=subdir --annotate="*" --rejoin &&
+        test_equal "$(last_commit_message)" "Split '\''subdir/'\'' into commit '\''$spl1'\''" &&
         undo
 '
 
-test_expect_success 'check split with --branch' '
-        spl1=$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin) &&
+test_expect_success 'split subdir/ with --rejoin and --message' '
+        git subtree split --prefix=subdir --message="Split & rejoin" --annotate="*" --rejoin &&
+        test_equal "$(last_commit_message)" "Split & rejoin" &&
+        undo
+'
+
+test_expect_success 'split subdir/ with --branch' '
+        spl1=$(git subtree split --prefix=subdir --message="Split & rejoin" --annotate="*" --rejoin) &&
         undo &&
-        git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --branch splitbr1 &&
-        check_equal ''"$(git rev-parse splitbr1)"'' "$spl1"
+        git subtree split --prefix=subdir --annotate="*" --branch splitbr1 &&
+        test_equal "$(git rev-parse splitbr1)" "$spl1"
 '
 
-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)"'' &&
+test_expect_success 'split subdir/ with --branch for an existing branch' '
+        spl1=$(git subtree split --prefix=subdir --annotate="*" --message="Split & rejoin" --rejoin) &&
         undo &&
         git branch splitbr2 sub1 &&
-        git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --branch splitbr2 &&
-        check_equal ''"$(git rev-parse splitbr2)"'' "$spl1"
+        git subtree split --prefix=subdir --annotate="*" --branch splitbr2 &&
+        test_equal "$(git rev-parse splitbr2)" "$spl1"
 '
 
-test_expect_success 'check split with --branch for an incompatible branch' '
-        test_must_fail git subtree split --prefix subdir --onto FETCH_HEAD --branch subdir
+test_expect_success 'split subdir/ with --branch for an incompatible branch' '
+        test_must_fail git subtree split --prefix=subdir --branch init
 '
 
-test_expect_success 'check split+rejoin' '
-        spl1=''"$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"'' &&
-        undo &&
-        git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --rejoin &&
-        check_equal ''"$(last_commit_message)"'' "Split '"'"'subdir/'"'"' into commit '"'"'"$spl1"'"'"'"
+test_expect_success 'split and rejoin' '
+        git subtree split --prefix=subdir --annotate="*" --rejoin
 '
 
 test_expect_success 'add main-sub8' '
@@ -253,8 +288,8 @@ test_expect_success 'add sub9' '
 cd ..
 
 test_expect_success 'split for sub8' '
-        split2=''"$(git subtree split --annotate='"'*'"' --prefix subdir/ --rejoin)"''
-        git branch split2 "$split2"
+        spl2=$(git subtree split --prefix=subdir/ --annotate="*" --rejoin) &&
+        git branch spl2 "$spl2"
 '
 
 test_expect_success 'add main-sub10' '
@@ -263,7 +298,7 @@ test_expect_success 'add main-sub10' '
 '
 
 test_expect_success 'split for sub10' '
-        spl3=''"$(git subtree split --annotate='"'*'"' --prefix subdir --rejoin)"'' &&
+        spl3=$(git subtree split --prefix=subdir --annotate="*" --rejoin) &&
         git branch spl3 "$spl3"
 '
 
@@ -284,13 +319,13 @@ chks="sub1 sub2 sub3 sub9"
 chks_sub=$(echo $chks | multiline | sed 's,^,subdir/,' | fixnl)
 
 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"
+        subfiles=$(git ls-files | fixnl) &&
+        test_equal "$subfiles" "$chkms $chks"
 '
 
-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"
+test_expect_success 'make sure the subproj *only* contains commits that affect the subdir' '
+        allchanges=$(git log --name-only --pretty=format:"" | sort | fixnl) &&
+        test_equal "$allchanges" "$chkms $chks"
 '
 
 # Back to mainline
@@ -303,25 +338,25 @@ test_expect_success 'pull from subproj' '
 '
 
 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"
+        mainfiles=$(git ls-files | fixnl) &&
+        test_equal "$mainfiles" "$chkm $chkms_sub $chks_sub"
 '
 
 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
         # change, since they were *only* changed in the subtree branch.
-        allchanges=''"$(git log --name-only --pretty=format:'"''"' | sort | fixnl)"'' &&
-        check_equal "$allchanges" ''"$(echo $chkms $chkm $chks $chkms_sub | multiline | sort | fixnl)"''
+        allchanges=$(git log --name-only --pretty=format:"" | sort | fixnl) &&
+        test_equal "$allchanges" "$(echo $chkms $chkm $chks $chkms_sub | multiline | sort | fixnl)"
 '
 
 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)"'' ""
+        test_equal "$(git log --pretty=format:"%s" HEAD^2 | grep -i split)" ""
 '
 
 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.*:")"'' ""
+        test_equal "$(git log --pretty=format:"%s%n%b" HEAD^2 | grep "git-subtree.*:")" ""
 '
 
 # prepare second pair of repositories
@@ -359,7 +394,7 @@ cd ../main
 test_expect_success 'add sub as subdir in main' '
         git fetch ../sub master &&
         git branch sub2 FETCH_HEAD &&
-        git subtree add --prefix subdir sub2
+        git subtree add --prefix=subdir sub2
 '
 
 cd ../sub
@@ -374,7 +409,7 @@ cd ../main
 test_expect_success 'merge from sub' '
         git fetch ../sub master &&
         git branch sub3 FETCH_HEAD &&
-        git subtree merge --prefix subdir sub3
+        git subtree merge --prefix=subdir sub3
 '
 
 test_expect_success 'add main-sub4' '
@@ -383,7 +418,7 @@ test_expect_success 'add main-sub4' '
 '
 
 test_expect_success 'split for main-sub4 without --onto' '
-        git subtree split --prefix subdir --branch mainsub4
+        git subtree split --prefix=subdir --branch mainsub4
 '
 
 # at this point, the new commit parent should be sub3 if it is not,
@@ -392,7 +427,7 @@ test_expect_success 'split for main-sub4 without --onto' '
 # itself)
 
 test_expect_success 'check that the commit parent is sub3' '
-        check_equal ''"$(git log --pretty=format:%P -1 mainsub4)"'' ''"$(git rev-parse sub3)"''
+        test_equal "$(git log --pretty=format:%P -1 mainsub4)" "$(git rev-parse sub3)"
 '
 
 test_expect_success 'add main-sub5' '
@@ -405,49 +440,23 @@ test_expect_success 'split for main-sub5 without --onto' '
         # also test that we still can split out an entirely new subtree
         # if the parent of the first commit in the tree is not empty,
         # then the new subtree has accidently been attached to something
-        git subtree split --prefix subdir2 --branch mainsub5 &&
-        check_equal ''"$(git log --pretty=format:%P -1 mainsub5)"'' ""
+        git subtree split --prefix=subdir2 --branch mainsub5 &&
+        test_equal "$(git log --pretty=format:%P -1 mainsub5)" ""
 '
 
-# make sure no patch changes more than one file.  The original set of commits
-# changed only one file each.  A multi-file change would imply that we pruned
-# commits too aggressively.
-joincommits()
-{
-	commit=
-	all=
-	while read x y; do
-		#echo "{$x}" >&2
-		if [ -z "$x" ]; then
-			continue
-		elif [ "$x" = "commit:" ]; then
-			if [ -n "$commit" ]; then
-				echo "$commit $all"
-				all=
-			fi
-			commit="$y"
-		else
-			all="$all $y"
-		fi
-	done
-	echo "$commit $all"
-}
-
 test_expect_success 'verify one file change per commit' '
         x= &&
-        list=''"$(git log --pretty=format:'"'commit: %H'"' | joincommits)"'' &&
-#        test_debug "echo HERE" &&
-#        test_debug "echo ''"$list"''" &&
-        (git log --pretty=format:'"'commit: %H'"' | joincommits |
-        (       while read commit a b; do
-		        test_debug "echo Verifying commit "''"$commit"''
-		        test_debug "echo a: "''"$a"''
-		        test_debug "echo b: "''"$b"''
-		        check_equal "$b" ""
-		        x=1
-	        done
-	        check_equal "$x" 1
-        ))
+        git log --pretty=format:"commit: %H" | join_commits |
+        (
+            while read commit a b; do
+                test_debug "echo Verifying commit $commit"
+                test_debug "echo a: $a"
+                test_debug "echo b: $b"
+                test_equal "$b" ""
+                x=1
+            done
+            test_equal "$x" 1
+        )
 '
 
 test_done
-- 
1.8.1

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH/RFC 5/7] contrib/subtree: Make each test self-contained
  2013-01-13  1:52 [PATCH/RFC 0/7] mutiple improvements Techlive Zheng
                   ` (3 preceding siblings ...)
  2013-01-13  1:52 ` [PATCH/RFC 4/7] contrib/subtree: Code cleaning and refactoring Techlive Zheng
@ 2013-01-13  1:52 ` Techlive Zheng
  2013-01-13  1:52 ` [PATCH/RFC 6/7] contrib/subtree: Use %B for the split commit message Techlive Zheng
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 18+ messages in thread
From: Techlive Zheng @ 2013-01-13  1:52 UTC (permalink / raw
  To: git, gitster; +Cc: apenwarr, greened, Techlive Zheng

Signed-off-by: Techlive Zheng <techlivezheng@gmail.com>
---
 contrib/subtree/t/t7900-subtree.sh | 865 ++++++++++++++++++++++++++-----------
 1 file changed, 614 insertions(+), 251 deletions(-)

diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh
index bb4fd1f..ece2064 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -12,12 +12,6 @@ export TEST_DIRECTORY=$(pwd)/../../../t
 
 . ../../../t/test-lib.sh
 
-create()
-{
-    echo "$1" >"$1"
-    git add "$1"
-}
-
 fixnl()
 {
     t=""
@@ -37,11 +31,6 @@ multiline()
     done
 }
 
-undo()
-{
-    git reset --hard HEAD~
-}
-
 test_equal()
 {
     test_debug 'echo'
@@ -78,373 +67,746 @@ join_commits()
     echo "$commit $all"
 }
 
+test_create_commit() (
+    repo=$1
+    commit=$2
+    cd "$repo"
+    mkdir -p "$(dirname "$commit")"
+    echo "$commit" > "$commit"
+    git add "$commit"
+    git commit -m "$commit"
+)
+
 last_commit_message()
 {
     git log --pretty=format:%s -1
 }
 
-test_expect_success 'init subproj' '
-        test_create_repo subproj
-'
-
-# To the subproject!
-cd subproj
-
-test_expect_success 'add sub1' '
-        create sub1 &&
-        git commit -m "sub1" &&
-        git branch sub1 &&
-        git branch -m master subproj
-'
-
-test_expect_success 'add sub2' '
-        create sub2 &&
-        git commit -m "sub2" &&
-        git branch sub2
-'
-
-test_expect_success 'add sub3' '
-        create sub3 &&
-        git commit -m "sub3" &&
-        git branch sub3
-'
-
-# Back to mainline
-cd ..
-
-test_expect_success 'add main4' '
-        create main4 &&
-        git commit -m "main4" &&
-        git branch -m master mainline &&
-        git branch init
-'
-
-test_expect_success 'fetch subproj history' '
-        git fetch ./subproj sub1 &&
-        git branch sub1 FETCH_HEAD
-'
+#
+# Tests for 'git subtree add'
+#
 
 test_expect_success 'no pull from non-existant subtree' '
-        test_must_fail git subtree pull --prefix=subdir ./subproj sub1
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        test_must_fail git subtree pull --prefix=subdir ./subproj master
+    )
 '
 
 test_expect_success 'no merge from non-existant subtree' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
         test_must_fail git subtree merge --prefix=subdir FETCH_HEAD
+    )
 '
 
 test_expect_success 'add subproj as subtree into subdir/ with --prefix' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
         git subtree add --prefix=subdir FETCH_HEAD &&
-        test_equal "$(last_commit_message)" "Add '\''subdir/'\'' from commit '\''$(git rev-parse FETCH_HEAD)'\''" &&
-        undo
+        test_equal "$(last_commit_message)" "Add '\''subdir/'\'' from commit '\''$(git rev-parse FETCH_HEAD)'\''"
+    )
 '
 
 test_expect_success 'add subproj as subtree into subdir/ with --prefix and --message' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
         git subtree add --prefix=subdir --message="Added subproject" FETCH_HEAD &&
-        test_equal "$(last_commit_message)" "Added subproject" &&
-        undo
+        test_equal "$(last_commit_message)" "Added subproject"
+    )
 '
 
 test_expect_success 'add subproj as subtree into subdir/ with --prefix as -P and --message as -m' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
         git subtree add -P subdir -m "Added subproject" FETCH_HEAD &&
-        test_equal "$(last_commit_message)" "Added subproject" &&
-        undo
+        test_equal "$(last_commit_message)" "Added subproject"
+    )
 '
 
 test_expect_success 'add subproj as subtree into subdir/ with --squash and --prefix and --message' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
         git subtree add --prefix=subdir --message="Added subproject with squash" --squash FETCH_HEAD &&
-        test_equal "$(last_commit_message)" "Added subproject with squash" &&
-        undo
+        test_equal "$(last_commit_message)" "Added subproject with squash"
+    )
 '
 
 test_expect_success 'merge the added subproj again, should do nothing' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
         git subtree add --prefix=subdir FETCH_HEAD &&
         # this shouldn not actually do anything, since FETCH_HEAD
         # is already a parent
         git merge -s ours -m "merge -s -ours" FETCH_HEAD
+    )
 '
 
-test_expect_success 'add main-sub5' '
-        create subdir/main-sub5 &&
-        git commit -m "main-sub5"
-'
-
-test_expect_success 'add main6' '
-        create main6 &&
-        git commit -m "main6 boring"
-'
-
-test_expect_success 'add main-sub7' '
-        create subdir/main-sub7 &&
-        git commit -m "main-sub7"
-'
-
-test_expect_success 'fetch new subproj history' '
-        git fetch ./subproj sub2 &&
-        git branch sub2 FETCH_HEAD
-'
+#
+# Tests for 'git subtree merge'
+#
 
 test_expect_success 'merge new subproj history into subdir/ with --prefix' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
         git subtree merge --prefix=subdir FETCH_HEAD &&
-        test_equal "$(last_commit_message)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\'' into mainline" &&
-        undo
+        test_equal "$(last_commit_message)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''"
+    )
 '
 
 test_expect_success 'merge new subproj history into subdir/ with --prefix and --message' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
         git subtree merge --prefix=subdir --message="Merged changes from subproject" FETCH_HEAD &&
-        test_equal "$(last_commit_message)" "Merged changes from subproject" &&
-        undo
+        test_equal "$(last_commit_message)" "Merged changes from subproject"
+    )
 '
 
 test_expect_success 'merge new subproj history into subdir/ with --squash and --prefix and --message' '
+    test_create_repo "$test_count/subproj" &&
+    test_create_repo "$test_count" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
         git subtree merge --prefix=subdir --message="Merged changes from subproject using squash" --squash FETCH_HEAD &&
-        test_equal "$(last_commit_message)" "Merged changes from subproject using squash" &&
-        undo
+        test_equal "$(last_commit_message)" "Merged changes from subproject using squash"
+    )
 '
 
-test_expect_success 'merge new subproj history into subdir/' '
-        git subtree merge --prefix=subdir FETCH_HEAD &&
-        git branch pre-split
-'
+#
+# Tests for 'git subtree split'
+#
 
 test_expect_success 'split requires option --prefix' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir FETCH_HEAD &&
         echo "You must provide the --prefix option." > expected &&
         test_must_fail git subtree split > actual 2>&1 &&
         test_debug "echo -n expected: " &&
         test_debug "cat expected" &&
         test_debug "echo -n actual: " &&
         test_debug "cat actual" &&
-        test_cmp expected actual &&
-        rm -f expected actual
+        test_cmp expected actual
+    )
 '
 
 test_expect_success 'split requires path given by option --prefix must exist' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir FETCH_HEAD &&
         echo "'\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" > expected &&
         test_must_fail git subtree split --prefix=non-existent-directory > actual 2>&1 &&
         test_debug "echo -n expected: " &&
         test_debug "cat expected" &&
         test_debug "echo -n actual: " &&
         test_debug "cat actual" &&
-        test_cmp expected actual &&
-        rm -f expected actual
+        test_cmp expected actual
+    )
 '
 
 test_expect_success 'split subdir/ with --rejoin' '
-        spl1=$(git subtree split --prefix=subdir --annotate="*") &&
-        git branch spl1 "$spl1" &&
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub1 &&
+    test_create_commit "$test_count" main2 &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    test_create_commit "$test_count" subdir/main-sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree merge --prefix=subdir FETCH_HEAD &&
+        split_hash=$(git subtree split --prefix=subdir --annotate="*") &&
         git subtree split --prefix=subdir --annotate="*" --rejoin &&
-        test_equal "$(last_commit_message)" "Split '\''subdir/'\'' into commit '\''$spl1'\''" &&
-        undo
+        test_equal "$(last_commit_message)" "Split '\''subdir/'\'' into commit '\''$split_hash'\''"
+    )
 '
 
 test_expect_success 'split subdir/ with --rejoin and --message' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub1 &&
+    test_create_commit "$test_count" main2 &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    test_create_commit "$test_count" subdir/main-sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree merge --prefix=subdir FETCH_HEAD &&
         git subtree split --prefix=subdir --message="Split & rejoin" --annotate="*" --rejoin &&
-        test_equal "$(last_commit_message)" "Split & rejoin" &&
-        undo
+        test_equal "$(last_commit_message)" "Split & rejoin"
+    )
 '
 
 test_expect_success 'split subdir/ with --branch' '
-        spl1=$(git subtree split --prefix=subdir --message="Split & rejoin" --annotate="*" --rejoin) &&
-        undo &&
-        git subtree split --prefix=subdir --annotate="*" --branch splitbr1 &&
-        test_equal "$(git rev-parse splitbr1)" "$spl1"
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub1 &&
+    test_create_commit "$test_count" main2 &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    test_create_commit "$test_count" subdir/main-sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree merge --prefix=subdir FETCH_HEAD &&
+        split_hash=$(git subtree split --prefix=subdir --annotate="*") &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br &&
+        test_equal "$(git rev-parse subproj-br)" "$split_hash"
+    )
 '
 
 test_expect_success 'split subdir/ with --branch for an existing branch' '
-        spl1=$(git subtree split --prefix=subdir --annotate="*" --message="Split & rejoin" --rejoin) &&
-        undo &&
-        git branch splitbr2 sub1 &&
-        git subtree split --prefix=subdir --annotate="*" --branch splitbr2 &&
-        test_equal "$(git rev-parse splitbr2)" "$spl1"
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git branch subproj-br FETCH_HEAD &&
+        git subtree add --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub1 &&
+    test_create_commit "$test_count" main2 &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    test_create_commit "$test_count" subdir/main-sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree merge --prefix=subdir FETCH_HEAD &&
+        split_hash=$(git subtree split --prefix=subdir --annotate="*") &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br &&
+        test_equal "$(git rev-parse subproj-br)" "$split_hash"
+    )
 '
 
 test_expect_success 'split subdir/ with --branch for an incompatible branch' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git branch init HEAD &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub1 &&
+    test_create_commit "$test_count" main2 &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    test_create_commit "$test_count" subdir/main-sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree merge --prefix=subdir FETCH_HEAD &&
         test_must_fail git subtree split --prefix=subdir --branch init
+    )
 '
 
-test_expect_success 'split and rejoin' '
-        git subtree split --prefix=subdir --annotate="*" --rejoin
-'
-
-test_expect_success 'add main-sub8' '
-        create subdir/main-sub8 &&
-        git commit -m "main-sub8"
-'
-
-# To the subproject!
-cd ./subproj
-
-test_expect_success 'merge split into subproj' '
-        git fetch .. spl1 &&
-        git branch spl1 FETCH_HEAD &&
-        git merge FETCH_HEAD
-'
-
-test_expect_success 'add sub9' '
-        create sub9 &&
-        git commit -m "sub9"
-'
-
-# Back to mainline
-cd ..
-
-test_expect_success 'split for sub8' '
-        spl2=$(git subtree split --prefix=subdir/ --annotate="*" --rejoin) &&
-        git branch spl2 "$spl2"
-'
-
-test_expect_success 'add main-sub10' '
-        create subdir/main-sub10 &&
-        git commit -m "main-sub10"
-'
-
-test_expect_success 'split for sub10' '
-        spl3=$(git subtree split --prefix=subdir --annotate="*" --rejoin) &&
-        git branch spl3 "$spl3"
-'
-
-# To the subproject!
-cd ./subproj
-
-test_expect_success 'merge split into subproj' '
-        git fetch .. spl3 &&
-        git branch spl3 FETCH_HEAD &&
-        git merge FETCH_HEAD &&
-        git branch subproj-merge-spl3
-'
-
-chkm="main4 main6"
-chkms="main-sub10 main-sub5 main-sub7 main-sub8"
-chkms_sub=$(echo $chkms | multiline | sed 's,^,subdir/,' | fixnl)
-chks="sub1 sub2 sub3 sub9"
-chks_sub=$(echo $chks | multiline | sed 's,^,subdir/,' | fixnl)
+#
+# Validity checking
+#
 
 test_expect_success 'make sure exactly the right set of files ends up in the subproj' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub1 &&
+    test_create_commit "$test_count" main2 &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    test_create_commit "$test_count" subdir/main-sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree merge --prefix=subdir FETCH_HEAD &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    test_create_commit "$test_count/subproj" sub3 &&
+    test_create_commit "$test_count" subdir/main-sub3 &&
+    (
+        cd "$test_count/subproj" &&
+        git fetch .. subproj-br && git merge FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count/subproj" sub4 &&
+    (
+        cd "$test_count" &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub4 &&
+    (
+        cd "$test_count" &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    (
+        cd "$test_count/subproj" &&
+        git fetch .. subproj-br && git merge FETCH_HEAD &&
+
+        chks="sub1 sub2 sub3 sub4" &&
+        chks_sub=$(echo $chks | multiline | sed '\''s,^,subdir/,'\'' | fixnl) &&
+        chkms="main-sub1 main-sub2 main-sub3 main-sub4" &&
+        chkms_sub=$(echo $chkms | multiline | sed '\''s,^,subdir/,'\'' | fixnl) &&
+
         subfiles=$(git ls-files | fixnl) &&
         test_equal "$subfiles" "$chkms $chks"
+    )
 '
 
 test_expect_success 'make sure the subproj *only* contains commits that affect the subdir' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub1 &&
+    test_create_commit "$test_count" main2 &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    test_create_commit "$test_count" subdir/main-sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree merge --prefix=subdir FETCH_HEAD &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    test_create_commit "$test_count/subproj" sub3 &&
+    test_create_commit "$test_count" subdir/main-sub3 &&
+    (
+        cd "$test_count/subproj" &&
+        git fetch .. subproj-br && git merge FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count/subproj" sub4 &&
+    (
+        cd "$test_count" &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub4 &&
+    (
+        cd "$test_count" &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    (
+        cd "$test_count/subproj" &&
+        git fetch .. subproj-br && git merge FETCH_HEAD &&
+
+        chks="sub1 sub2 sub3 sub4" &&
+        chks_sub=$(echo $chks | multiline | sed '\''s,^,subdir/,'\'' | fixnl) &&
+        chkms="main-sub1 main-sub2 main-sub3 main-sub4" &&
+        chkms_sub=$(echo $chkms | multiline | sed '\''s,^,subdir/,'\'' | fixnl) &&
+
         allchanges=$(git log --name-only --pretty=format:"" | sort | fixnl) &&
         test_equal "$allchanges" "$chkms $chks"
-'
-
-# Back to mainline
-cd ..
-
-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
+    )
 '
 
 test_expect_success 'make sure exactly the right set of files ends up in the mainline' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub1 &&
+    test_create_commit "$test_count" main2 &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    test_create_commit "$test_count" subdir/main-sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree merge --prefix=subdir FETCH_HEAD &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    test_create_commit "$test_count/subproj" sub3 &&
+    test_create_commit "$test_count" subdir/main-sub3 &&
+    (
+        cd "$test_count/subproj" &&
+        git fetch .. subproj-br && git merge FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count/subproj" sub4 &&
+    (
+        cd "$test_count" &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub4 &&
+    (
+        cd "$test_count" &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    (
+        cd "$test_count/subproj" &&
+        git fetch .. subproj-br && git merge FETCH_HEAD
+    ) &&
+    (
+        cd "$test_count" &&
+        git subtree pull --prefix=subdir ./subproj master &&
+
+        chkm="main1 main2" &&
+        chks="sub1 sub2 sub3 sub4" &&
+        chks_sub=$(echo $chks | multiline | sed '\''s,^,subdir/,'\'' | fixnl) &&
+        chkms="main-sub1 main-sub2 main-sub3 main-sub4" &&
+        chkms_sub=$(echo $chkms | multiline | sed '\''s,^,subdir/,'\'' | fixnl) &&
+
         mainfiles=$(git ls-files | fixnl) &&
         test_equal "$mainfiles" "$chkm $chkms_sub $chks_sub"
+    )
 '
 
 test_expect_success 'make sure each filename changed exactly once in the entire history' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub1 &&
+    test_create_commit "$test_count" main2 &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    test_create_commit "$test_count" subdir/main-sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree merge --prefix=subdir FETCH_HEAD &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    test_create_commit "$test_count/subproj" sub3 &&
+    test_create_commit "$test_count" subdir/main-sub3 &&
+    (
+        cd "$test_count/subproj" &&
+        git fetch .. subproj-br && git merge FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count/subproj" sub4 &&
+    (
+        cd "$test_count" &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub4 &&
+    (
+        cd "$test_count" &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    (
+        cd "$test_count/subproj" &&
+        git fetch .. subproj-br && git merge FETCH_HEAD
+    ) &&
+    (
+        cd "$test_count" &&
+        git subtree pull --prefix=subdir ./subproj master &&
+
+        chkm="main1 main2" &&
+        chks="sub1 sub2 sub3 sub4" &&
+        chks_sub=$(echo $chks | multiline | sed '\''s,^,subdir/,'\'' | fixnl) &&
+        chkms="main-sub1 main-sub2 main-sub3 main-sub4" &&
+        chkms_sub=$(echo $chkms | multiline | sed '\''s,^,subdir/,'\'' | fixnl) &&
+
         # main-sub?? and /subdir/main-sub?? both change, because those are the
         # changes that were split into their own history.  And subdir/sub?? never
         # change, since they were *only* changed in the subtree branch.
         allchanges=$(git log --name-only --pretty=format:"" | sort | fixnl) &&
         test_equal "$allchanges" "$(echo $chkms $chkm $chks $chkms_sub | multiline | sort | fixnl)"
+    )
 '
 
 test_expect_success 'make sure the --rejoin commits never make it into subproj' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub1 &&
+    test_create_commit "$test_count" main2 &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    test_create_commit "$test_count" subdir/main-sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree merge --prefix=subdir FETCH_HEAD &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    test_create_commit "$test_count/subproj" sub3 &&
+    test_create_commit "$test_count" subdir/main-sub3 &&
+    (
+        cd "$test_count/subproj" &&
+        git fetch .. subproj-br && git merge FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count/subproj" sub4 &&
+    (
+        cd "$test_count" &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub4 &&
+    (
+        cd "$test_count" &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    (
+        cd "$test_count/subproj" &&
+        git fetch .. subproj-br && git merge FETCH_HEAD
+    ) &&
+    (
+        cd "$test_count" &&
+        git subtree pull --prefix=subdir ./subproj master &&
+
         test_equal "$(git log --pretty=format:"%s" HEAD^2 | grep -i split)" ""
+    )
 '
 
 test_expect_success 'make sure no "git subtree" tagged commits make it into subproj' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub1 &&
+    test_create_commit "$test_count" main2 &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    test_create_commit "$test_count" subdir/main-sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree merge --prefix=subdir FETCH_HEAD &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    test_create_commit "$test_count/subproj" sub3 &&
+    test_create_commit "$test_count" subdir/main-sub3 &&
+    (
+        cd "$test_count/subproj" &&
+        git fetch .. subproj-br && git merge FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count/subproj" sub4 &&
+    (
+        cd "$test_count" &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub4 &&
+    (
+        cd "$test_count" &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    (
+        cd "$test_count/subproj" &&
+        git fetch .. subproj-br && git merge FETCH_HEAD
+    ) &&
+    (
+        cd "$test_count" &&
+        git subtree pull --prefix=subdir ./subproj master &&
+
         # They are meaningless to subproj since one side of the merge refers to the mainline
         test_equal "$(git log --pretty=format:"%s%n%b" HEAD^2 | grep "git-subtree.*:")" ""
+    )
 '
 
-# prepare second pair of repositories
-mkdir test2
-cd test2
-
-test_expect_success 'init main' '
-        test_create_repo main
-'
-
-cd main
-
-test_expect_success 'add main1' '
-        create main1 &&
-        git commit -m "main1"
-'
-
-cd ..
-
-test_expect_success 'init sub' '
-        test_create_repo sub
-'
-
-cd sub
-
-test_expect_success 'add sub2' '
-        create sub2 &&
-        git commit -m "sub2"
-'
-
-cd ../main
-
-# check if split can find proper base without --onto
-
-test_expect_success 'add sub as subdir in main' '
-        git fetch ../sub master &&
-        git branch sub2 FETCH_HEAD &&
-        git subtree add --prefix=subdir sub2
-'
-
-cd ../sub
-
-test_expect_success 'add sub3' '
-        create sub3 &&
-        git commit -m "sub3"
-'
-
-cd ../main
-
-test_expect_success 'merge from sub' '
-        git fetch ../sub master &&
-        git branch sub3 FETCH_HEAD &&
-        git subtree merge --prefix=subdir sub3
-'
-
-test_expect_success 'add main-sub4' '
-        create subdir/main-sub4 &&
-        git commit -m "main-sub4"
-'
-
-test_expect_success 'split for main-sub4 without --onto' '
-        git subtree split --prefix=subdir --branch mainsub4
-'
-
-# at this point, the new commit parent should be sub3 if it is not,
-# something went wrong (the "newparent" of "master~" commit should
-# have been sub3, but it was not, because its cache was not set to
-# itself)
-
-test_expect_success 'check that the commit parent is sub3' '
-        test_equal "$(git log --pretty=format:%P -1 mainsub4)" "$(git rev-parse sub3)"
-'
+#
+# A new set of tests
+#
 
-test_expect_success 'add main-sub5' '
-        mkdir subdir2 &&
-        create subdir2/main-sub5 &&
-        git commit -m "main-sub5"
-'
+test_expect_success 'make sure "git subtree split" find the correct parent' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git branch subproj-ref FETCH_HEAD &&
+        git subtree merge --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub1 &&
+    (
+        cd "$test_count" &&
+        git subtree split --prefix=subdir --branch subproj-br &&
+
+        # at this point, the new commit parent should be subproj-ref, if it is
+        # not, something went wrong (the "newparent" of "master~" commit should
+        # have been sub2, but it was not, because its cache was not set to
+        # itself)
+        test_equal "$(git log --pretty=format:%P -1 subproj-br)" "$(git rev-parse subproj-ref)"
+    )
+'
+
+test_expect_success 'split a new subtree without --onto option' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree merge --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub1 &&
+    (
+        cd "$test_count" &&
+        git subtree split --prefix=subdir --branch subproj-br
+    ) &&
+    test_create_commit "$test_count" subdir2/main-sub2 &&
+    (
+        cd "$test_count" &&
 
-test_expect_success 'split for main-sub5 without --onto' '
         # also test that we still can split out an entirely new subtree
         # if the parent of the first commit in the tree is not empty,
         # then the new subtree has accidently been attached to something
-        git subtree split --prefix=subdir2 --branch mainsub5 &&
-        test_equal "$(git log --pretty=format:%P -1 mainsub5)" ""
+        git subtree split --prefix=subdir2 --branch subproj2-br &&
+        test_equal "$(git log --pretty=format:%P -1 subproj2-br)" ""
+    )
 '
 
 test_expect_success 'verify one file change per commit' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git branch sub1 FETCH_HEAD &&
+        git subtree add --prefix=subdir sub1
+    ) &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree merge --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub1 &&
+    (
+        cd "$test_count" &&
+        git subtree split --prefix=subdir --branch subproj-br
+    ) &&
+    test_create_commit "$test_count" subdir2/main-sub2 &&
+    (
+        cd "$test_count" &&
+        git subtree split --prefix=subdir2 --branch subproj2-br &&
+
         x= &&
         git log --pretty=format:"commit: %H" | join_commits |
         (
@@ -457,6 +819,7 @@ test_expect_success 'verify one file change per commit' '
             done
             test_equal "$x" 1
         )
+    )
 '
 
 test_done
-- 
1.8.1

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH/RFC 6/7] contrib/subtree: Use %B for the split commit message
  2013-01-13  1:52 [PATCH/RFC 0/7] mutiple improvements Techlive Zheng
                   ` (4 preceding siblings ...)
  2013-01-13  1:52 ` [PATCH/RFC 5/7] contrib/subtree: Make each test self-contained Techlive Zheng
@ 2013-01-13  1:52 ` Techlive Zheng
  2013-01-13  1:52 ` [PATCH/RFC 7/7] contrib/subtree: Handle '--prefix' argument with a slash appended Techlive Zheng
  2013-01-14  3:52 ` [PATCH/RFC v2 0/8] contrib/subtree: Reroll to follow Git's whitespace policy Techlive Zheng
  7 siblings, 0 replies; 18+ messages in thread
From: Techlive Zheng @ 2013-01-13  1:52 UTC (permalink / raw
  To: git, gitster; +Cc: apenwarr, greened, Techlive Zheng

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.

After this commit, the newly split branch might differ from the previous
one. If this is the case, --fallback option could help.

Signed-off-by: Techlive Zheng <techlivezheng@gmail.com>
Signed-off-by: David A. Greene <greened@obbligato.org>
---
 contrib/subtree/git-subtree.sh     | 13 ++++++++++-
 contrib/subtree/git-subtree.txt    | 13 +++++++++++
 contrib/subtree/t/t7900-subtree.sh | 47 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 72 insertions(+), 1 deletion(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 91e6e87..018ee32 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -25,6 +25,7 @@ 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
+fallback      fallback to the obsolete commit generating mechanism
  options for 'add', 'merge', 'pull' and 'push'
 squash        merge subtree changes as a single commit
 "
@@ -45,6 +46,7 @@ ignore_joins=
 annotate=
 squash=
 message=
+fallback=
 
 debug()
 {
@@ -92,6 +94,8 @@ while [ $# -gt 0 ]; do
 		--no-ignore-joins) ignore_joins= ;;
 		--squash) squash=1 ;;
 		--no-squash) squash= ;;
+		--fallback) fallback=1 ;;
+		--no-fallback) fallback= ;;
 		--) break ;;
 		*) die "Unexpected option: $opt" ;;
 	esac
@@ -296,7 +300,14 @@ 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}"
-	git log -1 --pretty=format:'%an%n%ae%n%ad%n%cn%n%ce%n%cd%n%s%n%n%b' "$1" |
+
+	if [ -z "$fallback" ]; then
+		log_format='%an%n%ae%n%ad%n%cn%n%ce%n%cd%n%B'
+	else
+		log_format='%an%n%ae%n%ad%n%cn%n%ce%n%cd%n%s%n%n%b'
+	fi
+
+	git log -1 --pretty=format:"$log_format" "$1" |
 	(
 		read GIT_AUTHOR_NAME
 		read GIT_AUTHOR_EMAIL
diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt
index c5bce41..ca9f199 100644
--- a/contrib/subtree/git-subtree.txt
+++ b/contrib/subtree/git-subtree.txt
@@ -254,6 +254,19 @@ OPTIONS FOR split
 	'--rejoin' when you split, because you don't want the
 	subproject's history to be part of your project anyway.
 
+--fallback::
+	Previously, git subtree would introduce an extra new line for
+	the commits whose commit message contains only one line.
+	This behavior has been correct. Unfortunately, for those whose
+	current split branch contains these kind of commits, git subtree
+	will generate a new split branch which differs from the existing
+	split branch in these commits. It is better to use this new
+	split branch, because its commits stay intact within the mainline.
+	
+	Otherwise, the previous fault behavior could still be used with
+	this option. This option is only for a compatible purpose, newly
+	split branch should never use this option.
+
 
 EXAMPLE 1. Add command
 ----------------------
diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh
index ece2064..1492303 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -399,6 +399,53 @@ test_expect_success 'split subdir/ with --branch for an incompatible branch' '
     )
 '
 
+test_expect_success 'make sure commits with one line message stay intact after split' '
+    test_create_repo $test_count &&
+    test_create_repo $test_count/subproj &&
+    test_create_commit $test_count main1 &&
+    test_create_commit $test_count/subproj sub1 &&
+    (
+        cd $test_count &&
+        git fetch ./subproj master &&
+        ori_hash=$(git rev-parse FETCH_HEAD) &&
+        git branch subori FETCH_HEAD &&
+        git filter-branch --index-filter '\''git ls-files -s | sed "s-\t-&subdir/-" | GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info && mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"'\'' subori
+        git merge -m "Merge B project as our subdirectory" subori &&
+        git subtree split --prefix subdir --branch splitbr1 &&
+        new_hash_1=$(git rev-parse splitbr1) &&
+        test_equal "$ori_hash" "$new_hash_1" &&
+        git subtree split --prefix subdir --branch splitbr2 --fallback &&
+        new_hash_2=$(git rev-parse splitbr2) &&
+        test_must_fail test_equal "$ori_hash" "$new_hash_2"
+    )
+'
+
+test_expect_success 'make sure --fallback option works correctly for the existing split branch' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count"/subproj &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count"/subproj sub1 &&
+    (
+        cd $test_count &&
+        git fetch ./subproj master &&
+        ori_hash=$(git rev-parse FETCH_HEAD) &&
+        git subtree add --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub1 &&
+    (
+        cd $test_count &&
+        git subtree split --prefix subdir --branch splitbr1 &&
+        git subtree split --prefix subdir --branch splitbr2 --fallback &&
+        test_must_fail test_equal "$(git rev-parse splitbr1)" "$(git rev-parse splitbr2)"
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub2 &&
+    (
+        cd $test_count &&
+        test_must_fail git subtree split --prefix subdir --branch splitbr2 &&
+        git subtree split --prefix subdir --branch splitbr2 --fallback
+    )
+'
+
 #
 # Validity checking
 #
-- 
1.8.1

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH/RFC 7/7] contrib/subtree: Handle '--prefix' argument with a slash appended
  2013-01-13  1:52 [PATCH/RFC 0/7] mutiple improvements Techlive Zheng
                   ` (5 preceding siblings ...)
  2013-01-13  1:52 ` [PATCH/RFC 6/7] contrib/subtree: Use %B for the split commit message Techlive Zheng
@ 2013-01-13  1:52 ` Techlive Zheng
  2013-01-14  3:52 ` [PATCH/RFC v2 0/8] contrib/subtree: Reroll to follow Git's whitespace policy Techlive Zheng
  7 siblings, 0 replies; 18+ messages in thread
From: Techlive Zheng @ 2013-01-13  1:52 UTC (permalink / raw
  To: git, gitster; +Cc: apenwarr, greened, Techlive Zheng

'git subtree merge' will fail if the argument of '--prefix' has a slash
appended.

Signed-off-by: Techlive Zheng <techlivezheng@gmail.com>
---
 contrib/subtree/git-subtree.sh     |  2 +-
 contrib/subtree/t/t7900-subtree.sh | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 018ee32..574ff04 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -83,7 +83,7 @@ while [ $# -gt 0 ]; do
 		--annotate) annotate="$1"; shift ;;
 		--no-annotate) annotate= ;;
 		-b) branch="$1"; shift ;;
-		-P) prefix="$1"; shift ;;
+		-P) prefix="${1%/}"; shift ;;
 		-m) message="$1"; shift ;;
 		--no-prefix) prefix= ;;
 		--onto) onto="$1"; shift ;;
diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh
index 1492303..8e09606 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -238,6 +238,25 @@ test_expect_success 'merge new subproj history into subdir/ with --squash and --
     )
 '
 
+test_expect_success 'merge new subproj history into subdir/ with a slash appended to the argument of --prefix' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir/ FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree merge --prefix=subdir/ FETCH_HEAD &&
+        test_equal "$(last_commit_message)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''"
+    )
+'
+
 #
 # Tests for 'git subtree split'
 #
-- 
1.8.1

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH/RFC 4/7] contrib/subtree: Code cleaning and refactoring
  2013-01-13  1:52 ` [PATCH/RFC 4/7] contrib/subtree: Code cleaning and refactoring Techlive Zheng
@ 2013-01-14  3:30   ` 郑文辉(Techlive Zheng)
  0 siblings, 0 replies; 18+ messages in thread
From: 郑文辉(Techlive Zheng) @ 2013-01-14  3:30 UTC (permalink / raw
  To: git; +Cc: apenwarr, greened, Techlive Zheng

2013/1/13 Techlive Zheng <techlivezheng@gmail.com>:
> Mostly prepare for the later tests refactoring.
>
> Signed-off-by: Techlive Zheng <techlivezheng@gmail.com>

I am personally a SP-indenting guy, I did not aware of Git's indenting
policy until now, so it is bad that I replaced all the lines initially
indent using HT with SP in the test file of this commit. I will submit
another set of patches with the right indenting.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH/RFC v2 0/8] contrib/subtree: Reroll to follow Git's whitespace policy
  2013-01-13  1:52 [PATCH/RFC 0/7] mutiple improvements Techlive Zheng
                   ` (6 preceding siblings ...)
  2013-01-13  1:52 ` [PATCH/RFC 7/7] contrib/subtree: Handle '--prefix' argument with a slash appended Techlive Zheng
@ 2013-01-14  3:52 ` Techlive Zheng
  2013-01-14  3:52   ` [PATCH/RFC v2 1/8] contrib/subtree: Fix whitespaces Techlive Zheng
                     ` (7 more replies)
  7 siblings, 8 replies; 18+ messages in thread
From: Techlive Zheng @ 2013-01-14  3:52 UTC (permalink / raw
  To: git; +Cc: apenwarr, greened, Techlive Zheng

David A. Greene (1):
  contrib/subtree: Remove test number comments

Techlive Zheng (7):
  contrib/subtree: Fix whitespaces
  contrib/subtree: Add vim modeline
  contrib/subtree: Ignore testing directory
  contrib/subtree: Code cleaning and refactoring
  contrib/subtree: Make each test self-contained
  contrib/subtree: Use %B for the split commit message
  contrib/subtree: Handle '--prefix' argument with a slash appended

 contrib/subtree/.gitignore         |    5 +-
 contrib/subtree/git-subtree.sh     |   85 +--
 contrib/subtree/git-subtree.txt    |   55 +-
 contrib/subtree/t/t7900-subtree.sh | 1255 +++++++++++++++++++++++-------------
 4 files changed, 905 insertions(+), 495 deletions(-)

-- 
1.8.1

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH/RFC v2 1/8] contrib/subtree: Fix whitespaces
  2013-01-14  3:52 ` [PATCH/RFC v2 0/8] contrib/subtree: Reroll to follow Git's whitespace policy Techlive Zheng
@ 2013-01-14  3:52   ` Techlive Zheng
  2013-01-14  3:52   ` [PATCH/RFC v2 2/8] contrib/subtree: Add vim modeline Techlive Zheng
                     ` (6 subsequent siblings)
  7 siblings, 0 replies; 18+ messages in thread
From: Techlive Zheng @ 2013-01-14  3:52 UTC (permalink / raw
  To: git; +Cc: apenwarr, greened, Techlive Zheng

Previous code does not fulfill Git's whitespace policy.

Signed-off-by: Techlive Zheng <techlivezheng@gmail.com>
---
 contrib/subtree/git-subtree.sh     |  68 ++++----
 contrib/subtree/git-subtree.txt    |  42 ++---
 contrib/subtree/t/t7900-subtree.sh | 314 ++++++++++++++++++-------------------
 3 files changed, 212 insertions(+), 212 deletions(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 920c664..70f86ea 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -5,7 +5,7 @@
 # Copyright (C) 2009 Avery Pennarun <apenwarr@gmail.com>
 #
 if [ $# -eq 0 ]; then
-    set -- -h
+	set -- -h
 fi
 OPTS_SPEC="\
 git subtree add   --prefix=<prefix> <commit>
@@ -110,9 +110,9 @@ if [ -z "$prefix" ]; then
 fi
 
 case "$command" in
-	add) [ -e "$prefix" ] && 
+	add) [ -e "$prefix" ] &&
 		die "prefix '$prefix' already exists." ;;
-	*)   [ -e "$prefix" ] || 
+	*)   [ -e "$prefix" ] ||
 		die "'$prefix' does not exist; use 'git subtree add'" ;;
 esac
 
@@ -181,8 +181,8 @@ cache_set()
 	oldrev="$1"
 	newrev="$2"
 	if [ "$oldrev" != "latest_old" \
-	     -a "$oldrev" != "latest_new" \
-	     -a -e "$cachedir/$oldrev" ]; then
+		-a "$oldrev" != "latest_new" \
+		-a -e "$cachedir/$oldrev" ]; then
 		die "cache for $oldrev already exists!"
 	fi
 	echo "$newrev" >"$cachedir/$oldrev"
@@ -304,7 +304,7 @@ copy_commit()
 		read GIT_COMMITTER_NAME
 		read GIT_COMMITTER_EMAIL
 		read GIT_COMMITTER_DATE
-		export  GIT_AUTHOR_NAME \
+		export GIT_AUTHOR_NAME \
 			GIT_AUTHOR_EMAIL \
 			GIT_AUTHOR_DATE \
 			GIT_COMMITTER_NAME \
@@ -327,7 +327,7 @@ add_msg()
 	fi
 	cat <<-EOF
 		$commit_message
-		
+
 		git-subtree-dir: $dir
 		git-subtree-mainline: $latest_old
 		git-subtree-split: $latest_new
@@ -355,7 +355,7 @@ rejoin_msg()
 	fi
 	cat <<-EOF
 		$commit_message
-		
+
 		git-subtree-dir: $dir
 		git-subtree-mainline: $latest_old
 		git-subtree-split: $latest_new
@@ -368,7 +368,7 @@ squash_msg()
 	oldsub="$2"
 	newsub="$3"
 	newsub_short=$(git rev-parse --short "$newsub")
-	
+
 	if [ -n "$oldsub" ]; then
 		oldsub_short=$(git rev-parse --short "$oldsub")
 		echo "Squashed '$dir/' changes from $oldsub_short..$newsub_short"
@@ -378,7 +378,7 @@ squash_msg()
 	else
 		echo "Squashed '$dir/' content from commit $newsub_short"
 	fi
-	
+
 	echo
 	echo "git-subtree-dir: $dir"
 	echo "git-subtree-split: $newsub"
@@ -427,7 +427,7 @@ new_squash_commit()
 	newsub="$3"
 	tree=$(toptree_for_commit $newsub) || exit $?
 	if [ -n "$old" ]; then
-		squash_msg "$dir" "$oldsub" "$newsub" | 
+		squash_msg "$dir" "$oldsub" "$newsub" |
 			git commit-tree "$tree" -p "$old" || exit $?
 	else
 		squash_msg "$dir" "" "$newsub" |
@@ -455,7 +455,7 @@ copy_or_skip()
 		else
 			nonidentical="$parent"
 		fi
-		
+
 		# sometimes both old parents map to the same newparent;
 		# eliminate duplicates
 		is_new=1
@@ -470,7 +470,7 @@ copy_or_skip()
 			p="$p -p $parent"
 		fi
 	done
-	
+
 	if [ -n "$identical" ]; then
 		echo $identical
 	else
@@ -495,14 +495,14 @@ cmd_add()
 	fi
 
 	ensure_clean
-	
+
 	if [ $# -eq 1 ]; then
 		"cmd_add_commit" "$@"
 	elif [ $# -eq 2 ]; then
 		"cmd_add_repository" "$@"
 	else
-	    say "error: parameters were '$@'"
-	    die "Provide either a refspec or a repository and refspec."
+		say "error: parameters were '$@'"
+		die "Provide either a refspec or a repository and refspec."
 	fi
 }
 
@@ -522,19 +522,19 @@ cmd_add_commit()
 	revs=$(git rev-parse $default --revs-only "$@") || exit $?
 	set -- $revs
 	rev="$1"
-	
+
 	debug "Adding $dir as '$rev'..."
 	git read-tree --prefix="$dir" $rev || exit $?
 	git checkout -- "$dir" || exit $?
 	tree=$(git write-tree) || exit $?
-	
+
 	headrev=$(git rev-parse HEAD) || exit $?
 	if [ -n "$headrev" -a "$headrev" != "$rev" ]; then
 		headp="-p $headrev"
 	else
 		headp=
 	fi
-	
+
 	if [ -n "$squash" ]; then
 		rev=$(new_squash_commit "" "" "$rev") || exit $?
 		commit=$(add_squashed_msg "$rev" "$dir" |
@@ -544,7 +544,7 @@ cmd_add_commit()
 			 git commit-tree $tree $headp -p "$rev") || exit $?
 	fi
 	git reset "$commit" || exit $?
-	
+
 	say "Added dir '$dir'"
 }
 
@@ -552,7 +552,7 @@ cmd_split()
 {
 	debug "Splitting $dir..."
 	cache_setup || exit $?
-	
+
 	if [ -n "$onto" ]; then
 		debug "Reading history for --onto=$onto..."
 		git rev-list $onto |
@@ -563,13 +563,13 @@ cmd_split()
 			cache_set $rev $rev
 		done
 	fi
-	
+
 	if [ -n "$ignore_joins" ]; then
 		unrevs=
 	else
 		unrevs="$(find_existing_splits "$dir" "$revs")"
 	fi
-	
+
 	# 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)
@@ -591,12 +591,12 @@ cmd_split()
 		debug "  parents: $parents"
 		newparents=$(cache_get $parents)
 		debug "  newparents: $newparents"
-		
+
 		tree=$(subtree_for_commit $rev "$dir")
 		debug "  tree is: $tree"
 
 		check_parents $parents
-		
+
 		# ugly.  is there no better way to tell if this is a subtree
 		# vs. a mainline commit?  Does it matter?
 		if [ -z $tree ]; then
@@ -617,7 +617,7 @@ cmd_split()
 	if [ -z "$latest_new" ]; then
 		die "No new revisions were found"
 	fi
-	
+
 	if [ -n "$rejoin" ]; then
 		debug "Merging split branch into HEAD..."
 		latest_old=$(cache_get latest_old)
@@ -645,13 +645,13 @@ cmd_merge()
 {
 	revs=$(git rev-parse $default --revs-only "$@") || exit $?
 	ensure_clean
-	
+
 	set -- $revs
 	if [ $# -ne 1 ]; then
 		die "You must provide exactly one revision.  Got: '$revs'"
 	fi
 	rev="$1"
-	
+
 	if [ -n "$squash" ]; then
 		first_split="$(find_latest_squash "$dir")"
 		if [ -z "$first_split" ]; then
@@ -697,15 +697,15 @@ cmd_pull()
 cmd_push()
 {
 	if [ $# -ne 2 ]; then
-	    die "You must provide <repository> <refspec>"
+		die "You must provide <repository> <refspec>"
 	fi
 	if [ -e "$dir" ]; then
-	    repository=$1
-	    refspec=$2
-	    echo "git push using: " $repository $refspec
-	    git push $repository $(git subtree split --prefix=$prefix):refs/heads/$refspec
+		repository=$1
+		refspec=$2
+		echo "git push using: " $repository $refspec
+		git push $repository $(git subtree split --prefix=$prefix):refs/heads/$refspec
 	else
-	    die "'$dir' must already exist. Try 'git subtree add'."
+		die "'$dir' must already exist. Try 'git subtree add'."
 	fi
 }
 
diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt
index c5bce41..72be8e4 100644
--- a/contrib/subtree/git-subtree.txt
+++ b/contrib/subtree/git-subtree.txt
@@ -86,15 +86,15 @@ merge::
 	go back in time from v2.5 to v2.4, for example.  If your
 	merge introduces a conflict, you can resolve it in the
 	usual ways.
-	
+
 pull::
 	Exactly like 'merge', but parallels 'git pull' in that
 	it fetches the given commit from the specified remote
 	repository.
-	
+
 push::
 	Does a 'split' (see below) using the <prefix> supplied
-	and then does a 'git push' to push the result to the 
+	and then does a 'git push' to push the result to the
 	repository and refspec. This can be used to push your
 	subtree to different branches of the remote repository.
 
@@ -106,19 +106,19 @@ split::
 	contents of <prefix> at the root of the project instead
 	of in a subdirectory.  Thus, the newly created history
 	is suitable for export as a separate git repository.
-	
+
 	After splitting successfully, a single commit id is
 	printed to stdout.  This corresponds to the HEAD of the
 	newly created tree, which you can manipulate however you
 	want.
-	
+
 	Repeated splits of exactly the same history are
 	guaranteed to be identical (ie. to produce the same
 	commit ids).  Because of this, if you add new commits
 	and then re-split, the new commits will be attached as
 	commits on top of the history you generated last time,
 	so 'git merge' and friends will work as expected.
-	
+
 	Note that if you use '--squash' when you merge, you
 	should usually not just '--rejoin' when you split.
 
@@ -155,26 +155,26 @@ OPTIONS FOR add, merge, push, pull
 	project, produce only a single commit that contains all
 	the differences you want to merge, and then merge that
 	new commit into your project.
-	
+
 	Using this option helps to reduce log clutter. People
 	rarely want to see every change that happened between
 	v1.0 and v1.1 of the library they're using, since none of the
 	interim versions were ever included in their application.
-	
+
 	Using '--squash' also helps avoid problems when the same
 	subproject is included multiple times in the same
 	project, or is removed and then re-added.  In such a
 	case, it doesn't make sense to combine the histories
 	anyway, since it's unclear which part of the history
 	belongs to which subtree.
-	
+
 	Furthermore, with '--squash', you can switch back and
 	forth between different versions of a subtree, rather
 	than strictly forward.  'git subtree merge --squash'
 	always adjusts the subtree to match the exactly
 	specified commit, even if getting to that commit would
 	require undoing some changes that were added earlier.
-	
+
 	Whether or not you use '--squash', changes made in your
 	local repository remain intact and can be later split
 	and send upstream to the subproject.
@@ -190,11 +190,11 @@ OPTIONS FOR split
 	commits with the same commit message, but possibly
 	different content, from the original commits, this can help
 	to differentiate them and avoid confusion.
-	
+
 	Whenever you split, you need to use the same
 	<annotation>, or else you don't have a guarantee that
 	the new re-created history will be identical to the old
-	one.  That will prevent merging from working correctly. 
+	one.  That will prevent merging from working correctly.
 	git subtree tries to make it work anyway, particularly
 	if you use --rejoin, but it may not always be effective.
 
@@ -203,8 +203,8 @@ OPTIONS FOR split
 	This option is only valid for the split command.
 
 	After generating the synthetic history, create a new
-	branch called <branch> that contains the new history. 
-	This is suitable for immediate pushing upstream. 
+	branch called <branch> that contains the new history.
+	This is suitable for immediate pushing upstream.
 	<branch> must not already exist.
 
 --ignore-joins::
@@ -227,7 +227,7 @@ OPTIONS FOR split
 	revision of the subproject's history that was imported
 	into your project, and git subtree will attempt to build
 	its history from there.
-	
+
 	If you used 'git subtree add', you should never need
 	this option.
 
@@ -238,18 +238,18 @@ OPTIONS FOR split
 	history back into your main project.  That way, future
 	splits can search only the part of history that has
 	been added since the most recent --rejoin.
-	
+
 	If your split commits end up merged into the upstream
 	subproject, and then you want to get the latest upstream
 	version, this will allow git's merge algorithm to more
 	intelligently avoid conflicts (since it knows these
 	synthetic commits are already part of the upstream
 	repository).
-	
+
 	Unfortunately, using this option results in 'git log'
 	showing an extra copy of every new commit that was
 	created (the original, and the synthetic one).
-	
+
 	If you do all your merges with '--squash', don't use
 	'--rejoin' when you split, because you don't want the
 	subproject's history to be part of your project anyway.
@@ -284,7 +284,7 @@ First, get your own copy of the git.git repository:
 	$ cd test-git
 
 gitweb (commit 1130ef3) was merged into git as of commit
-0a8f4f0, after which it was no longer maintained separately. 
+0a8f4f0, after which it was no longer maintained separately.
 But imagine it had been maintained separately, and we wanted to
 extract git's changes to gitweb since that time, to share with
 the upstream.  You could do this:
@@ -294,7 +294,7 @@ the upstream.  You could do this:
         	--branch gitweb-latest
         $ gitk gitweb-latest
         $ git push git@github.com:whatever/gitweb.git gitweb-latest:master
-        
+
 (We use '0a8f4f0^..' because that means "all the changes from
 0a8f4f0 to the current version, including 0a8f4f0 itself.")
 
@@ -328,7 +328,7 @@ And fast forward again:
 	$ git subtree merge --prefix=gitweb --squash gitweb-latest
 
 And notice that your change is still intact:
-	
+
 	$ ls -l gitweb/myfile
 
 And you can split it out and look at your changes versus
diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh
index bc2eeb0..b98f7d0 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -23,7 +23,7 @@ check_equal()
 {
 	test_debug 'echo'
 	test_debug "echo \"check a:\" \"{$1}\""
-	test_debug "echo \"      b:\" \"{$2}\""
+	test_debug "echo \"		 b:\" \"{$2}\""
 	if [ "$1" = "$2" ]; then
 		return 0
 	else
@@ -62,7 +62,7 @@ last_commit_message()
 
 # 1
 test_expect_success 'init subproj' '
-        test_create_repo subproj
+		test_create_repo subproj
 '
 
 # To the subproject!
@@ -70,24 +70,24 @@ cd subproj
 
 # 2
 test_expect_success 'add sub1' '
-        create sub1 &&
-        git commit -m "sub1" &&
-        git branch sub1 &&
-        git branch -m master subproj
+		create sub1 &&
+		git commit -m "sub1" &&
+		git branch sub1 &&
+		git branch -m master subproj
 '
 
 # 3
 test_expect_success 'add sub2' '
-        create sub2 &&
-        git commit -m "sub2" &&
-        git branch sub2
+		create sub2 &&
+		git commit -m "sub2" &&
+		git branch sub2
 '
 
 # 4
 test_expect_success 'add sub3' '
-        create sub3 &&
-        git commit -m "sub3" &&
-        git branch sub3
+		create sub3 &&
+		git commit -m "sub3" &&
+		git branch sub3
 '
 
 # Back to mainline
@@ -95,173 +95,173 @@ cd ..
 
 # 5
 test_expect_success 'add main4' '
-        create main4 &&
-        git commit -m "main4" &&
-        git branch -m master mainline &&
-        git branch subdir
+		create main4 &&
+		git commit -m "main4" &&
+		git branch -m master mainline &&
+		git branch subdir
 '
 
 # 6
 test_expect_success 'fetch subproj history' '
-        git fetch ./subproj sub1 &&
-        git branch sub1 FETCH_HEAD
+		git fetch ./subproj sub1 &&
+		git branch sub1 FETCH_HEAD
 '
 
 # 7
 test_expect_success 'no subtree exists in main tree' '
-        test_must_fail git subtree merge --prefix=subdir sub1
+		test_must_fail git subtree merge --prefix=subdir sub1
 '
 
 # 8
 test_expect_success 'no pull from non-existant subtree' '
-        test_must_fail git subtree pull --prefix=subdir ./subproj sub1
+		test_must_fail git subtree pull --prefix=subdir ./subproj sub1
 '
 
 # 9
 test_expect_success 'check if --message works for add' '
-        git subtree add --prefix=subdir --message="Added subproject" sub1 &&
-        check_equal ''"$(last_commit_message)"'' "Added subproject" &&
-        undo
+		git subtree add --prefix=subdir --message="Added subproject" sub1 &&
+		check_equal ''"$(last_commit_message)"'' "Added subproject" &&
+		undo
 '
 
 # 10
 test_expect_success 'check if --message works as -m and --prefix as -P' '
-        git subtree add -P subdir -m "Added subproject using git subtree" sub1 &&
-        check_equal ''"$(last_commit_message)"'' "Added subproject using git subtree" &&
-        undo
+		git subtree add -P subdir -m "Added subproject using git subtree" sub1 &&
+		check_equal ''"$(last_commit_message)"'' "Added subproject using git subtree" &&
+		undo
 '
 
 # 11
 test_expect_success 'check if --message works with squash too' '
-        git subtree add -P subdir -m "Added subproject with squash" --squash sub1 &&
-        check_equal ''"$(last_commit_message)"'' "Added subproject with squash" &&
-        undo
+		git subtree add -P subdir -m "Added subproject with squash" --squash sub1 &&
+		check_equal ''"$(last_commit_message)"'' "Added subproject with squash" &&
+		undo
 '
 
 # 12
 test_expect_success 'add subproj to mainline' '
-        git subtree add --prefix=subdir/ FETCH_HEAD &&
-        check_equal ''"$(last_commit_message)"'' "Add '"'subdir/'"' from commit '"'"'''"$(git rev-parse sub1)"'''"'"'"
+		git subtree add --prefix=subdir/ FETCH_HEAD &&
+		check_equal ''"$(last_commit_message)"'' "Add '"'subdir/'"' from commit '"'"'''"$(git rev-parse sub1)"'''"'"'"
 '
 
 # 13
 # this shouldn't actually do anything, since FETCH_HEAD is already a parent
 test_expect_success 'merge fetched subproj' '
-        git merge -m "merge -s -ours" -s ours FETCH_HEAD
+		git merge -m "merge -s -ours" -s ours FETCH_HEAD
 '
 
 # 14
 test_expect_success 'add main-sub5' '
-        create subdir/main-sub5 &&
-        git commit -m "main-sub5"
+		create subdir/main-sub5 &&
+		git commit -m "main-sub5"
 '
 
 # 15
 test_expect_success 'add main6' '
-        create main6 &&
-        git commit -m "main6 boring"
+		create main6 &&
+		git commit -m "main6 boring"
 '
 
 # 16
 test_expect_success 'add main-sub7' '
-        create subdir/main-sub7 &&
-        git commit -m "main-sub7"
+		create subdir/main-sub7 &&
+		git commit -m "main-sub7"
 '
 
 # 17
 test_expect_success 'fetch new subproj history' '
-        git fetch ./subproj sub2 &&
-        git branch sub2 FETCH_HEAD
+		git fetch ./subproj sub2 &&
+		git branch sub2 FETCH_HEAD
 '
 
 # 18
 test_expect_success 'check if --message works for merge' '
-        git subtree merge --prefix=subdir -m "Merged changes from subproject" sub2 &&
-        check_equal ''"$(last_commit_message)"'' "Merged changes from subproject" &&
-        undo
+		git subtree merge --prefix=subdir -m "Merged changes from subproject" sub2 &&
+		check_equal ''"$(last_commit_message)"'' "Merged changes from subproject" &&
+		undo
 '
 
 # 19
 test_expect_success 'check if --message for merge works with squash too' '
-        git subtree merge --prefix subdir -m "Merged changes from subproject using squash" --squash sub2 &&
-        check_equal ''"$(last_commit_message)"'' "Merged changes from subproject using squash" &&
-        undo
+		git subtree merge --prefix subdir -m "Merged changes from subproject using squash" --squash sub2 &&
+		check_equal ''"$(last_commit_message)"'' "Merged changes from subproject using squash" &&
+		undo
 '
 
 # 20
 test_expect_success 'merge new subproj history into subdir' '
-        git subtree merge --prefix=subdir FETCH_HEAD &&
-        git branch pre-split &&
-        check_equal ''"$(last_commit_message)"'' "Merge commit '"'"'"$(git rev-parse sub2)"'"'"' into mainline"
+		git subtree merge --prefix=subdir FETCH_HEAD &&
+		git branch pre-split &&
+		check_equal ''"$(last_commit_message)"'' "Merge commit '"'"'"$(git rev-parse sub2)"'"'"' into mainline"
 '
 
 # 21
 test_expect_success 'Check that prefix argument is required for split' '
-        echo "You must provide the --prefix option." > expected &&
-        test_must_fail git subtree split > actual 2>&1 &&
-        test_debug "echo -n expected: " &&
-        test_debug "cat expected" &&
-        test_debug "echo -n actual: " &&
-        test_debug "cat actual" &&
-        test_cmp expected actual &&
-        rm -f expected actual
+		echo "You must provide the --prefix option." > expected &&
+		test_must_fail git subtree split > actual 2>&1 &&
+		test_debug "echo -n expected: " &&
+		test_debug "cat expected" &&
+		test_debug "echo -n actual: " &&
+		test_debug "cat actual" &&
+		test_cmp expected actual &&
+		rm -f expected actual
 '
 
 # 22
 test_expect_success 'Check that the <prefix> exists for a split' '
-        echo "'"'"'non-existent-directory'"'"'" does not exist\; use "'"'"'git subtree add'"'"'" > expected &&
-        test_must_fail git subtree split --prefix=non-existent-directory > actual 2>&1 &&
-        test_debug "echo -n expected: " &&
-        test_debug "cat expected" &&
-        test_debug "echo -n actual: " &&
-        test_debug "cat actual" &&
-        test_cmp expected actual
-#        rm -f expected actual
+		echo "'"'"'non-existent-directory'"'"'" does not exist\; use "'"'"'git subtree add'"'"'" > expected &&
+		test_must_fail git subtree split --prefix=non-existent-directory > actual 2>&1 &&
+		test_debug "echo -n expected: " &&
+		test_debug "cat expected" &&
+		test_debug "echo -n actual: " &&
+		test_debug "cat actual" &&
+		test_cmp expected actual
+#		 rm -f expected actual
 '
 
 # 23
 test_expect_success 'check if --message works for split+rejoin' '
-        spl1=''"$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"'' &&
-        git branch spl1 "$spl1" &&
-        check_equal ''"$(last_commit_message)"'' "Split & rejoin" &&
-        undo
+		spl1=''"$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"'' &&
+		git branch spl1 "$spl1" &&
+		check_equal ''"$(last_commit_message)"'' "Split & rejoin" &&
+		undo
 '
 
 # 24
 test_expect_success 'check split with --branch' '
-        spl1=$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin) &&
-        undo &&
-        git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --branch splitbr1 &&
-        check_equal ''"$(git rev-parse splitbr1)"'' "$spl1"
+		spl1=$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin) &&
+		undo &&
+		git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --branch splitbr1 &&
+		check_equal ''"$(git rev-parse splitbr1)"'' "$spl1"
 '
 
 # 25
 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 &&
-        git branch splitbr2 sub1 &&
-        git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --branch splitbr2 &&
-        check_equal ''"$(git rev-parse splitbr2)"'' "$spl1"
+		spl1=''"$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"'' &&
+		undo &&
+		git branch splitbr2 sub1 &&
+		git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --branch splitbr2 &&
+		check_equal ''"$(git rev-parse splitbr2)"'' "$spl1"
 '
 
 # 26
 test_expect_success 'check split with --branch for an incompatible branch' '
-        test_must_fail git subtree split --prefix subdir --onto FETCH_HEAD --branch subdir
+		test_must_fail git subtree split --prefix subdir --onto FETCH_HEAD --branch subdir
 '
 
 
 # 27
 test_expect_success 'check split+rejoin' '
-        spl1=''"$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"'' &&
-        undo &&
-        git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --rejoin &&
-        check_equal ''"$(last_commit_message)"'' "Split '"'"'subdir/'"'"' into commit '"'"'"$spl1"'"'"'"
+		spl1=''"$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"'' &&
+		undo &&
+		git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --rejoin &&
+		check_equal ''"$(last_commit_message)"'' "Split '"'"'subdir/'"'"' into commit '"'"'"$spl1"'"'"'"
 '
 
 # 28
 test_expect_success 'add main-sub8' '
-        create subdir/main-sub8 &&
-        git commit -m "main-sub8"
+		create subdir/main-sub8 &&
+		git commit -m "main-sub8"
 '
 
 # To the subproject!
@@ -269,15 +269,15 @@ cd ./subproj
 
 # 29
 test_expect_success 'merge split into subproj' '
-        git fetch .. spl1 &&
-        git branch spl1 FETCH_HEAD &&
-        git merge FETCH_HEAD
+		git fetch .. spl1 &&
+		git branch spl1 FETCH_HEAD &&
+		git merge FETCH_HEAD
 '
 
 # 30
 test_expect_success 'add sub9' '
-        create sub9 &&
-        git commit -m "sub9"
+		create sub9 &&
+		git commit -m "sub9"
 '
 
 # Back to mainline
@@ -285,20 +285,20 @@ cd ..
 
 # 31
 test_expect_success 'split for sub8' '
-        split2=''"$(git subtree split --annotate='"'*'"' --prefix subdir/ --rejoin)"''
-        git branch split2 "$split2"
+		split2=''"$(git subtree split --annotate='"'*'"' --prefix subdir/ --rejoin)"''
+		git branch split2 "$split2"
 '
 
 # 32
 test_expect_success 'add main-sub10' '
-        create subdir/main-sub10 &&
-        git commit -m "main-sub10"
+		create subdir/main-sub10 &&
+		git commit -m "main-sub10"
 '
 
 # 33
 test_expect_success 'split for sub10' '
-        spl3=''"$(git subtree split --annotate='"'*'"' --prefix subdir --rejoin)"'' &&
-        git branch spl3 "$spl3"
+		spl3=''"$(git subtree split --annotate='"'*'"' --prefix subdir --rejoin)"'' &&
+		git branch spl3 "$spl3"
 '
 
 # To the subproject!
@@ -306,10 +306,10 @@ cd ./subproj
 
 # 34
 test_expect_success 'merge split into subproj' '
-        git fetch .. spl3 &&
-        git branch spl3 FETCH_HEAD &&
-        git merge FETCH_HEAD &&
-        git branch subproj-merge-spl3
+		git fetch .. spl3 &&
+		git branch spl3 FETCH_HEAD &&
+		git merge FETCH_HEAD &&
+		git branch subproj-merge-spl3
 '
 
 chkm="main4 main6"
@@ -320,14 +320,14 @@ chks_sub=$(echo $chks | multiline | sed 's,^,subdir/,' | fixnl)
 
 # 35
 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"
+		subfiles=''"$(git ls-files | fixnl)"'' &&
+		check_equal "$subfiles" "$chkms $chks"
 '
 
 # 36
 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"
+		allchanges=''"$(git log --name-only --pretty=format:'"''"' | sort | fixnl)"'' &&
+		check_equal "$allchanges" "$chkms $chks"
 '
 
 # Back to mainline
@@ -335,35 +335,35 @@ cd ..
 
 # 37
 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
+		git fetch ./subproj subproj-merge-spl3 &&
+		git branch subproj-merge-spl3 FETCH_HEAD &&
+		git subtree pull --prefix=subdir ./subproj subproj-merge-spl3
 '
 
 # 38
 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"
+		mainfiles=''"$(git ls-files | fixnl)"'' &&
+		check_equal "$mainfiles" "$chkm $chkms_sub $chks_sub"
 '
 
 # 39
 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
-        # change, since they were *only* changed in the subtree branch.
-        allchanges=''"$(git log --name-only --pretty=format:'"''"' | sort | fixnl)"'' &&
-        check_equal "$allchanges" ''"$(echo $chkms $chkm $chks $chkms_sub | multiline | sort | fixnl)"''
+		# main-sub?? and /subdir/main-sub?? both change, because those are the
+		# changes that were split into their own history.  And subdir/sub?? never
+		# change, since they were *only* changed in the subtree branch.
+		allchanges=''"$(git log --name-only --pretty=format:'"''"' | sort | fixnl)"'' &&
+		check_equal "$allchanges" ''"$(echo $chkms $chkm $chks $chkms_sub | multiline | sort | fixnl)"''
 '
 
 # 40
 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)"'' ""
+		check_equal ''"$(git log --pretty=format:'"'%s'"' HEAD^2 | grep -i split)"'' ""
 '
 
 # 41
 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.*:")"'' ""
+		# 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.*:")"'' ""
 '
 
 # prepare second pair of repositories
@@ -372,30 +372,30 @@ cd test2
 
 # 42
 test_expect_success 'init main' '
-        test_create_repo main
+		test_create_repo main
 '
 
 cd main
 
 # 43
 test_expect_success 'add main1' '
-        create main1 &&
-        git commit -m "main1"
+		create main1 &&
+		git commit -m "main1"
 '
 
 cd ..
 
 # 44
 test_expect_success 'init sub' '
-        test_create_repo sub
+		test_create_repo sub
 '
 
 cd sub
 
 # 45
 test_expect_success 'add sub2' '
-        create sub2 &&
-        git commit -m "sub2"
+		create sub2 &&
+		git commit -m "sub2"
 '
 
 cd ../main
@@ -404,37 +404,37 @@ cd ../main
 
 # 46
 test_expect_success 'add sub as subdir in main' '
-        git fetch ../sub master &&
-        git branch sub2 FETCH_HEAD &&
-        git subtree add --prefix subdir sub2
+		git fetch ../sub master &&
+		git branch sub2 FETCH_HEAD &&
+		git subtree add --prefix subdir sub2
 '
 
 cd ../sub
 
 # 47
 test_expect_success 'add sub3' '
-        create sub3 &&
-        git commit -m "sub3"
+		create sub3 &&
+		git commit -m "sub3"
 '
 
 cd ../main
 
 # 48
 test_expect_success 'merge from sub' '
-        git fetch ../sub master &&
-        git branch sub3 FETCH_HEAD &&
-        git subtree merge --prefix subdir sub3
+		git fetch ../sub master &&
+		git branch sub3 FETCH_HEAD &&
+		git subtree merge --prefix subdir sub3
 '
 
 # 49
 test_expect_success 'add main-sub4' '
-        create subdir/main-sub4 &&
-        git commit -m "main-sub4"
+		create subdir/main-sub4 &&
+		git commit -m "main-sub4"
 '
 
 # 50
 test_expect_success 'split for main-sub4 without --onto' '
-        git subtree split --prefix subdir --branch mainsub4
+		git subtree split --prefix subdir --branch mainsub4
 '
 
 # at this point, the new commit parent should be sub3 if it is not,
@@ -444,23 +444,23 @@ test_expect_success 'split for main-sub4 without --onto' '
 
 # 51
 test_expect_success 'check that the commit parent is sub3' '
-        check_equal ''"$(git log --pretty=format:%P -1 mainsub4)"'' ''"$(git rev-parse sub3)"''
+		check_equal ''"$(git log --pretty=format:%P -1 mainsub4)"'' ''"$(git rev-parse sub3)"''
 '
 
 # 52
 test_expect_success 'add main-sub5' '
-        mkdir subdir2 &&
-        create subdir2/main-sub5 &&
-        git commit -m "main-sub5"
+		mkdir subdir2 &&
+		create subdir2/main-sub5 &&
+		git commit -m "main-sub5"
 '
 
 # 53
 test_expect_success 'split for main-sub5 without --onto' '
-        # also test that we still can split out an entirely new subtree
-        # if the parent of the first commit in the tree is not empty,
-        # then the new subtree has accidently been attached to something
-        git subtree split --prefix subdir2 --branch mainsub5 &&
-        check_equal ''"$(git log --pretty=format:%P -1 mainsub5)"'' ""
+		# also test that we still can split out an entirely new subtree
+		# if the parent of the first commit in the tree is not empty,
+		# then the new subtree has accidently been attached to something
+		git subtree split --prefix subdir2 --branch mainsub5 &&
+		check_equal ''"$(git log --pretty=format:%P -1 mainsub5)"'' ""
 '
 
 # make sure no patch changes more than one file.  The original set of commits
@@ -489,20 +489,20 @@ joincommits()
 
 # 54
 test_expect_success 'verify one file change per commit' '
-        x= &&
-        list=''"$(git log --pretty=format:'"'commit: %H'"' | joincommits)"'' &&
-#        test_debug "echo HERE" &&
-#        test_debug "echo ''"$list"''" &&
-        (git log --pretty=format:'"'commit: %H'"' | joincommits |
-        (       while read commit a b; do
-		        test_debug "echo Verifying commit "''"$commit"''
-		        test_debug "echo a: "''"$a"''
-		        test_debug "echo b: "''"$b"''
-		        check_equal "$b" ""
-		        x=1
-	        done
-	        check_equal "$x" 1
-        ))
+		x= &&
+		list=''"$(git log --pretty=format:'"'commit: %H'"' | joincommits)"'' &&
+#		 test_debug "echo HERE" &&
+#		 test_debug "echo ''"$list"''" &&
+		(git log --pretty=format:'"'commit: %H'"' | joincommits |
+		(		while read commit a b; do
+				test_debug "echo Verifying commit "''"$commit"''
+				test_debug "echo a: "''"$a"''
+				test_debug "echo b: "''"$b"''
+				check_equal "$b" ""
+				x=1
+			done
+			check_equal "$x" 1
+		))
 '
 
 test_done
-- 
1.8.1

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH/RFC v2 2/8] contrib/subtree: Add vim modeline
  2013-01-14  3:52 ` [PATCH/RFC v2 0/8] contrib/subtree: Reroll to follow Git's whitespace policy Techlive Zheng
  2013-01-14  3:52   ` [PATCH/RFC v2 1/8] contrib/subtree: Fix whitespaces Techlive Zheng
@ 2013-01-14  3:52   ` Techlive Zheng
  2013-01-14  3:52   ` [PATCH/RFC v2 3/8] contrib/subtree: Ignore testing directory Techlive Zheng
                     ` (5 subsequent siblings)
  7 siblings, 0 replies; 18+ messages in thread
From: Techlive Zheng @ 2013-01-14  3:52 UTC (permalink / raw
  To: git; +Cc: apenwarr, greened, Techlive Zheng

Signed-off-by: Techlive Zheng <techlivezheng@gmail.com>
---
 contrib/subtree/git-subtree.sh     | 2 ++
 contrib/subtree/t/t7900-subtree.sh | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 70f86ea..88903c0 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -710,3 +710,5 @@ cmd_push()
 }
 
 "cmd_$command" "$@"
+
+# vim: set ts=4 sw=4 noet
diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh
index b98f7d0..e32d31a 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -506,3 +506,5 @@ test_expect_success 'verify one file change per commit' '
 '
 
 test_done
+
+# vim: set ts=4 sw=4 noet
-- 
1.8.1

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH/RFC v2 3/8] contrib/subtree: Ignore testing directory
  2013-01-14  3:52 ` [PATCH/RFC v2 0/8] contrib/subtree: Reroll to follow Git's whitespace policy Techlive Zheng
  2013-01-14  3:52   ` [PATCH/RFC v2 1/8] contrib/subtree: Fix whitespaces Techlive Zheng
  2013-01-14  3:52   ` [PATCH/RFC v2 2/8] contrib/subtree: Add vim modeline Techlive Zheng
@ 2013-01-14  3:52   ` Techlive Zheng
  2013-01-14  3:52   ` [PATCH/RFC v2 4/8] contrib/subtree: Remove test number comments Techlive Zheng
                     ` (4 subsequent siblings)
  7 siblings, 0 replies; 18+ messages in thread
From: Techlive Zheng @ 2013-01-14  3:52 UTC (permalink / raw
  To: git; +Cc: apenwarr, greened, Techlive Zheng

Signed-off-by: Techlive Zheng <techlivezheng@gmail.com>
---
 contrib/subtree/.gitignore | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/contrib/subtree/.gitignore b/contrib/subtree/.gitignore
index 91360a3..59aeeb4 100644
--- a/contrib/subtree/.gitignore
+++ b/contrib/subtree/.gitignore
@@ -1,6 +1,5 @@
 *~
 git-subtree
-git-subtree.xml
 git-subtree.1
-mainline
-subproj
+git-subtree.xml
+t/trash\ directory.*
-- 
1.8.1

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH/RFC v2 4/8] contrib/subtree: Remove test number comments
  2013-01-14  3:52 ` [PATCH/RFC v2 0/8] contrib/subtree: Reroll to follow Git's whitespace policy Techlive Zheng
                     ` (2 preceding siblings ...)
  2013-01-14  3:52   ` [PATCH/RFC v2 3/8] contrib/subtree: Ignore testing directory Techlive Zheng
@ 2013-01-14  3:52   ` Techlive Zheng
  2013-01-14  3:52   ` [PATCH/RFC v2 5/8] contrib/subtree: Code cleaning and refactoring Techlive Zheng
                     ` (3 subsequent siblings)
  7 siblings, 0 replies; 18+ messages in thread
From: Techlive Zheng @ 2013-01-14  3:52 UTC (permalink / raw
  To: git; +Cc: apenwarr, greened, Techlive Zheng

From: "David A. Greene" <greened@obbligato.org>

Delete the comments indicating test numbers as it causes maintenance
headaches.  t*.sh -i will help us find any broken tests.

Signed-off-by: David A. Greene <greened@obbligato.org>
Signed-off-by: Techlive Zheng <techlivezheng@gmail.com>
---
 contrib/subtree/t/t7900-subtree.sh | 55 --------------------------------------
 1 file changed, 55 deletions(-)

diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh
index e32d31a..851d00c 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -60,7 +60,6 @@ last_commit_message()
 	git log --pretty=format:%s -1
 }
 
-# 1
 test_expect_success 'init subproj' '
 		test_create_repo subproj
 '
@@ -68,7 +67,6 @@ test_expect_success 'init subproj' '
 # To the subproject!
 cd subproj
 
-# 2
 test_expect_success 'add sub1' '
 		create sub1 &&
 		git commit -m "sub1" &&
@@ -76,14 +74,12 @@ test_expect_success 'add sub1' '
 		git branch -m master subproj
 '
 
-# 3
 test_expect_success 'add sub2' '
 		create sub2 &&
 		git commit -m "sub2" &&
 		git branch sub2
 '
 
-# 4
 test_expect_success 'add sub3' '
 		create sub3 &&
 		git commit -m "sub3" &&
@@ -93,7 +89,6 @@ test_expect_success 'add sub3' '
 # Back to mainline
 cd ..
 
-# 5
 test_expect_success 'add main4' '
 		create main4 &&
 		git commit -m "main4" &&
@@ -101,101 +96,85 @@ test_expect_success 'add main4' '
 		git branch subdir
 '
 
-# 6
 test_expect_success 'fetch subproj history' '
 		git fetch ./subproj sub1 &&
 		git branch sub1 FETCH_HEAD
 '
 
-# 7
 test_expect_success 'no subtree exists in main tree' '
 		test_must_fail git subtree merge --prefix=subdir sub1
 '
 
-# 8
 test_expect_success 'no pull from non-existant subtree' '
 		test_must_fail git subtree pull --prefix=subdir ./subproj sub1
 '
 
-# 9
 test_expect_success 'check if --message works for add' '
 		git subtree add --prefix=subdir --message="Added subproject" sub1 &&
 		check_equal ''"$(last_commit_message)"'' "Added subproject" &&
 		undo
 '
 
-# 10
 test_expect_success 'check if --message works as -m and --prefix as -P' '
 		git subtree add -P subdir -m "Added subproject using git subtree" sub1 &&
 		check_equal ''"$(last_commit_message)"'' "Added subproject using git subtree" &&
 		undo
 '
 
-# 11
 test_expect_success 'check if --message works with squash too' '
 		git subtree add -P subdir -m "Added subproject with squash" --squash sub1 &&
 		check_equal ''"$(last_commit_message)"'' "Added subproject with squash" &&
 		undo
 '
 
-# 12
 test_expect_success 'add subproj to mainline' '
 		git subtree add --prefix=subdir/ FETCH_HEAD &&
 		check_equal ''"$(last_commit_message)"'' "Add '"'subdir/'"' from commit '"'"'''"$(git rev-parse sub1)"'''"'"'"
 '
 
-# 13
 # this shouldn't actually do anything, since FETCH_HEAD is already a parent
 test_expect_success 'merge fetched subproj' '
 		git merge -m "merge -s -ours" -s ours FETCH_HEAD
 '
 
-# 14
 test_expect_success 'add main-sub5' '
 		create subdir/main-sub5 &&
 		git commit -m "main-sub5"
 '
 
-# 15
 test_expect_success 'add main6' '
 		create main6 &&
 		git commit -m "main6 boring"
 '
 
-# 16
 test_expect_success 'add main-sub7' '
 		create subdir/main-sub7 &&
 		git commit -m "main-sub7"
 '
 
-# 17
 test_expect_success 'fetch new subproj history' '
 		git fetch ./subproj sub2 &&
 		git branch sub2 FETCH_HEAD
 '
 
-# 18
 test_expect_success 'check if --message works for merge' '
 		git subtree merge --prefix=subdir -m "Merged changes from subproject" sub2 &&
 		check_equal ''"$(last_commit_message)"'' "Merged changes from subproject" &&
 		undo
 '
 
-# 19
 test_expect_success 'check if --message for merge works with squash too' '
 		git subtree merge --prefix subdir -m "Merged changes from subproject using squash" --squash sub2 &&
 		check_equal ''"$(last_commit_message)"'' "Merged changes from subproject using squash" &&
 		undo
 '
 
-# 20
 test_expect_success 'merge new subproj history into subdir' '
 		git subtree merge --prefix=subdir FETCH_HEAD &&
 		git branch pre-split &&
 		check_equal ''"$(last_commit_message)"'' "Merge commit '"'"'"$(git rev-parse sub2)"'"'"' into mainline"
 '
 
-# 21
 test_expect_success 'Check that prefix argument is required for split' '
 		echo "You must provide the --prefix option." > expected &&
 		test_must_fail git subtree split > actual 2>&1 &&
@@ -207,7 +186,6 @@ test_expect_success 'Check that prefix argument is required for split' '
 		rm -f expected actual
 '
 
-# 22
 test_expect_success 'Check that the <prefix> exists for a split' '
 		echo "'"'"'non-existent-directory'"'"'" does not exist\; use "'"'"'git subtree add'"'"'" > expected &&
 		test_must_fail git subtree split --prefix=non-existent-directory > actual 2>&1 &&
@@ -219,7 +197,6 @@ test_expect_success 'Check that the <prefix> exists for a split' '
 #		 rm -f expected actual
 '
 
-# 23
 test_expect_success 'check if --message works for split+rejoin' '
 		spl1=''"$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"'' &&
 		git branch spl1 "$spl1" &&
@@ -227,7 +204,6 @@ test_expect_success 'check if --message works for split+rejoin' '
 		undo
 '
 
-# 24
 test_expect_success 'check split with --branch' '
 		spl1=$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin) &&
 		undo &&
@@ -235,7 +211,6 @@ test_expect_success 'check split with --branch' '
 		check_equal ''"$(git rev-parse splitbr1)"'' "$spl1"
 '
 
-# 25
 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 +219,10 @@ test_expect_success 'check split with --branch for an existing branch' '
 		check_equal ''"$(git rev-parse splitbr2)"'' "$spl1"
 '
 
-# 26
 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
 test_expect_success 'check split+rejoin' '
 		spl1=''"$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"'' &&
 		undo &&
@@ -258,7 +230,6 @@ test_expect_success 'check split+rejoin' '
 		check_equal ''"$(last_commit_message)"'' "Split '"'"'subdir/'"'"' into commit '"'"'"$spl1"'"'"'"
 '
 
-# 28
 test_expect_success 'add main-sub8' '
 		create subdir/main-sub8 &&
 		git commit -m "main-sub8"
@@ -267,14 +238,12 @@ test_expect_success 'add main-sub8' '
 # To the subproject!
 cd ./subproj
 
-# 29
 test_expect_success 'merge split into subproj' '
 		git fetch .. spl1 &&
 		git branch spl1 FETCH_HEAD &&
 		git merge FETCH_HEAD
 '
 
-# 30
 test_expect_success 'add sub9' '
 		create sub9 &&
 		git commit -m "sub9"
@@ -283,19 +252,16 @@ test_expect_success 'add sub9' '
 # Back to mainline
 cd ..
 
-# 31
 test_expect_success 'split for sub8' '
 		split2=''"$(git subtree split --annotate='"'*'"' --prefix subdir/ --rejoin)"''
 		git branch split2 "$split2"
 '
 
-# 32
 test_expect_success 'add main-sub10' '
 		create subdir/main-sub10 &&
 		git commit -m "main-sub10"
 '
 
-# 33
 test_expect_success 'split for sub10' '
 		spl3=''"$(git subtree split --annotate='"'*'"' --prefix subdir --rejoin)"'' &&
 		git branch spl3 "$spl3"
@@ -304,7 +270,6 @@ test_expect_success 'split for sub10' '
 # To the subproject!
 cd ./subproj
 
-# 34
 test_expect_success 'merge split into subproj' '
 		git fetch .. spl3 &&
 		git branch spl3 FETCH_HEAD &&
@@ -318,13 +283,11 @@ chkms_sub=$(echo $chkms | multiline | sed 's,^,subdir/,' | fixnl)
 chks="sub1 sub2 sub3 sub9"
 chks_sub=$(echo $chks | multiline | sed 's,^,subdir/,' | fixnl)
 
-# 35
 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
 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 +296,17 @@ test_expect_success 'make sure the subproj history *only* contains commits that
 # Back to mainline
 cd ..
 
-# 37
 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
 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
 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 +315,10 @@ 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
 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
 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 +328,12 @@ test_expect_success 'make sure no "git subtree" tagged commits make it into subp
 mkdir test2
 cd test2
 
-# 42
 test_expect_success 'init main' '
 		test_create_repo main
 '
 
 cd main
 
-# 43
 test_expect_success 'add main1' '
 		create main1 &&
 		git commit -m "main1"
@@ -385,14 +341,12 @@ test_expect_success 'add main1' '
 
 cd ..
 
-# 44
 test_expect_success 'init sub' '
 		test_create_repo sub
 '
 
 cd sub
 
-# 45
 test_expect_success 'add sub2' '
 		create sub2 &&
 		git commit -m "sub2"
@@ -402,7 +356,6 @@ cd ../main
 
 # check if split can find proper base without --onto
 
-# 46
 test_expect_success 'add sub as subdir in main' '
 		git fetch ../sub master &&
 		git branch sub2 FETCH_HEAD &&
@@ -411,7 +364,6 @@ test_expect_success 'add sub as subdir in main' '
 
 cd ../sub
 
-# 47
 test_expect_success 'add sub3' '
 		create sub3 &&
 		git commit -m "sub3"
@@ -419,20 +371,17 @@ test_expect_success 'add sub3' '
 
 cd ../main
 
-# 48
 test_expect_success 'merge from sub' '
 		git fetch ../sub master &&
 		git branch sub3 FETCH_HEAD &&
 		git subtree merge --prefix subdir sub3
 '
 
-# 49
 test_expect_success 'add main-sub4' '
 		create subdir/main-sub4 &&
 		git commit -m "main-sub4"
 '
 
-# 50
 test_expect_success 'split for main-sub4 without --onto' '
 		git subtree split --prefix subdir --branch mainsub4
 '
@@ -442,19 +391,16 @@ 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
 test_expect_success 'check that the commit parent is sub3' '
 		check_equal ''"$(git log --pretty=format:%P -1 mainsub4)"'' ''"$(git rev-parse sub3)"''
 '
 
-# 52
 test_expect_success 'add main-sub5' '
 		mkdir subdir2 &&
 		create subdir2/main-sub5 &&
 		git commit -m "main-sub5"
 '
 
-# 53
 test_expect_success 'split for main-sub5 without --onto' '
 		# also test that we still can split out an entirely new subtree
 		# if the parent of the first commit in the tree is not empty,
@@ -487,7 +433,6 @@ joincommits()
 	echo "$commit $all"
 }
 
-# 54
 test_expect_success 'verify one file change per commit' '
 		x= &&
 		list=''"$(git log --pretty=format:'"'commit: %H'"' | joincommits)"'' &&
-- 
1.8.1

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH/RFC v2 5/8] contrib/subtree: Code cleaning and refactoring
  2013-01-14  3:52 ` [PATCH/RFC v2 0/8] contrib/subtree: Reroll to follow Git's whitespace policy Techlive Zheng
                     ` (3 preceding siblings ...)
  2013-01-14  3:52   ` [PATCH/RFC v2 4/8] contrib/subtree: Remove test number comments Techlive Zheng
@ 2013-01-14  3:52   ` Techlive Zheng
  2013-01-14  3:52   ` [PATCH/RFC v2 6/8] contrib/subtree: Make each test self-contained Techlive Zheng
                     ` (2 subsequent siblings)
  7 siblings, 0 replies; 18+ messages in thread
From: Techlive Zheng @ 2013-01-14  3:52 UTC (permalink / raw
  To: git; +Cc: apenwarr, greened, Techlive Zheng

Mostly prepare for the later tests refactoring.

Signed-off-by: Techlive Zheng <techlivezheng@gmail.com>
---
 contrib/subtree/t/t7900-subtree.sh | 251 +++++++++++++++++++------------------
 1 file changed, 130 insertions(+), 121 deletions(-)

diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh
index 851d00c..69bd41c 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -4,7 +4,7 @@
 #
 test_description='Basic porcelain support for subtrees
 
-This test verifies the basic operation of the merge, pull, add
+This test verifies the basic operation of the add, pull, merge
 and split subcommands of git subtree.
 '
 
@@ -18,19 +18,6 @@ create()
 	git add "$1"
 }
 
-
-check_equal()
-{
-	test_debug 'echo'
-	test_debug "echo \"check a:\" \"{$1}\""
-	test_debug "echo \"		 b:\" \"{$2}\""
-	if [ "$1" = "$2" ]; then
-		return 0
-	else
-		return 1
-	fi
-}
-
 fixnl()
 {
 	t=""
@@ -55,6 +42,42 @@ undo()
 	git reset --hard HEAD~
 }
 
+test_equal()
+{
+	test_debug 'echo'
+	test_debug "echo \"check a:\" \"{$1}\""
+	test_debug "echo \"		 b:\" \"{$2}\""
+	if [ "$1" = "$2" ]; then
+		return 0
+	else
+		return 1
+	fi
+}
+
+# Make sure no patch changes more than one file.
+# The original set of commits changed only one file each.
+# A multi-file change would imply that we pruned commits
+# too aggressively.
+join_commits()
+{
+	commit=
+	all=
+	while read x y; do
+		if [ -z "$x" ]; then
+			continue
+		elif [ "$x" = "commit:" ]; then
+			if [ -n "$commit" ]; then
+				echo "$commit $all"
+				all=
+			fi
+			commit="$y"
+		else
+			all="$all $y"
+		fi
+	done
+	echo "$commit $all"
+}
+
 last_commit_message()
 {
 	git log --pretty=format:%s -1
@@ -93,7 +116,7 @@ test_expect_success 'add main4' '
 		create main4 &&
 		git commit -m "main4" &&
 		git branch -m master mainline &&
-		git branch subdir
+		git branch init
 '
 
 test_expect_success 'fetch subproj history' '
@@ -101,40 +124,43 @@ test_expect_success 'fetch subproj history' '
 		git branch sub1 FETCH_HEAD
 '
 
-test_expect_success 'no subtree exists in main tree' '
-		test_must_fail git subtree merge --prefix=subdir sub1
-'
-
 test_expect_success 'no pull from non-existant subtree' '
 		test_must_fail git subtree pull --prefix=subdir ./subproj sub1
 '
 
-test_expect_success 'check if --message works for add' '
-		git subtree add --prefix=subdir --message="Added subproject" sub1 &&
-		check_equal ''"$(last_commit_message)"'' "Added subproject" &&
+test_expect_success 'no merge from non-existant subtree' '
+		test_must_fail git subtree merge --prefix=subdir FETCH_HEAD
+'
+
+test_expect_success 'add subproj as subtree into subdir/ with --prefix' '
+		git subtree add --prefix=subdir FETCH_HEAD &&
+		test_equal "$(last_commit_message)" "Add '\''subdir/'\'' from commit '\''$(git rev-parse FETCH_HEAD)'\''" &&
 		undo
 '
 
-test_expect_success 'check if --message works as -m and --prefix as -P' '
-		git subtree add -P subdir -m "Added subproject using git subtree" sub1 &&
-		check_equal ''"$(last_commit_message)"'' "Added subproject using git subtree" &&
+test_expect_success 'add subproj as subtree into subdir/ with --prefix and --message' '
+		git subtree add --prefix=subdir --message="Added subproject" FETCH_HEAD &&
+		test_equal "$(last_commit_message)" "Added subproject" &&
 		undo
 '
 
-test_expect_success 'check if --message works with squash too' '
-		git subtree add -P subdir -m "Added subproject with squash" --squash sub1 &&
-		check_equal ''"$(last_commit_message)"'' "Added subproject with squash" &&
+test_expect_success 'add subproj as subtree into subdir/ with --prefix as -P and --message as -m' '
+		git subtree add -P subdir -m "Added subproject" FETCH_HEAD &&
+		test_equal "$(last_commit_message)" "Added subproject" &&
 		undo
 '
 
-test_expect_success 'add subproj to mainline' '
-		git subtree add --prefix=subdir/ FETCH_HEAD &&
-		check_equal ''"$(last_commit_message)"'' "Add '"'subdir/'"' from commit '"'"'''"$(git rev-parse sub1)"'''"'"'"
+test_expect_success 'add subproj as subtree into subdir/ with --squash and --prefix and --message' '
+		git subtree add --prefix=subdir --message="Added subproject with squash" --squash FETCH_HEAD &&
+		test_equal "$(last_commit_message)" "Added subproject with squash" &&
+		undo
 '
 
-# this shouldn't actually do anything, since FETCH_HEAD is already a parent
-test_expect_success 'merge fetched subproj' '
-		git merge -m "merge -s -ours" -s ours FETCH_HEAD
+test_expect_success 'merge the added subproj again, should do nothing' '
+		git subtree add --prefix=subdir FETCH_HEAD &&
+		# this shouldn not actually do anything, since FETCH_HEAD
+		# is already a parent
+		git merge -s ours -m "merge -s -ours" FETCH_HEAD
 '
 
 test_expect_success 'add main-sub5' '
@@ -157,25 +183,30 @@ test_expect_success 'fetch new subproj history' '
 		git branch sub2 FETCH_HEAD
 '
 
-test_expect_success 'check if --message works for merge' '
-		git subtree merge --prefix=subdir -m "Merged changes from subproject" sub2 &&
-		check_equal ''"$(last_commit_message)"'' "Merged changes from subproject" &&
+test_expect_success 'merge new subproj history into subdir/ with --prefix' '
+		git subtree merge --prefix=subdir FETCH_HEAD &&
+		test_equal "$(last_commit_message)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\'' into mainline" &&
 		undo
 '
 
-test_expect_success 'check if --message for merge works with squash too' '
-		git subtree merge --prefix subdir -m "Merged changes from subproject using squash" --squash sub2 &&
-		check_equal ''"$(last_commit_message)"'' "Merged changes from subproject using squash" &&
+test_expect_success 'merge new subproj history into subdir/ with --prefix and --message' '
+		git subtree merge --prefix=subdir --message="Merged changes from subproject" FETCH_HEAD &&
+		test_equal "$(last_commit_message)" "Merged changes from subproject" &&
 		undo
 '
 
-test_expect_success 'merge new subproj history into subdir' '
+test_expect_success 'merge new subproj history into subdir/ with --squash and --prefix and --message' '
+		git subtree merge --prefix=subdir --message="Merged changes from subproject using squash" --squash FETCH_HEAD &&
+		test_equal "$(last_commit_message)" "Merged changes from subproject using squash" &&
+		undo
+'
+
+test_expect_success 'merge new subproj history into subdir/' '
 		git subtree merge --prefix=subdir FETCH_HEAD &&
-		git branch pre-split &&
-		check_equal ''"$(last_commit_message)"'' "Merge commit '"'"'"$(git rev-parse sub2)"'"'"' into mainline"
+		git branch pre-split
 '
 
-test_expect_success 'Check that prefix argument is required for split' '
+test_expect_success 'split requires option --prefix' '
 		echo "You must provide the --prefix option." > expected &&
 		test_must_fail git subtree split > actual 2>&1 &&
 		test_debug "echo -n expected: " &&
@@ -186,48 +217,52 @@ test_expect_success 'Check that prefix argument is required for split' '
 		rm -f expected actual
 '
 
-test_expect_success 'Check that the <prefix> exists for a split' '
-		echo "'"'"'non-existent-directory'"'"'" does not exist\; use "'"'"'git subtree add'"'"'" > expected &&
+test_expect_success 'split requires path given by option --prefix must exist' '
+		echo "'\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" > expected &&
 		test_must_fail git subtree split --prefix=non-existent-directory > actual 2>&1 &&
 		test_debug "echo -n expected: " &&
 		test_debug "cat expected" &&
 		test_debug "echo -n actual: " &&
 		test_debug "cat actual" &&
-		test_cmp expected actual
-#		 rm -f expected actual
+		test_cmp expected actual &&
+		rm -f expected actual
 '
 
-test_expect_success 'check if --message works for split+rejoin' '
-		spl1=''"$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"'' &&
+test_expect_success 'split subdir/ with --rejoin' '
+		spl1=$(git subtree split --prefix=subdir --annotate="*") &&
 		git branch spl1 "$spl1" &&
-		check_equal ''"$(last_commit_message)"'' "Split & rejoin" &&
+		git subtree split --prefix=subdir --annotate="*" --rejoin &&
+		test_equal "$(last_commit_message)" "Split '\''subdir/'\'' into commit '\''$spl1'\''" &&
 		undo
 '
 
-test_expect_success 'check split with --branch' '
-		spl1=$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin) &&
+test_expect_success 'split subdir/ with --rejoin and --message' '
+		git subtree split --prefix=subdir --message="Split & rejoin" --annotate="*" --rejoin &&
+		test_equal "$(last_commit_message)" "Split & rejoin" &&
+		undo
+'
+
+test_expect_success 'split subdir/ with --branch' '
+		spl1=$(git subtree split --prefix=subdir --message="Split & rejoin" --annotate="*" --rejoin) &&
 		undo &&
-		git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --branch splitbr1 &&
-		check_equal ''"$(git rev-parse splitbr1)"'' "$spl1"
+		git subtree split --prefix=subdir --annotate="*" --branch splitbr1 &&
+		test_equal "$(git rev-parse splitbr1)" "$spl1"
 '
 
-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)"'' &&
+test_expect_success 'split subdir/ with --branch for an existing branch' '
+		spl1=$(git subtree split --prefix=subdir --annotate="*" --message="Split & rejoin" --rejoin) &&
 		undo &&
 		git branch splitbr2 sub1 &&
-		git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --branch splitbr2 &&
-		check_equal ''"$(git rev-parse splitbr2)"'' "$spl1"
+		git subtree split --prefix=subdir --annotate="*" --branch splitbr2 &&
+		test_equal "$(git rev-parse splitbr2)" "$spl1"
 '
 
-test_expect_success 'check split with --branch for an incompatible branch' '
-		test_must_fail git subtree split --prefix subdir --onto FETCH_HEAD --branch subdir
+test_expect_success 'split subdir/ with --branch for an incompatible branch' '
+		test_must_fail git subtree split --prefix=subdir --branch init
 '
 
-test_expect_success 'check split+rejoin' '
-		spl1=''"$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"'' &&
-		undo &&
-		git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --rejoin &&
-		check_equal ''"$(last_commit_message)"'' "Split '"'"'subdir/'"'"' into commit '"'"'"$spl1"'"'"'"
+test_expect_success 'split and rejoin' '
+		git subtree split --prefix=subdir --annotate="*" --rejoin
 '
 
 test_expect_success 'add main-sub8' '
@@ -253,8 +288,8 @@ test_expect_success 'add sub9' '
 cd ..
 
 test_expect_success 'split for sub8' '
-		split2=''"$(git subtree split --annotate='"'*'"' --prefix subdir/ --rejoin)"''
-		git branch split2 "$split2"
+		spl2=$(git subtree split --prefix=subdir/ --annotate="*" --rejoin) &&
+		git branch spl2 "$spl2"
 '
 
 test_expect_success 'add main-sub10' '
@@ -263,7 +298,7 @@ test_expect_success 'add main-sub10' '
 '
 
 test_expect_success 'split for sub10' '
-		spl3=''"$(git subtree split --annotate='"'*'"' --prefix subdir --rejoin)"'' &&
+		spl3=$(git subtree split --prefix=subdir --annotate="*" --rejoin) &&
 		git branch spl3 "$spl3"
 '
 
@@ -284,13 +319,13 @@ chks="sub1 sub2 sub3 sub9"
 chks_sub=$(echo $chks | multiline | sed 's,^,subdir/,' | fixnl)
 
 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"
+		subfiles=$(git ls-files | fixnl) &&
+		test_equal "$subfiles" "$chkms $chks"
 '
 
-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"
+test_expect_success 'make sure the subproj *only* contains commits that affect the subdir' '
+		allchanges=$(git log --name-only --pretty=format:"" | sort | fixnl) &&
+		test_equal "$allchanges" "$chkms $chks"
 '
 
 # Back to mainline
@@ -303,25 +338,25 @@ test_expect_success 'pull from subproj' '
 '
 
 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"
+		mainfiles=$(git ls-files | fixnl) &&
+		test_equal "$mainfiles" "$chkm $chkms_sub $chks_sub"
 '
 
 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
 		# change, since they were *only* changed in the subtree branch.
-		allchanges=''"$(git log --name-only --pretty=format:'"''"' | sort | fixnl)"'' &&
-		check_equal "$allchanges" ''"$(echo $chkms $chkm $chks $chkms_sub | multiline | sort | fixnl)"''
+		allchanges=$(git log --name-only --pretty=format:"" | sort | fixnl) &&
+		test_equal "$allchanges" "$(echo $chkms $chkm $chks $chkms_sub | multiline | sort | fixnl)"
 '
 
 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)"'' ""
+		test_equal "$(git log --pretty=format:"%s" HEAD^2 | grep -i split)" ""
 '
 
 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.*:")"'' ""
+		test_equal "$(git log --pretty=format:"%s%n%b" HEAD^2 | grep "git-subtree.*:")" ""
 '
 
 # prepare second pair of repositories
@@ -359,7 +394,7 @@ cd ../main
 test_expect_success 'add sub as subdir in main' '
 		git fetch ../sub master &&
 		git branch sub2 FETCH_HEAD &&
-		git subtree add --prefix subdir sub2
+		git subtree add --prefix=subdir sub2
 '
 
 cd ../sub
@@ -374,7 +409,7 @@ cd ../main
 test_expect_success 'merge from sub' '
 		git fetch ../sub master &&
 		git branch sub3 FETCH_HEAD &&
-		git subtree merge --prefix subdir sub3
+		git subtree merge --prefix=subdir sub3
 '
 
 test_expect_success 'add main-sub4' '
@@ -383,7 +418,7 @@ test_expect_success 'add main-sub4' '
 '
 
 test_expect_success 'split for main-sub4 without --onto' '
-		git subtree split --prefix subdir --branch mainsub4
+		git subtree split --prefix=subdir --branch mainsub4
 '
 
 # at this point, the new commit parent should be sub3 if it is not,
@@ -392,7 +427,7 @@ test_expect_success 'split for main-sub4 without --onto' '
 # itself)
 
 test_expect_success 'check that the commit parent is sub3' '
-		check_equal ''"$(git log --pretty=format:%P -1 mainsub4)"'' ''"$(git rev-parse sub3)"''
+		test_equal "$(git log --pretty=format:%P -1 mainsub4)" "$(git rev-parse sub3)"
 '
 
 test_expect_success 'add main-sub5' '
@@ -405,49 +440,23 @@ test_expect_success 'split for main-sub5 without --onto' '
 		# also test that we still can split out an entirely new subtree
 		# if the parent of the first commit in the tree is not empty,
 		# then the new subtree has accidently been attached to something
-		git subtree split --prefix subdir2 --branch mainsub5 &&
-		check_equal ''"$(git log --pretty=format:%P -1 mainsub5)"'' ""
+		git subtree split --prefix=subdir2 --branch mainsub5 &&
+		test_equal "$(git log --pretty=format:%P -1 mainsub5)" ""
 '
 
-# make sure no patch changes more than one file.  The original set of commits
-# changed only one file each.  A multi-file change would imply that we pruned
-# commits too aggressively.
-joincommits()
-{
-	commit=
-	all=
-	while read x y; do
-		#echo "{$x}" >&2
-		if [ -z "$x" ]; then
-			continue
-		elif [ "$x" = "commit:" ]; then
-			if [ -n "$commit" ]; then
-				echo "$commit $all"
-				all=
-			fi
-			commit="$y"
-		else
-			all="$all $y"
-		fi
-	done
-	echo "$commit $all"
-}
-
 test_expect_success 'verify one file change per commit' '
 		x= &&
-		list=''"$(git log --pretty=format:'"'commit: %H'"' | joincommits)"'' &&
-#		 test_debug "echo HERE" &&
-#		 test_debug "echo ''"$list"''" &&
-		(git log --pretty=format:'"'commit: %H'"' | joincommits |
-		(		while read commit a b; do
-				test_debug "echo Verifying commit "''"$commit"''
-				test_debug "echo a: "''"$a"''
-				test_debug "echo b: "''"$b"''
-				check_equal "$b" ""
+		git log --pretty=format:"commit: %H" | join_commits |
+		(
+			while read commit a b; do
+				test_debug "echo Verifying commit $commit"
+				test_debug "echo a: $a"
+				test_debug "echo b: $b"
+				test_equal "$b" ""
 				x=1
 			done
-			check_equal "$x" 1
-		))
+			test_equal "$x" 1
+		)
 '
 
 test_done
-- 
1.8.1

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH/RFC v2 6/8] contrib/subtree: Make each test self-contained
  2013-01-14  3:52 ` [PATCH/RFC v2 0/8] contrib/subtree: Reroll to follow Git's whitespace policy Techlive Zheng
                     ` (4 preceding siblings ...)
  2013-01-14  3:52   ` [PATCH/RFC v2 5/8] contrib/subtree: Code cleaning and refactoring Techlive Zheng
@ 2013-01-14  3:52   ` Techlive Zheng
  2013-01-14  3:52   ` [PATCH/RFC v2 7/8] contrib/subtree: Use %B for the split commit message Techlive Zheng
  2013-01-14  3:52   ` [PATCH/RFC v2 8/8] contrib/subtree: Handle '--prefix' argument with a slash appended Techlive Zheng
  7 siblings, 0 replies; 18+ messages in thread
From: Techlive Zheng @ 2013-01-14  3:52 UTC (permalink / raw
  To: git; +Cc: apenwarr, greened, Techlive Zheng

Signed-off-by: Techlive Zheng <techlivezheng@gmail.com>
---
 contrib/subtree/t/t7900-subtree.sh | 865 ++++++++++++++++++++++++++-----------
 1 file changed, 614 insertions(+), 251 deletions(-)

diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh
index 69bd41c..ef83f31 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -12,12 +12,6 @@ export TEST_DIRECTORY=$(pwd)/../../../t
 
 . ../../../t/test-lib.sh
 
-create()
-{
-	echo "$1" >"$1"
-	git add "$1"
-}
-
 fixnl()
 {
 	t=""
@@ -37,11 +31,6 @@ multiline()
 	done
 }
 
-undo()
-{
-	git reset --hard HEAD~
-}
-
 test_equal()
 {
 	test_debug 'echo'
@@ -78,373 +67,746 @@ join_commits()
 	echo "$commit $all"
 }
 
+test_create_commit() (
+	repo=$1
+	commit=$2
+	cd "$repo"
+	mkdir -p "$(dirname "$commit")"
+	echo "$commit" > "$commit"
+	git add "$commit"
+	git commit -m "$commit"
+)
+
 last_commit_message()
 {
 	git log --pretty=format:%s -1
 }
 
-test_expect_success 'init subproj' '
-		test_create_repo subproj
-'
-
-# To the subproject!
-cd subproj
-
-test_expect_success 'add sub1' '
-		create sub1 &&
-		git commit -m "sub1" &&
-		git branch sub1 &&
-		git branch -m master subproj
-'
-
-test_expect_success 'add sub2' '
-		create sub2 &&
-		git commit -m "sub2" &&
-		git branch sub2
-'
-
-test_expect_success 'add sub3' '
-		create sub3 &&
-		git commit -m "sub3" &&
-		git branch sub3
-'
-
-# Back to mainline
-cd ..
-
-test_expect_success 'add main4' '
-		create main4 &&
-		git commit -m "main4" &&
-		git branch -m master mainline &&
-		git branch init
-'
-
-test_expect_success 'fetch subproj history' '
-		git fetch ./subproj sub1 &&
-		git branch sub1 FETCH_HEAD
-'
+#
+# Tests for 'git subtree add'
+#
 
 test_expect_success 'no pull from non-existant subtree' '
-		test_must_fail git subtree pull --prefix=subdir ./subproj sub1
+	test_create_repo "$test_count" &&
+	test_create_repo "$test_count/subproj" &&
+	test_create_commit "$test_count" main1 &&
+	test_create_commit "$test_count/subproj" sub1 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		test_must_fail git subtree pull --prefix=subdir ./subproj master
+	)
 '
 
 test_expect_success 'no merge from non-existant subtree' '
+	test_create_repo "$test_count" &&
+	test_create_repo "$test_count/subproj" &&
+	test_create_commit "$test_count" main1 &&
+	test_create_commit "$test_count/subproj" sub1 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
 		test_must_fail git subtree merge --prefix=subdir FETCH_HEAD
+	)
 '
 
 test_expect_success 'add subproj as subtree into subdir/ with --prefix' '
+	test_create_repo "$test_count" &&
+	test_create_repo "$test_count/subproj" &&
+	test_create_commit "$test_count" main1 &&
+	test_create_commit "$test_count/subproj" sub1 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
 		git subtree add --prefix=subdir FETCH_HEAD &&
-		test_equal "$(last_commit_message)" "Add '\''subdir/'\'' from commit '\''$(git rev-parse FETCH_HEAD)'\''" &&
-		undo
+		test_equal "$(last_commit_message)" "Add '\''subdir/'\'' from commit '\''$(git rev-parse FETCH_HEAD)'\''"
+	)
 '
 
 test_expect_success 'add subproj as subtree into subdir/ with --prefix and --message' '
+	test_create_repo "$test_count" &&
+	test_create_repo "$test_count/subproj" &&
+	test_create_commit "$test_count" main1 &&
+	test_create_commit "$test_count/subproj" sub1 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
 		git subtree add --prefix=subdir --message="Added subproject" FETCH_HEAD &&
-		test_equal "$(last_commit_message)" "Added subproject" &&
-		undo
+		test_equal "$(last_commit_message)" "Added subproject"
+	)
 '
 
 test_expect_success 'add subproj as subtree into subdir/ with --prefix as -P and --message as -m' '
+	test_create_repo "$test_count" &&
+	test_create_repo "$test_count/subproj" &&
+	test_create_commit "$test_count" main1 &&
+	test_create_commit "$test_count/subproj" sub1 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
 		git subtree add -P subdir -m "Added subproject" FETCH_HEAD &&
-		test_equal "$(last_commit_message)" "Added subproject" &&
-		undo
+		test_equal "$(last_commit_message)" "Added subproject"
+	)
 '
 
 test_expect_success 'add subproj as subtree into subdir/ with --squash and --prefix and --message' '
+	test_create_repo "$test_count" &&
+	test_create_repo "$test_count/subproj" &&
+	test_create_commit "$test_count" main1 &&
+	test_create_commit "$test_count/subproj" sub1 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
 		git subtree add --prefix=subdir --message="Added subproject with squash" --squash FETCH_HEAD &&
-		test_equal "$(last_commit_message)" "Added subproject with squash" &&
-		undo
+		test_equal "$(last_commit_message)" "Added subproject with squash"
+	)
 '
 
 test_expect_success 'merge the added subproj again, should do nothing' '
+	test_create_repo "$test_count" &&
+	test_create_repo "$test_count/subproj" &&
+	test_create_commit "$test_count" main1 &&
+	test_create_commit "$test_count/subproj" sub1 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
 		git subtree add --prefix=subdir FETCH_HEAD &&
 		# this shouldn not actually do anything, since FETCH_HEAD
 		# is already a parent
 		git merge -s ours -m "merge -s -ours" FETCH_HEAD
+	)
 '
 
-test_expect_success 'add main-sub5' '
-		create subdir/main-sub5 &&
-		git commit -m "main-sub5"
-'
-
-test_expect_success 'add main6' '
-		create main6 &&
-		git commit -m "main6 boring"
-'
-
-test_expect_success 'add main-sub7' '
-		create subdir/main-sub7 &&
-		git commit -m "main-sub7"
-'
-
-test_expect_success 'fetch new subproj history' '
-		git fetch ./subproj sub2 &&
-		git branch sub2 FETCH_HEAD
-'
+#
+# Tests for 'git subtree merge'
+#
 
 test_expect_success 'merge new subproj history into subdir/ with --prefix' '
+	test_create_repo "$test_count" &&
+	test_create_repo "$test_count/subproj" &&
+	test_create_commit "$test_count" main1 &&
+	test_create_commit "$test_count/subproj" sub1 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git subtree add --prefix=subdir FETCH_HEAD
+	) &&
+	test_create_commit "$test_count/subproj" sub2 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
 		git subtree merge --prefix=subdir FETCH_HEAD &&
-		test_equal "$(last_commit_message)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\'' into mainline" &&
-		undo
+		test_equal "$(last_commit_message)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''"
+	)
 '
 
 test_expect_success 'merge new subproj history into subdir/ with --prefix and --message' '
+	test_create_repo "$test_count" &&
+	test_create_repo "$test_count/subproj" &&
+	test_create_commit "$test_count" main1 &&
+	test_create_commit "$test_count/subproj" sub1 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git subtree add --prefix=subdir FETCH_HEAD
+	) &&
+	test_create_commit "$test_count/subproj" sub2 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
 		git subtree merge --prefix=subdir --message="Merged changes from subproject" FETCH_HEAD &&
-		test_equal "$(last_commit_message)" "Merged changes from subproject" &&
-		undo
+		test_equal "$(last_commit_message)" "Merged changes from subproject"
+	)
 '
 
 test_expect_success 'merge new subproj history into subdir/ with --squash and --prefix and --message' '
+	test_create_repo "$test_count/subproj" &&
+	test_create_repo "$test_count" &&
+	test_create_commit "$test_count" main1 &&
+	test_create_commit "$test_count/subproj" sub1 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git subtree add --prefix=subdir FETCH_HEAD
+	) &&
+	test_create_commit "$test_count/subproj" sub2 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
 		git subtree merge --prefix=subdir --message="Merged changes from subproject using squash" --squash FETCH_HEAD &&
-		test_equal "$(last_commit_message)" "Merged changes from subproject using squash" &&
-		undo
+		test_equal "$(last_commit_message)" "Merged changes from subproject using squash"
+	)
 '
 
-test_expect_success 'merge new subproj history into subdir/' '
-		git subtree merge --prefix=subdir FETCH_HEAD &&
-		git branch pre-split
-'
+#
+# Tests for 'git subtree split'
+#
 
 test_expect_success 'split requires option --prefix' '
+	test_create_repo "$test_count" &&
+	test_create_repo "$test_count/subproj" &&
+	test_create_commit "$test_count" main1 &&
+	test_create_commit "$test_count/subproj" sub1 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git subtree add --prefix=subdir FETCH_HEAD &&
 		echo "You must provide the --prefix option." > expected &&
 		test_must_fail git subtree split > actual 2>&1 &&
 		test_debug "echo -n expected: " &&
 		test_debug "cat expected" &&
 		test_debug "echo -n actual: " &&
 		test_debug "cat actual" &&
-		test_cmp expected actual &&
-		rm -f expected actual
+		test_cmp expected actual
+	)
 '
 
 test_expect_success 'split requires path given by option --prefix must exist' '
+	test_create_repo "$test_count" &&
+	test_create_repo "$test_count/subproj" &&
+	test_create_commit "$test_count" main1 &&
+	test_create_commit "$test_count/subproj" sub1 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git subtree add --prefix=subdir FETCH_HEAD &&
 		echo "'\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" > expected &&
 		test_must_fail git subtree split --prefix=non-existent-directory > actual 2>&1 &&
 		test_debug "echo -n expected: " &&
 		test_debug "cat expected" &&
 		test_debug "echo -n actual: " &&
 		test_debug "cat actual" &&
-		test_cmp expected actual &&
-		rm -f expected actual
+		test_cmp expected actual
+	)
 '
 
 test_expect_success 'split subdir/ with --rejoin' '
-		spl1=$(git subtree split --prefix=subdir --annotate="*") &&
-		git branch spl1 "$spl1" &&
+	test_create_repo "$test_count" &&
+	test_create_repo "$test_count/subproj" &&
+	test_create_commit "$test_count" main1 &&
+	test_create_commit "$test_count/subproj" sub1 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git subtree add --prefix=subdir FETCH_HEAD
+	) &&
+	test_create_commit "$test_count" subdir/main-sub1 &&
+	test_create_commit "$test_count" main2 &&
+	test_create_commit "$test_count/subproj" sub2 &&
+	test_create_commit "$test_count" subdir/main-sub2 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git subtree merge --prefix=subdir FETCH_HEAD &&
+		split_hash=$(git subtree split --prefix=subdir --annotate="*") &&
 		git subtree split --prefix=subdir --annotate="*" --rejoin &&
-		test_equal "$(last_commit_message)" "Split '\''subdir/'\'' into commit '\''$spl1'\''" &&
-		undo
+		test_equal "$(last_commit_message)" "Split '\''subdir/'\'' into commit '\''$split_hash'\''"
+	)
 '
 
 test_expect_success 'split subdir/ with --rejoin and --message' '
+	test_create_repo "$test_count" &&
+	test_create_repo "$test_count/subproj" &&
+	test_create_commit "$test_count" main1 &&
+	test_create_commit "$test_count/subproj" sub1 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git subtree add --prefix=subdir FETCH_HEAD
+	) &&
+	test_create_commit "$test_count" subdir/main-sub1 &&
+	test_create_commit "$test_count" main2 &&
+	test_create_commit "$test_count/subproj" sub2 &&
+	test_create_commit "$test_count" subdir/main-sub2 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git subtree merge --prefix=subdir FETCH_HEAD &&
 		git subtree split --prefix=subdir --message="Split & rejoin" --annotate="*" --rejoin &&
-		test_equal "$(last_commit_message)" "Split & rejoin" &&
-		undo
+		test_equal "$(last_commit_message)" "Split & rejoin"
+	)
 '
 
 test_expect_success 'split subdir/ with --branch' '
-		spl1=$(git subtree split --prefix=subdir --message="Split & rejoin" --annotate="*" --rejoin) &&
-		undo &&
-		git subtree split --prefix=subdir --annotate="*" --branch splitbr1 &&
-		test_equal "$(git rev-parse splitbr1)" "$spl1"
+	test_create_repo "$test_count" &&
+	test_create_repo "$test_count/subproj" &&
+	test_create_commit "$test_count" main1 &&
+	test_create_commit "$test_count/subproj" sub1 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git subtree add --prefix=subdir FETCH_HEAD
+	) &&
+	test_create_commit "$test_count" subdir/main-sub1 &&
+	test_create_commit "$test_count" main2 &&
+	test_create_commit "$test_count/subproj" sub2 &&
+	test_create_commit "$test_count" subdir/main-sub2 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git subtree merge --prefix=subdir FETCH_HEAD &&
+		split_hash=$(git subtree split --prefix=subdir --annotate="*") &&
+		git subtree split --prefix=subdir --annotate="*" --branch subproj-br &&
+		test_equal "$(git rev-parse subproj-br)" "$split_hash"
+	)
 '
 
 test_expect_success 'split subdir/ with --branch for an existing branch' '
-		spl1=$(git subtree split --prefix=subdir --annotate="*" --message="Split & rejoin" --rejoin) &&
-		undo &&
-		git branch splitbr2 sub1 &&
-		git subtree split --prefix=subdir --annotate="*" --branch splitbr2 &&
-		test_equal "$(git rev-parse splitbr2)" "$spl1"
+	test_create_repo "$test_count" &&
+	test_create_repo "$test_count/subproj" &&
+	test_create_commit "$test_count" main1 &&
+	test_create_commit "$test_count/subproj" sub1 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git branch subproj-br FETCH_HEAD &&
+		git subtree add --prefix=subdir FETCH_HEAD
+	) &&
+	test_create_commit "$test_count" subdir/main-sub1 &&
+	test_create_commit "$test_count" main2 &&
+	test_create_commit "$test_count/subproj" sub2 &&
+	test_create_commit "$test_count" subdir/main-sub2 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git subtree merge --prefix=subdir FETCH_HEAD &&
+		split_hash=$(git subtree split --prefix=subdir --annotate="*") &&
+		git subtree split --prefix=subdir --annotate="*" --branch subproj-br &&
+		test_equal "$(git rev-parse subproj-br)" "$split_hash"
+	)
 '
 
 test_expect_success 'split subdir/ with --branch for an incompatible branch' '
+	test_create_repo "$test_count" &&
+	test_create_repo "$test_count/subproj" &&
+	test_create_commit "$test_count" main1 &&
+	test_create_commit "$test_count/subproj" sub1 &&
+	(
+		cd "$test_count" &&
+		git branch init HEAD &&
+		git fetch ./subproj master &&
+		git subtree add --prefix=subdir FETCH_HEAD
+	) &&
+	test_create_commit "$test_count" subdir/main-sub1 &&
+	test_create_commit "$test_count" main2 &&
+	test_create_commit "$test_count/subproj" sub2 &&
+	test_create_commit "$test_count" subdir/main-sub2 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git subtree merge --prefix=subdir FETCH_HEAD &&
 		test_must_fail git subtree split --prefix=subdir --branch init
+	)
 '
 
-test_expect_success 'split and rejoin' '
-		git subtree split --prefix=subdir --annotate="*" --rejoin
-'
-
-test_expect_success 'add main-sub8' '
-		create subdir/main-sub8 &&
-		git commit -m "main-sub8"
-'
-
-# To the subproject!
-cd ./subproj
-
-test_expect_success 'merge split into subproj' '
-		git fetch .. spl1 &&
-		git branch spl1 FETCH_HEAD &&
-		git merge FETCH_HEAD
-'
-
-test_expect_success 'add sub9' '
-		create sub9 &&
-		git commit -m "sub9"
-'
-
-# Back to mainline
-cd ..
-
-test_expect_success 'split for sub8' '
-		spl2=$(git subtree split --prefix=subdir/ --annotate="*" --rejoin) &&
-		git branch spl2 "$spl2"
-'
-
-test_expect_success 'add main-sub10' '
-		create subdir/main-sub10 &&
-		git commit -m "main-sub10"
-'
-
-test_expect_success 'split for sub10' '
-		spl3=$(git subtree split --prefix=subdir --annotate="*" --rejoin) &&
-		git branch spl3 "$spl3"
-'
-
-# To the subproject!
-cd ./subproj
-
-test_expect_success 'merge split into subproj' '
-		git fetch .. spl3 &&
-		git branch spl3 FETCH_HEAD &&
-		git merge FETCH_HEAD &&
-		git branch subproj-merge-spl3
-'
-
-chkm="main4 main6"
-chkms="main-sub10 main-sub5 main-sub7 main-sub8"
-chkms_sub=$(echo $chkms | multiline | sed 's,^,subdir/,' | fixnl)
-chks="sub1 sub2 sub3 sub9"
-chks_sub=$(echo $chks | multiline | sed 's,^,subdir/,' | fixnl)
+#
+# Validity checking
+#
 
 test_expect_success 'make sure exactly the right set of files ends up in the subproj' '
+	test_create_repo "$test_count" &&
+	test_create_repo "$test_count/subproj" &&
+	test_create_commit "$test_count" main1 &&
+	test_create_commit "$test_count/subproj" sub1 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git subtree add --prefix=subdir FETCH_HEAD
+	) &&
+	test_create_commit "$test_count" subdir/main-sub1 &&
+	test_create_commit "$test_count" main2 &&
+	test_create_commit "$test_count/subproj" sub2 &&
+	test_create_commit "$test_count" subdir/main-sub2 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git subtree merge --prefix=subdir FETCH_HEAD &&
+		git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+	) &&
+	test_create_commit "$test_count/subproj" sub3 &&
+	test_create_commit "$test_count" subdir/main-sub3 &&
+	(
+		cd "$test_count/subproj" &&
+		git fetch .. subproj-br && git merge FETCH_HEAD
+	) &&
+	test_create_commit "$test_count/subproj" sub4 &&
+	(
+		cd "$test_count" &&
+		git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+	) &&
+	test_create_commit "$test_count" subdir/main-sub4 &&
+	(
+		cd "$test_count" &&
+		git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+	) &&
+	(
+		cd "$test_count/subproj" &&
+		git fetch .. subproj-br && git merge FETCH_HEAD &&
+
+		chks="sub1 sub2 sub3 sub4" &&
+		chks_sub=$(echo $chks | multiline | sed '\''s,^,subdir/,'\'' | fixnl) &&
+		chkms="main-sub1 main-sub2 main-sub3 main-sub4" &&
+		chkms_sub=$(echo $chkms | multiline | sed '\''s,^,subdir/,'\'' | fixnl) &&
+
 		subfiles=$(git ls-files | fixnl) &&
 		test_equal "$subfiles" "$chkms $chks"
+	)
 '
 
 test_expect_success 'make sure the subproj *only* contains commits that affect the subdir' '
+	test_create_repo "$test_count" &&
+	test_create_repo "$test_count/subproj" &&
+	test_create_commit "$test_count" main1 &&
+	test_create_commit "$test_count/subproj" sub1 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git subtree add --prefix=subdir FETCH_HEAD
+	) &&
+	test_create_commit "$test_count" subdir/main-sub1 &&
+	test_create_commit "$test_count" main2 &&
+	test_create_commit "$test_count/subproj" sub2 &&
+	test_create_commit "$test_count" subdir/main-sub2 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git subtree merge --prefix=subdir FETCH_HEAD &&
+		git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+	) &&
+	test_create_commit "$test_count/subproj" sub3 &&
+	test_create_commit "$test_count" subdir/main-sub3 &&
+	(
+		cd "$test_count/subproj" &&
+		git fetch .. subproj-br && git merge FETCH_HEAD
+	) &&
+	test_create_commit "$test_count/subproj" sub4 &&
+	(
+		cd "$test_count" &&
+		git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+	) &&
+	test_create_commit "$test_count" subdir/main-sub4 &&
+	(
+		cd "$test_count" &&
+		git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+	) &&
+	(
+		cd "$test_count/subproj" &&
+		git fetch .. subproj-br && git merge FETCH_HEAD &&
+
+		chks="sub1 sub2 sub3 sub4" &&
+		chks_sub=$(echo $chks | multiline | sed '\''s,^,subdir/,'\'' | fixnl) &&
+		chkms="main-sub1 main-sub2 main-sub3 main-sub4" &&
+		chkms_sub=$(echo $chkms | multiline | sed '\''s,^,subdir/,'\'' | fixnl) &&
+
 		allchanges=$(git log --name-only --pretty=format:"" | sort | fixnl) &&
 		test_equal "$allchanges" "$chkms $chks"
-'
-
-# Back to mainline
-cd ..
-
-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
+	)
 '
 
 test_expect_success 'make sure exactly the right set of files ends up in the mainline' '
+	test_create_repo "$test_count" &&
+	test_create_repo "$test_count/subproj" &&
+	test_create_commit "$test_count" main1 &&
+	test_create_commit "$test_count/subproj" sub1 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git subtree add --prefix=subdir FETCH_HEAD
+	) &&
+	test_create_commit "$test_count" subdir/main-sub1 &&
+	test_create_commit "$test_count" main2 &&
+	test_create_commit "$test_count/subproj" sub2 &&
+	test_create_commit "$test_count" subdir/main-sub2 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git subtree merge --prefix=subdir FETCH_HEAD &&
+		git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+	) &&
+	test_create_commit "$test_count/subproj" sub3 &&
+	test_create_commit "$test_count" subdir/main-sub3 &&
+	(
+		cd "$test_count/subproj" &&
+		git fetch .. subproj-br && git merge FETCH_HEAD
+	) &&
+	test_create_commit "$test_count/subproj" sub4 &&
+	(
+		cd "$test_count" &&
+		git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+	) &&
+	test_create_commit "$test_count" subdir/main-sub4 &&
+	(
+		cd "$test_count" &&
+		git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+	) &&
+	(
+		cd "$test_count/subproj" &&
+		git fetch .. subproj-br && git merge FETCH_HEAD
+	) &&
+	(
+		cd "$test_count" &&
+		git subtree pull --prefix=subdir ./subproj master &&
+
+		chkm="main1 main2" &&
+		chks="sub1 sub2 sub3 sub4" &&
+		chks_sub=$(echo $chks | multiline | sed '\''s,^,subdir/,'\'' | fixnl) &&
+		chkms="main-sub1 main-sub2 main-sub3 main-sub4" &&
+		chkms_sub=$(echo $chkms | multiline | sed '\''s,^,subdir/,'\'' | fixnl) &&
+
 		mainfiles=$(git ls-files | fixnl) &&
 		test_equal "$mainfiles" "$chkm $chkms_sub $chks_sub"
+	)
 '
 
 test_expect_success 'make sure each filename changed exactly once in the entire history' '
+	test_create_repo "$test_count" &&
+	test_create_repo "$test_count/subproj" &&
+	test_create_commit "$test_count" main1 &&
+	test_create_commit "$test_count/subproj" sub1 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git subtree add --prefix=subdir FETCH_HEAD
+	) &&
+	test_create_commit "$test_count" subdir/main-sub1 &&
+	test_create_commit "$test_count" main2 &&
+	test_create_commit "$test_count/subproj" sub2 &&
+	test_create_commit "$test_count" subdir/main-sub2 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git subtree merge --prefix=subdir FETCH_HEAD &&
+		git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+	) &&
+	test_create_commit "$test_count/subproj" sub3 &&
+	test_create_commit "$test_count" subdir/main-sub3 &&
+	(
+		cd "$test_count/subproj" &&
+		git fetch .. subproj-br && git merge FETCH_HEAD
+	) &&
+	test_create_commit "$test_count/subproj" sub4 &&
+	(
+		cd "$test_count" &&
+		git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+	) &&
+	test_create_commit "$test_count" subdir/main-sub4 &&
+	(
+		cd "$test_count" &&
+		git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+	) &&
+	(
+		cd "$test_count/subproj" &&
+		git fetch .. subproj-br && git merge FETCH_HEAD
+	) &&
+	(
+		cd "$test_count" &&
+		git subtree pull --prefix=subdir ./subproj master &&
+
+		chkm="main1 main2" &&
+		chks="sub1 sub2 sub3 sub4" &&
+		chks_sub=$(echo $chks | multiline | sed '\''s,^,subdir/,'\'' | fixnl) &&
+		chkms="main-sub1 main-sub2 main-sub3 main-sub4" &&
+		chkms_sub=$(echo $chkms | multiline | sed '\''s,^,subdir/,'\'' | fixnl) &&
+
 		# main-sub?? and /subdir/main-sub?? both change, because those are the
 		# changes that were split into their own history.  And subdir/sub?? never
 		# change, since they were *only* changed in the subtree branch.
 		allchanges=$(git log --name-only --pretty=format:"" | sort | fixnl) &&
 		test_equal "$allchanges" "$(echo $chkms $chkm $chks $chkms_sub | multiline | sort | fixnl)"
+	)
 '
 
 test_expect_success 'make sure the --rejoin commits never make it into subproj' '
+	test_create_repo "$test_count" &&
+	test_create_repo "$test_count/subproj" &&
+	test_create_commit "$test_count" main1 &&
+	test_create_commit "$test_count/subproj" sub1 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git subtree add --prefix=subdir FETCH_HEAD
+	) &&
+	test_create_commit "$test_count" subdir/main-sub1 &&
+	test_create_commit "$test_count" main2 &&
+	test_create_commit "$test_count/subproj" sub2 &&
+	test_create_commit "$test_count" subdir/main-sub2 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git subtree merge --prefix=subdir FETCH_HEAD &&
+		git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+	) &&
+	test_create_commit "$test_count/subproj" sub3 &&
+	test_create_commit "$test_count" subdir/main-sub3 &&
+	(
+		cd "$test_count/subproj" &&
+		git fetch .. subproj-br && git merge FETCH_HEAD
+	) &&
+	test_create_commit "$test_count/subproj" sub4 &&
+	(
+		cd "$test_count" &&
+		git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+	) &&
+	test_create_commit "$test_count" subdir/main-sub4 &&
+	(
+		cd "$test_count" &&
+		git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+	) &&
+	(
+		cd "$test_count/subproj" &&
+		git fetch .. subproj-br && git merge FETCH_HEAD
+	) &&
+	(
+		cd "$test_count" &&
+		git subtree pull --prefix=subdir ./subproj master &&
+
 		test_equal "$(git log --pretty=format:"%s" HEAD^2 | grep -i split)" ""
+	)
 '
 
 test_expect_success 'make sure no "git subtree" tagged commits make it into subproj' '
+	test_create_repo "$test_count" &&
+	test_create_repo "$test_count/subproj" &&
+	test_create_commit "$test_count" main1 &&
+	test_create_commit "$test_count/subproj" sub1 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git subtree add --prefix=subdir FETCH_HEAD
+	) &&
+	test_create_commit "$test_count" subdir/main-sub1 &&
+	test_create_commit "$test_count" main2 &&
+	test_create_commit "$test_count/subproj" sub2 &&
+	test_create_commit "$test_count" subdir/main-sub2 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git subtree merge --prefix=subdir FETCH_HEAD &&
+		git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+	) &&
+	test_create_commit "$test_count/subproj" sub3 &&
+	test_create_commit "$test_count" subdir/main-sub3 &&
+	(
+		cd "$test_count/subproj" &&
+		git fetch .. subproj-br && git merge FETCH_HEAD
+	) &&
+	test_create_commit "$test_count/subproj" sub4 &&
+	(
+		cd "$test_count" &&
+		git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+	) &&
+	test_create_commit "$test_count" subdir/main-sub4 &&
+	(
+		cd "$test_count" &&
+		git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+	) &&
+	(
+		cd "$test_count/subproj" &&
+		git fetch .. subproj-br && git merge FETCH_HEAD
+	) &&
+	(
+		cd "$test_count" &&
+		git subtree pull --prefix=subdir ./subproj master &&
+
 		# They are meaningless to subproj since one side of the merge refers to the mainline
 		test_equal "$(git log --pretty=format:"%s%n%b" HEAD^2 | grep "git-subtree.*:")" ""
+	)
 '
 
-# prepare second pair of repositories
-mkdir test2
-cd test2
-
-test_expect_success 'init main' '
-		test_create_repo main
-'
-
-cd main
-
-test_expect_success 'add main1' '
-		create main1 &&
-		git commit -m "main1"
-'
-
-cd ..
-
-test_expect_success 'init sub' '
-		test_create_repo sub
-'
-
-cd sub
-
-test_expect_success 'add sub2' '
-		create sub2 &&
-		git commit -m "sub2"
-'
-
-cd ../main
-
-# check if split can find proper base without --onto
-
-test_expect_success 'add sub as subdir in main' '
-		git fetch ../sub master &&
-		git branch sub2 FETCH_HEAD &&
-		git subtree add --prefix=subdir sub2
-'
-
-cd ../sub
-
-test_expect_success 'add sub3' '
-		create sub3 &&
-		git commit -m "sub3"
-'
-
-cd ../main
-
-test_expect_success 'merge from sub' '
-		git fetch ../sub master &&
-		git branch sub3 FETCH_HEAD &&
-		git subtree merge --prefix=subdir sub3
-'
-
-test_expect_success 'add main-sub4' '
-		create subdir/main-sub4 &&
-		git commit -m "main-sub4"
-'
-
-test_expect_success 'split for main-sub4 without --onto' '
-		git subtree split --prefix=subdir --branch mainsub4
-'
-
-# at this point, the new commit parent should be sub3 if it is not,
-# something went wrong (the "newparent" of "master~" commit should
-# have been sub3, but it was not, because its cache was not set to
-# itself)
-
-test_expect_success 'check that the commit parent is sub3' '
-		test_equal "$(git log --pretty=format:%P -1 mainsub4)" "$(git rev-parse sub3)"
-'
+#
+# A new set of tests
+#
 
-test_expect_success 'add main-sub5' '
-		mkdir subdir2 &&
-		create subdir2/main-sub5 &&
-		git commit -m "main-sub5"
-'
+test_expect_success 'make sure "git subtree split" find the correct parent' '
+	test_create_repo "$test_count" &&
+	test_create_repo "$test_count/subproj" &&
+	test_create_commit "$test_count" main1 &&
+	test_create_commit "$test_count/subproj" sub1 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git subtree add --prefix=subdir FETCH_HEAD
+	) &&
+	test_create_commit "$test_count/subproj" sub2 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git branch subproj-ref FETCH_HEAD &&
+		git subtree merge --prefix=subdir FETCH_HEAD
+	) &&
+	test_create_commit "$test_count" subdir/main-sub1 &&
+	(
+		cd "$test_count" &&
+		git subtree split --prefix=subdir --branch subproj-br &&
+
+		# at this point, the new commit parent should be subproj-ref, if it is
+		# not, something went wrong (the "newparent" of "master~" commit should
+		# have been sub2, but it was not, because its cache was not set to
+		# itself)
+		test_equal "$(git log --pretty=format:%P -1 subproj-br)" "$(git rev-parse subproj-ref)"
+	)
+'
+
+test_expect_success 'split a new subtree without --onto option' '
+	test_create_repo "$test_count" &&
+	test_create_repo "$test_count/subproj" &&
+	test_create_commit "$test_count" main1 &&
+	test_create_commit "$test_count/subproj" sub1 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git subtree add --prefix=subdir FETCH_HEAD
+	) &&
+	test_create_commit "$test_count/subproj" sub2 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git subtree merge --prefix=subdir FETCH_HEAD
+	) &&
+	test_create_commit "$test_count" subdir/main-sub1 &&
+	(
+		cd "$test_count" &&
+		git subtree split --prefix=subdir --branch subproj-br
+	) &&
+	test_create_commit "$test_count" subdir2/main-sub2 &&
+	(
+		cd "$test_count" &&
 
-test_expect_success 'split for main-sub5 without --onto' '
 		# also test that we still can split out an entirely new subtree
 		# if the parent of the first commit in the tree is not empty,
 		# then the new subtree has accidently been attached to something
-		git subtree split --prefix=subdir2 --branch mainsub5 &&
-		test_equal "$(git log --pretty=format:%P -1 mainsub5)" ""
+		git subtree split --prefix=subdir2 --branch subproj2-br &&
+		test_equal "$(git log --pretty=format:%P -1 subproj2-br)" ""
+	)
 '
 
 test_expect_success 'verify one file change per commit' '
+	test_create_repo "$test_count" &&
+	test_create_repo "$test_count/subproj" &&
+	test_create_commit "$test_count" main1 &&
+	test_create_commit "$test_count/subproj" sub1 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git branch sub1 FETCH_HEAD &&
+		git subtree add --prefix=subdir sub1
+	) &&
+	test_create_commit "$test_count/subproj" sub2 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git subtree merge --prefix=subdir FETCH_HEAD
+	) &&
+	test_create_commit "$test_count" subdir/main-sub1 &&
+	(
+		cd "$test_count" &&
+		git subtree split --prefix=subdir --branch subproj-br
+	) &&
+	test_create_commit "$test_count" subdir2/main-sub2 &&
+	(
+		cd "$test_count" &&
+		git subtree split --prefix=subdir2 --branch subproj2-br &&
+
 		x= &&
 		git log --pretty=format:"commit: %H" | join_commits |
 		(
@@ -457,6 +819,7 @@ test_expect_success 'verify one file change per commit' '
 			done
 			test_equal "$x" 1
 		)
+	)
 '
 
 test_done
-- 
1.8.1

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH/RFC v2 7/8] contrib/subtree: Use %B for the split commit message
  2013-01-14  3:52 ` [PATCH/RFC v2 0/8] contrib/subtree: Reroll to follow Git's whitespace policy Techlive Zheng
                     ` (5 preceding siblings ...)
  2013-01-14  3:52   ` [PATCH/RFC v2 6/8] contrib/subtree: Make each test self-contained Techlive Zheng
@ 2013-01-14  3:52   ` Techlive Zheng
  2013-01-14  3:52   ` [PATCH/RFC v2 8/8] contrib/subtree: Handle '--prefix' argument with a slash appended Techlive Zheng
  7 siblings, 0 replies; 18+ messages in thread
From: Techlive Zheng @ 2013-01-14  3:52 UTC (permalink / raw
  To: git; +Cc: apenwarr, greened, Techlive Zheng

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.

After this commit, the newly split branch might differ from the previous
one. If this is the case, --fallback option could help.

Signed-off-by: Techlive Zheng <techlivezheng@gmail.com>
Signed-off-by: David A. Greene <greened@obbligato.org>
---
 contrib/subtree/git-subtree.sh     | 13 ++++++++++-
 contrib/subtree/git-subtree.txt    | 13 +++++++++++
 contrib/subtree/t/t7900-subtree.sh | 47 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 72 insertions(+), 1 deletion(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 88903c0..d529a76 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -25,6 +25,7 @@ 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
+fallback      fallback to the obsolete commit generating mechanism
  options for 'add', 'merge', 'pull' and 'push'
 squash        merge subtree changes as a single commit
 "
@@ -45,6 +46,7 @@ ignore_joins=
 annotate=
 squash=
 message=
+fallback=
 
 debug()
 {
@@ -92,6 +94,8 @@ while [ $# -gt 0 ]; do
 		--no-ignore-joins) ignore_joins= ;;
 		--squash) squash=1 ;;
 		--no-squash) squash= ;;
+		--fallback) fallback=1 ;;
+		--no-fallback) fallback= ;;
 		--) break ;;
 		*) die "Unexpected option: $opt" ;;
 	esac
@@ -296,7 +300,14 @@ 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}"
-	git log -1 --pretty=format:'%an%n%ae%n%ad%n%cn%n%ce%n%cd%n%s%n%n%b' "$1" |
+
+	if [ -z "$fallback" ]; then
+		log_format='%an%n%ae%n%ad%n%cn%n%ce%n%cd%n%B'
+	else
+		log_format='%an%n%ae%n%ad%n%cn%n%ce%n%cd%n%s%n%n%b'
+	fi
+
+	git log -1 --pretty=format:"$log_format" "$1" |
 	(
 		read GIT_AUTHOR_NAME
 		read GIT_AUTHOR_EMAIL
diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt
index 72be8e4..55d0575 100644
--- a/contrib/subtree/git-subtree.txt
+++ b/contrib/subtree/git-subtree.txt
@@ -254,6 +254,19 @@ OPTIONS FOR split
 	'--rejoin' when you split, because you don't want the
 	subproject's history to be part of your project anyway.
 
+--fallback::
+	Previously, git subtree would introduce an extra new line for
+	the commits whose commit message contains only one line.
+	This behavior has been correct. Unfortunately, for those whose
+	current split branch contains these kind of commits, git subtree
+	will generate a new split branch which differs from the existing
+	split branch in these commits. It is better to use this new
+	split branch, because its commits stay intact within the mainline.
+
+	Otherwise, the previous fault behavior could still be used with
+	this option. This option is only for a compatible purpose, newly
+	split branch should never use this option.
+
 
 EXAMPLE 1. Add command
 ----------------------
diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh
index ef83f31..232ed89 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -399,6 +399,53 @@ test_expect_success 'split subdir/ with --branch for an incompatible branch' '
 	)
 '
 
+test_expect_success 'make sure commits with one line message stay intact after split' '
+	test_create_repo $test_count &&
+	test_create_repo $test_count/subproj &&
+	test_create_commit $test_count main1 &&
+	test_create_commit $test_count/subproj sub1 &&
+	(
+		cd $test_count &&
+		git fetch ./subproj master &&
+		ori_hash=$(git rev-parse FETCH_HEAD) &&
+		git branch subori FETCH_HEAD &&
+		git filter-branch --index-filter '\''git ls-files -s | sed "s-\t-&subdir/-" | GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info && mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"'\'' subori
+		git merge -m "Merge B project as our subdirectory" subori &&
+		git subtree split --prefix subdir --branch splitbr1 &&
+		new_hash_1=$(git rev-parse splitbr1) &&
+		test_equal "$ori_hash" "$new_hash_1" &&
+		git subtree split --prefix subdir --branch splitbr2 --fallback &&
+		new_hash_2=$(git rev-parse splitbr2) &&
+		test_must_fail test_equal "$ori_hash" "$new_hash_2"
+	)
+'
+
+test_expect_success 'make sure --fallback option works correctly for the existing split branch' '
+	test_create_repo "$test_count" &&
+	test_create_repo "$test_count"/subproj &&
+	test_create_commit "$test_count" main1 &&
+	test_create_commit "$test_count"/subproj sub1 &&
+	(
+		cd $test_count &&
+		git fetch ./subproj master &&
+		ori_hash=$(git rev-parse FETCH_HEAD) &&
+		git subtree add --prefix=subdir FETCH_HEAD
+	) &&
+	test_create_commit "$test_count" subdir/main-sub1 &&
+	(
+		cd $test_count &&
+		git subtree split --prefix subdir --branch splitbr1 &&
+		git subtree split --prefix subdir --branch splitbr2 --fallback &&
+		test_must_fail test_equal "$(git rev-parse splitbr1)" "$(git rev-parse splitbr2)"
+	) &&
+	test_create_commit "$test_count" subdir/main-sub2 &&
+	(
+		cd $test_count &&
+		test_must_fail git subtree split --prefix subdir --branch splitbr2 &&
+		git subtree split --prefix subdir --branch splitbr2 --fallback
+	)
+'
+
 #
 # Validity checking
 #
-- 
1.8.1

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH/RFC v2 8/8] contrib/subtree: Handle '--prefix' argument with a slash appended
  2013-01-14  3:52 ` [PATCH/RFC v2 0/8] contrib/subtree: Reroll to follow Git's whitespace policy Techlive Zheng
                     ` (6 preceding siblings ...)
  2013-01-14  3:52   ` [PATCH/RFC v2 7/8] contrib/subtree: Use %B for the split commit message Techlive Zheng
@ 2013-01-14  3:52   ` Techlive Zheng
  7 siblings, 0 replies; 18+ messages in thread
From: Techlive Zheng @ 2013-01-14  3:52 UTC (permalink / raw
  To: git; +Cc: apenwarr, greened, Techlive Zheng

'git subtree merge' will fail if the argument of '--prefix' has a slash
appended.

Signed-off-by: Techlive Zheng <techlivezheng@gmail.com>
---
 contrib/subtree/git-subtree.sh     |  2 +-
 contrib/subtree/t/t7900-subtree.sh | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index d529a76..40100e5 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -83,7 +83,7 @@ while [ $# -gt 0 ]; do
 		--annotate) annotate="$1"; shift ;;
 		--no-annotate) annotate= ;;
 		-b) branch="$1"; shift ;;
-		-P) prefix="$1"; shift ;;
+		-P) prefix="${1%/}"; shift ;;
 		-m) message="$1"; shift ;;
 		--no-prefix) prefix= ;;
 		--onto) onto="$1"; shift ;;
diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh
index 232ed89..297dac4 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -238,6 +238,25 @@ test_expect_success 'merge new subproj history into subdir/ with --squash and --
 	)
 '
 
+test_expect_success 'merge new subproj history into subdir/ with a slash appended to the argument of --prefix' '
+	test_create_repo "$test_count" &&
+	test_create_repo "$test_count/subproj" &&
+	test_create_commit "$test_count" main1 &&
+	test_create_commit "$test_count/subproj" sub1 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git subtree add --prefix=subdir/ FETCH_HEAD
+	) &&
+	test_create_commit "$test_count/subproj" sub2 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git subtree merge --prefix=subdir/ FETCH_HEAD &&
+		test_equal "$(last_commit_message)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''"
+	)
+'
+
 #
 # Tests for 'git subtree split'
 #
-- 
1.8.1

^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2013-01-14  3:59 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-13  1:52 [PATCH/RFC 0/7] mutiple improvements Techlive Zheng
2013-01-13  1:52 ` [PATCH/RFC 1/7] contrib/subtree: Add vim modeline Techlive Zheng
2013-01-13  1:52 ` [PATCH/RFC 2/7] contrib/subtree: Ignore testing directory Techlive Zheng
2013-01-13  1:52 ` [PATCH/RFC 3/7] contrib/subtree: Remove test number comments Techlive Zheng
2013-01-13  1:52 ` [PATCH/RFC 4/7] contrib/subtree: Code cleaning and refactoring Techlive Zheng
2013-01-14  3:30   ` 郑文辉(Techlive Zheng)
2013-01-13  1:52 ` [PATCH/RFC 5/7] contrib/subtree: Make each test self-contained Techlive Zheng
2013-01-13  1:52 ` [PATCH/RFC 6/7] contrib/subtree: Use %B for the split commit message Techlive Zheng
2013-01-13  1:52 ` [PATCH/RFC 7/7] contrib/subtree: Handle '--prefix' argument with a slash appended Techlive Zheng
2013-01-14  3:52 ` [PATCH/RFC v2 0/8] contrib/subtree: Reroll to follow Git's whitespace policy Techlive Zheng
2013-01-14  3:52   ` [PATCH/RFC v2 1/8] contrib/subtree: Fix whitespaces Techlive Zheng
2013-01-14  3:52   ` [PATCH/RFC v2 2/8] contrib/subtree: Add vim modeline Techlive Zheng
2013-01-14  3:52   ` [PATCH/RFC v2 3/8] contrib/subtree: Ignore testing directory Techlive Zheng
2013-01-14  3:52   ` [PATCH/RFC v2 4/8] contrib/subtree: Remove test number comments Techlive Zheng
2013-01-14  3:52   ` [PATCH/RFC v2 5/8] contrib/subtree: Code cleaning and refactoring Techlive Zheng
2013-01-14  3:52   ` [PATCH/RFC v2 6/8] contrib/subtree: Make each test self-contained Techlive Zheng
2013-01-14  3:52   ` [PATCH/RFC v2 7/8] contrib/subtree: Use %B for the split commit message Techlive Zheng
2013-01-14  3:52   ` [PATCH/RFC v2 8/8] contrib/subtree: Handle '--prefix' argument with a slash appended Techlive Zheng

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).