Skip to content

Commit 57bd80c

Browse files
dschoGit for Windows Build Agent
authored and
Git for Windows Build Agent
committed
Merge pull request #2714 from lbonanomi/main
Rationalize line endings for scissors-cleanup
2 parents a6fcb52 + 48f0c72 commit 57bd80c

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

t/t7502-commit-porcelain.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,48 @@ test_expect_success 'cleanup commit messages (scissors option,-F,-e, scissors on
271271
test_must_be_empty actual
272272
'
273273

274+
test_expect_success 'helper-editor' '
275+
276+
write_script lf-to-crlf.sh <<-\EOF
277+
sed "s/\$/Q/" <"$1" | tr Q "\\015" >"$1".new &&
278+
mv -f "$1".new "$1"
279+
EOF
280+
'
281+
282+
test_expect_success 'cleanup commit messages (scissors option,-F,-e, CR/LF line endings)' '
283+
284+
test_config core.editor "\"$PWD/lf-to-crlf.sh\"" &&
285+
scissors="# ------------------------ >8 ------------------------" &&
286+
287+
test_write_lines >text \
288+
"# Keep this comment" "" " $scissors" \
289+
"# Keep this comment, too" "$scissors" \
290+
"# Remove this comment" "$scissors" \
291+
"Remove this comment, too" &&
292+
293+
test_write_lines >expect \
294+
"# Keep this comment" "" " $scissors" \
295+
"# Keep this comment, too" &&
296+
297+
git commit --cleanup=scissors -e -F text --allow-empty &&
298+
git cat-file -p HEAD >raw &&
299+
sed -e "1,/^\$/d" raw >actual &&
300+
test_cmp expect actual
301+
'
302+
303+
test_expect_success 'cleanup commit messages (scissors option,-F,-e, scissors on first line, CR/LF line endings)' '
304+
305+
scissors="# ------------------------ >8 ------------------------" &&
306+
test_write_lines >text \
307+
"$scissors" \
308+
"# Remove this comment and any following lines" &&
309+
cp text /tmp/test2-text &&
310+
git commit --cleanup=scissors -e -F text --allow-empty --allow-empty-message &&
311+
git cat-file -p HEAD >raw &&
312+
sed -e "1,/^\$/d" raw >actual &&
313+
test_must_be_empty actual
314+
'
315+
274316
test_expect_success 'cleanup commit messages (strip option,-F)' '
275317
276318
echo >>negative &&

wt-status.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#define AB_DELAY_WARNING_IN_MS (2 * 1000)
2323

2424
static const char cut_line[] =
25-
"------------------------ >8 ------------------------\n";
25+
"------------------------ >8 ------------------------";
2626

2727
static char default_wt_status_colors[][COLOR_MAXLEN] = {
2828
GIT_COLOR_NORMAL, /* WT_STATUS_HEADER */
@@ -1001,15 +1001,22 @@ static void wt_longstatus_print_other(struct wt_status *s,
10011001
status_printf_ln(s, GIT_COLOR_NORMAL, "%s", "");
10021002
}
10031003

1004+
static inline int starts_with_newline(const char *p)
1005+
{
1006+
return *p == '\n' || (*p == '\r' && p[1] == '\n');
1007+
}
1008+
10041009
size_t wt_status_locate_end(const char *s, size_t len)
10051010
{
10061011
const char *p;
10071012
struct strbuf pattern = STRBUF_INIT;
10081013

10091014
strbuf_addf(&pattern, "\n%c %s", comment_line_char, cut_line);
1010-
if (starts_with(s, pattern.buf + 1))
1015+
if (starts_with(s, pattern.buf + 1) &&
1016+
starts_with_newline(s + pattern.len - 1))
10111017
len = 0;
1012-
else if ((p = strstr(s, pattern.buf)))
1018+
else if ((p = strstr(s, pattern.buf)) &&
1019+
starts_with_newline(p + pattern.len))
10131020
len = p - s + 1;
10141021
strbuf_release(&pattern);
10151022
return len;

0 commit comments

Comments
 (0)