Test that git-am does not lose -C/-p/--whitespace options
authorJunio C Hamano <gitster@pobox.com>
Fri, 5 Dec 2008 01:08:48 +0000 (17:08 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 5 Dec 2008 02:45:02 +0000 (18:45 -0800)
These tests make sure that "git am" does not lose command line options
specified when it was started, after it is interrupted by a patch that
does not apply earlier in the series.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t4252-am-options.sh [new file with mode: 0755]
t/t4252/am-test-1-1 [new file with mode: 0644]
t/t4252/am-test-1-2 [new file with mode: 0644]
t/t4252/am-test-2-1 [new file with mode: 0644]
t/t4252/am-test-2-2 [new file with mode: 0644]
t/t4252/am-test-3-1 [new file with mode: 0644]
t/t4252/am-test-3-2 [new file with mode: 0644]
t/t4252/am-test-4-1 [new file with mode: 0644]
t/t4252/am-test-4-2 [new file with mode: 0644]
t/t4252/file-1-0 [new file with mode: 0644]
t/t4252/file-2-0 [new file with mode: 0644]

diff --git a/t/t4252-am-options.sh b/t/t4252-am-options.sh
new file mode 100755 (executable)
index 0000000..1a1946d
--- /dev/null
@@ -0,0 +1,54 @@
+#!/bin/sh
+
+test_description='git am not losing options'
+. ./test-lib.sh
+
+tm="$TEST_DIRECTORY/t4252"
+
+test_expect_success setup '
+       cp "$tm/file-1-0" file-1 &&
+       cp "$tm/file-2-0" file-2 &&
+       git add file-1 file-2 &&
+       test_tick &&
+       git commit -m initial &&
+       git tag initial
+'
+
+test_expect_success 'interrupted am --whitespace=fix' '
+       rm -rf .git/rebase-apply &&
+       git reset --hard initial &&
+       test_must_fail git am --whitespace=fix "$tm"/am-test-1-? &&
+       git am --skip &&
+       grep 3 file-1 &&
+       grep "^Six$" file-2
+'
+
+test_expect_success 'interrupted am -C1' '
+       rm -rf .git/rebase-apply &&
+       git reset --hard initial &&
+       test_must_fail git am -C1 "$tm"/am-test-2-? &&
+       git am --skip &&
+       grep 3 file-1 &&
+       grep "^Three$" file-2
+'
+
+test_expect_success 'interrupted am -p2' '
+       rm -rf .git/rebase-apply &&
+       git reset --hard initial &&
+       test_must_fail git am -p2 "$tm"/am-test-3-? &&
+       git am --skip &&
+       grep 3 file-1 &&
+       grep "^Three$" file-2
+'
+
+test_expect_success 'interrupted am -C1 -p2' '
+       rm -rf .git/rebase-apply &&
+       git reset --hard initial &&
+       test_must_fail git am -p2 -C1 "$tm"/am-test-4-? &&
+       cat .git/rebase-apply/apply_opt_extra &&
+       git am --skip &&
+       grep 3 file-1 &&
+       grep "^Three$" file-2
+'
+
+test_done
diff --git a/t/t4252/am-test-1-1 b/t/t4252/am-test-1-1
new file mode 100644 (file)
index 0000000..b0c09dc
--- /dev/null
@@ -0,0 +1,19 @@
+From: A U Thor <au.thor@example.com>
+Date: Thu Dec 4 16:00:00 2008 -0800
+Subject: Three
+
+Application of this should be rejected because the first line in the
+context does not match.
+
+diff --git i/file-1 w/file-1
+index 06e567b..10f8342 100644
+--- i/file-1
++++ w/file-1
+@@ -1,6 +1,6 @@
+ One
+ 2
+-3
++Three 
+ 4
+ 5
+ 6
diff --git a/t/t4252/am-test-1-2 b/t/t4252/am-test-1-2
new file mode 100644 (file)
index 0000000..1b874ae
--- /dev/null
@@ -0,0 +1,21 @@
+From: A U Thor <au.thor@example.com>
+Date: Thu Dec 4 16:00:00 2008 -0800
+Subject: Six
+
+Applying this patch with --whitespace=fix should lose 
+the trailing whitespace after "Six".
+
+diff --git i/file-2 w/file-2
+index 06e567b..b6f3a16 100644
+--- i/file-2
++++ w/file-2
+@@ -1,7 +1,7 @@
+ 1
+ 2
+-3
++Three
+ 4
+ 5
+-6
++Six 
+ 7
diff --git a/t/t4252/am-test-2-1 b/t/t4252/am-test-2-1
new file mode 100644 (file)
index 0000000..feda94a
--- /dev/null
@@ -0,0 +1,19 @@
+From: A U Thor <au.thor@example.com>
+Date: Thu Dec 4 16:00:00 2008 -0800
+Subject: Three
+
+Application of this should be rejected even with -C1 because the
+preimage line in the context does not match.
+
+diff --git i/file-1 w/file-1
+index 06e567b..10f8342 100644
+--- i/file-1
++++ w/file-1
+@@ -1,6 +1,6 @@
+ 1
+ 2
+-Tres
++Three 
+ 4
+ 5
+ 6
diff --git a/t/t4252/am-test-2-2 b/t/t4252/am-test-2-2
new file mode 100644 (file)
index 0000000..2ac6600
--- /dev/null
@@ -0,0 +1,21 @@
+From: A U Thor <au.thor@example.com>
+Date: Thu Dec 4 16:00:00 2008 -0800
+Subject: Six
+
+Applying this patch with -C1 should be successful even though 
+the first line in the context does not match.
+
+diff --git i/file-2 w/file-2
+index 06e567b..b6f3a16 100644
+--- i/file-2
++++ w/file-2
+@@ -1,7 +1,7 @@
+ One
+ 2
+-3
++Three
+ 4
+ 5
+-6
++Six
+ 7
diff --git a/t/t4252/am-test-3-1 b/t/t4252/am-test-3-1
new file mode 100644 (file)
index 0000000..608e5ab
--- /dev/null
@@ -0,0 +1,19 @@
+From: A U Thor <au.thor@example.com>
+Date: Thu Dec 4 16:00:00 2008 -0800
+Subject: Three
+
+Application of this should be rejected even with -p2 because the
+preimage line in the context does not match.
+
+diff --git i/junk/file-1 w/junk/file-1
+index 06e567b..10f8342 100644
+--- i/junk/file-1
++++ w/junk/file-1
+@@ -1,6 +1,6 @@
+ 1
+ 2
+-Tres
++Three 
+ 4
+ 5
+ 6
diff --git a/t/t4252/am-test-3-2 b/t/t4252/am-test-3-2
new file mode 100644 (file)
index 0000000..0081b96
--- /dev/null
@@ -0,0 +1,21 @@
+From: A U Thor <au.thor@example.com>
+Date: Thu Dec 4 16:00:00 2008 -0800
+Subject: Six
+
+Applying this patch with -p2 should be successful even though
+the patch is against a wrong level.
+
+diff --git i/junk/file-2 w/junk/file-2
+index 06e567b..b6f3a16 100644
+--- i/junk/file-2
++++ w/junk/file-2
+@@ -1,7 +1,7 @@
+ 1
+ 2
+-3
++Three
+ 4
+ 5
+-6
++Six
+ 7
diff --git a/t/t4252/am-test-4-1 b/t/t4252/am-test-4-1
new file mode 100644 (file)
index 0000000..e48cd6c
--- /dev/null
@@ -0,0 +1,19 @@
+From: A U Thor <au.thor@example.com>
+Date: Thu Dec 4 16:00:00 2008 -0800
+Subject: Three
+
+Application of this should be rejected even with -C1 -p2 because
+the preimage line in the context does not match.
+
+diff --git i/junk/file-1 w/junk/file-1
+index 06e567b..10f8342 100644
+--- i/junk/file-1
++++ w/junk/file-1
+@@ -1,6 +1,6 @@
+ 1
+ 2
+-Tres
++Three 
+ 4
+ 5
+ 6
diff --git a/t/t4252/am-test-4-2 b/t/t4252/am-test-4-2
new file mode 100644 (file)
index 0000000..0e69bfa
--- /dev/null
@@ -0,0 +1,22 @@
+From: A U Thor <au.thor@example.com>
+Date: Thu Dec 4 16:00:00 2008 -0800
+Subject: Six
+
+Applying this patch with -C1 -p2 should be successful even though
+the patch is against a wrong level and the first context line does
+not match.
+
+diff --git i/junk/file-2 w/junk/file-2
+index 06e567b..b6f3a16 100644
+--- i/junk/file-2
++++ w/junk/file-2
+@@ -1,7 +1,7 @@
+ One
+ 2
+-3
++Three
+ 4
+ 5
+-6
++Six
+ 7
diff --git a/t/t4252/file-1-0 b/t/t4252/file-1-0
new file mode 100644 (file)
index 0000000..06e567b
--- /dev/null
@@ -0,0 +1,7 @@
+1
+2
+3
+4
+5
+6
+7
diff --git a/t/t4252/file-2-0 b/t/t4252/file-2-0
new file mode 100644 (file)
index 0000000..06e567b
--- /dev/null
@@ -0,0 +1,7 @@
+1
+2
+3
+4
+5
+6
+7