Skip to content

Commit 5122614

Browse files
committed
Merge branch 'rs/patch-id-with-incomplete-line'
The patch-id computation did not ignore the "incomplete last line" marker like whitespaces. * rs/patch-id-with-incomplete-line: patch-id: ignore newline at end of file in diff_flush_patch_id()
2 parents 8923a45 + 82a6201 commit 5122614

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

diff.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6044,6 +6044,8 @@ static void patch_id_consume(void *priv, char *line, unsigned long len)
60446044
struct patch_id_t *data = priv;
60456045
int new_len;
60466046

6047+
if (len > 12 && starts_with(line, "\\ "))
6048+
return;
60476049
new_len = remove_space(line, len);
60486050

60496051
the_hash_algo->update_fn(data->ctx, line, new_len);

t/t3500-cherry.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,27 @@ test_expect_success \
5555
expr "$(echo $(git cherry master my-topic-branch) )" : "+ [^ ]* - .*"
5656
'
5757

58+
test_expect_success 'cherry ignores whitespace' '
59+
git switch --orphan=upstream-with-space &&
60+
test_commit initial file &&
61+
>expect &&
62+
git switch --create=feature-without-space &&
63+
64+
# A spaceless file on the feature branch. Expect a match upstream.
65+
printf space >file &&
66+
git add file &&
67+
git commit -m"file without space" &&
68+
git log --format="- %H" -1 >>expect &&
69+
70+
# A further change. Should not match upstream.
71+
test_commit change file &&
72+
git log --format="+ %H" -1 >>expect &&
73+
74+
git switch upstream-with-space &&
75+
# Same as the spaceless file, just with spaces and on upstream.
76+
test_commit "file with space" file "s p a c e" file-with-space &&
77+
git cherry upstream-with-space feature-without-space >actual &&
78+
test_cmp expect actual
79+
'
80+
5881
test_done

0 commit comments

Comments
 (0)