[PATCH v3 0/9] Correct offsets of hunks when one is skipped

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Phillip Wood <phillip.wood@xxxxxxxxxxxxx>

I've fixed the use of test_set_editor most of which was already in pu
and reworked the sha1 comparisons to rewrite the hashes in the index
lines rather than deleting the index lines.

Cover letter to v1:

While working on a patch series to stage selected lines from a hunk
without having to edit it I got worried that subsequent patches would
be applied in the wrong place which lead to this series to correct the
offsets of hunks following those that are skipped or edited.

Interdiff:

diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index 0fb9c0e0f1..05540ee9ef 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -10,6 +10,16 @@ then
 	test_done
 fi
 
+diff_cmp () {
+	for x
+	do
+		sed  -e '/^index/s/[0-9a-f]*[1-9a-f][0-9a-f]*\.\./1234567../' \
+		     -e '/^index/s/\.\.[0-9a-f]*[1-9a-f][0-9a-f]*/..9abcdef/' \
+		     "$x" >"$x.filtered"
+	done
+	test_cmp "$1.filtered" "$2.filtered"
+}
+
 test_expect_success 'setup (initial)' '
 	echo content >file &&
 	git add file &&
@@ -24,6 +34,7 @@ test_expect_success 'status works (initial)' '
 test_expect_success 'setup expected' '
 	cat >expected <<-EOF
 	new file mode 100644
+	index 0000000..d95f3ad
 	--- /dev/null
 	+++ b/file
 	@@ -0,0 +1 @@
@@ -33,8 +44,8 @@ test_expect_success 'setup expected' '
 
 test_expect_success 'diff works (initial)' '
 	(echo d; echo 1) | git add -i >output &&
-	sed -ne /^index/d -e "/new file/,/content/p" <output >diff &&
-	test_cmp expected diff
+	sed -ne "/new file/,/content/p" <output >diff &&
+	diff_cmp expected diff
 '
 test_expect_success 'revert works (initial)' '
 	git add file &&
@@ -59,6 +70,7 @@ test_expect_success 'status works (commit)' '
 
 test_expect_success 'setup expected' '
 	cat >expected <<-EOF
+	index 180b47c..b6f2c08 100644
 	--- a/file
 	+++ b/file
 	@@ -1 +1,2 @@
@@ -69,8 +81,8 @@ test_expect_success 'setup expected' '
 
 test_expect_success 'diff works (commit)' '
 	(echo d; echo 1) | git add -i >output &&
-	sed -ne "/^---/,/content/p" <output >diff &&
-	test_cmp expected diff
+	sed -ne "/^index/,/content/p" <output >diff &&
+	diff_cmp expected diff
 '
 test_expect_success 'revert works (commit)' '
 	git add file &&
@@ -88,8 +100,8 @@ test_expect_success 'setup expected' '
 test_expect_success 'dummy edit works' '
 	test_set_editor : &&
 	(echo e; echo a) | git add -p &&
-	git diff | sed /^index/d >diff &&
-	test_cmp expected diff
+	git diff > diff &&
+	diff_cmp expected diff
 '
 
 test_expect_success 'setup patch' '
@@ -103,12 +115,11 @@ test_expect_success 'setup patch' '
 '
 
 test_expect_success 'setup fake editor' '
-	FAKE_EDITOR="$(pwd)/fake-editor.sh" &&
-	write_script "$FAKE_EDITOR" <<-\EOF &&
+	write_script "fake_editor.sh" <<-\EOF &&
 	mv -f "$1" oldpatch &&
 	mv -f patch "$1"
 	EOF
-	test_set_editor "$FAKE_EDITOR"
+	test_set_editor "$(pwd)/fake_editor.sh"
 '
 
 test_expect_success 'bad edit rejected' '
@@ -143,6 +154,7 @@ test_expect_success 'setup patch' '
 test_expect_success 'setup expected' '
 	cat >expected <<-EOF
 	diff --git a/file b/file
+	index b5dd6c9..f910ae9 100644
 	--- a/file
 	+++ b/file
 	@@ -1,4 +1,4 @@
@@ -156,8 +168,8 @@ test_expect_success 'setup expected' '
 
 test_expect_success 'real edit works' '
 	(echo e; echo n; echo d) | git add -p &&
-	git diff | sed /^index/d >output &&
-	test_cmp expected output
+	git diff >output &&
+	diff_cmp expected output
 '
 
 test_expect_success 'skip files similarly as commit -a' '
@@ -165,11 +177,11 @@ test_expect_success 'skip files similarly as commit -a' '
 	echo file >.gitignore &&
 	echo changed >file &&
 	echo y | git add -p file &&
-	git diff | sed /^index/d >output &&
+	git diff >output &&
 	git reset &&
 	git commit -am commit &&
-	git diff | sed /^index/d >expected &&
-	test_cmp expected output &&
+	git diff >expected &&
+	diff_cmp expected output &&
 	git reset --hard HEAD^
 '
 rm -f .gitignore
@@ -214,6 +226,7 @@ test_expect_success 'setup again' '
 # Write the patch file with a new line at the top and bottom
 test_expect_success 'setup patch' '
 	cat >patch <<-EOF
+	index 180b47c..b6f2c08 100644
 	--- a/file
 	+++ b/file
 	@@ -1,2 +1,4 @@
@@ -228,7 +241,7 @@ test_expect_success 'setup patch' '
 # Expected output, diff is similar to the patch but w/ diff at the top
 test_expect_success 'setup expected' '
 	echo diff --git a/file b/file >expected &&
-	cat patch >>expected &&
+	cat patch |sed "/^index/s/ 100644/ 100755/" >>expected &&
 	cat >expected-output <<-EOF
 	--- a/file
 	+++ b/file
@@ -258,8 +271,8 @@ test_expect_success C_LOCALE_OUTPUT 'add first line works' '
 		sed -n -e "s/^Stage this hunk[^@]*\(@@ .*\)/\1/" \
 		       -e "/^[-+@ \\\\]"/p  >output &&
 	test_must_be_empty error &&
-	git diff --cached | sed /^index/d >diff &&
-	test_cmp expected diff &&
+	git diff --cached >diff &&
+	diff_cmp expected diff &&
 	test_cmp expected-output output
 '
 
@@ -267,6 +280,7 @@ test_expect_success 'setup expected' '
 	cat >expected <<-EOF
 	diff --git a/non-empty b/non-empty
 	deleted file mode 100644
+	index d95f3ad..0000000
 	--- a/non-empty
 	+++ /dev/null
 	@@ -1 +0,0 @@
@@ -281,14 +295,15 @@ test_expect_success 'deleting a non-empty file' '
 	git commit -m non-empty &&
 	rm non-empty &&
 	echo y | git add -p non-empty &&
-	git diff --cached | sed /^index/d >diff &&
-	test_cmp expected diff
+	git diff --cached >diff &&
+	diff_cmp expected diff
 '
 
 test_expect_success 'setup expected' '
 	cat >expected <<-EOF
 	diff --git a/empty b/empty
 	deleted file mode 100644
+	index e69de29..0000000
 	EOF
 '
 
@@ -299,8 +314,8 @@ test_expect_success 'deleting an empty file' '
 	git commit -m empty &&
 	rm empty &&
 	echo y | git add -p empty &&
-	git diff --cached | sed /^index/d >diff &&
-	test_cmp expected diff
+	git diff --cached >diff &&
+	diff_cmp expected diff
 '
 
 test_expect_success 'split hunk setup' '
@@ -326,7 +341,7 @@ test_expect_success 'split hunk "add -p (edit)"' '
 	#    exits.
 	printf "%s\n" s e     q n q q |
 	EDITOR=: git add -p &&
-	git diff | sed /^index/d >actual &&
+	git diff >actual &&
 	! grep "^+15" actual
 '
 
@@ -338,7 +353,7 @@ test_expect_failure 'split hunk "add -p (no, yes, edit)"' '
 	printf "%s\n" s n y e   q n q q |
 	EDITOR=: git add -p 2>error &&
 	test_must_be_empty error &&
-	git diff | sed /^index/d >actual &&
+	git diff >actual &&
 	! grep "^+31" actual
 '
 
@@ -357,14 +372,15 @@ test_expect_success 'patch mode ignores unmerged entries' '
 	cat >expected <<-\EOF &&
 	* Unmerged path conflict.t
 	diff --git a/non-conflict.t b/non-conflict.t
+	index f766221..5ea2ed4 100644
 	--- a/non-conflict.t
 	+++ b/non-conflict.t
 	@@ -1 +1 @@
 	-non-conflict
 	+changed
 	EOF
-	git diff --cached | sed /^index/d >diff &&
-	test_cmp expected diff
+	git diff --cached >diff &&
+	diff_cmp expected diff
 '
 
 test_expect_success TTY 'diffs can be colorized' '
@@ -393,7 +409,7 @@ test_expect_success 'patch-mode via -i prompts for files' '
 
 	echo test >expect &&
 	git diff --cached --name-only >actual &&
-	test_cmp expect actual
+	diff_cmp expect actual
 '
 
 test_expect_success 'add -p handles globs' '
@@ -550,7 +566,6 @@ test_expect_success 'add -p works with pathological context lines' '
 
 test_expect_success 'add -p patch editing works with pathological context lines' '
 	git reset &&
-	test_set_editor "$FAKE_EDITOR" &&
 	# n q q below is in case edit fails
 	printf "%s\n" e y    n q q |
 	git add -p &&

Phillip Wood (9):
  add -i: add function to format hunk header
  t3701: indent here documents
  t3701: use test_write_lines and write_script
  t3701: don't hard code sha1 hash values
  t3701: add failing test for pathological context lines
  add -p: Adjust offsets of subsequent hunks when one is skipped
  add -p: calculate offset delta for edited patches
  add -p: fix counting when splitting and coalescing
  add -p: don't rely on apply's '--recount' option

 git-add--interactive.perl  | 106 +++++++++++++----
 t/t3701-add-interactive.sh | 288 +++++++++++++++++++++++++--------------------
 2 files changed, 240 insertions(+), 154 deletions(-)

-- 
2.16.1




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux