Skip to content

Commit 5311fe4

Browse files
dschoGit for Windows Build Agent
authored andcommitted
Merge pull request #2714 from lbonanomi/main
Rationalize line endings for scissors-cleanup
2 parents 7b9ce45 + 9f1637b commit 5311fe4

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
@@ -586,6 +586,48 @@ test_expect_success 'cleanup commit messages (scissors option,-F,-e, scissors on
586586
test_must_be_empty actual
587587
'
588588

589+
test_expect_success 'helper-editor' '
590+
591+
write_script lf-to-crlf.sh <<-\EOF
592+
sed "s/\$/Q/" <"$1" | tr Q "\\015" >"$1".new &&
593+
mv -f "$1".new "$1"
594+
EOF
595+
'
596+
597+
test_expect_success 'cleanup commit messages (scissors option,-F,-e, CR/LF line endings)' '
598+
599+
test_config core.editor "\"$PWD/lf-to-crlf.sh\"" &&
600+
scissors="# ------------------------ >8 ------------------------" &&
601+
602+
test_write_lines >text \
603+
"# Keep this comment" "" " $scissors" \
604+
"# Keep this comment, too" "$scissors" \
605+
"# Remove this comment" "$scissors" \
606+
"Remove this comment, too" &&
607+
608+
test_write_lines >expect \
609+
"# Keep this comment" "" " $scissors" \
610+
"# Keep this comment, too" &&
611+
612+
git commit --cleanup=scissors -e -F text --allow-empty &&
613+
git cat-file -p HEAD >raw &&
614+
sed -e "1,/^\$/d" raw >actual &&
615+
test_cmp expect actual
616+
'
617+
618+
test_expect_success 'cleanup commit messages (scissors option,-F,-e, scissors on first line, CR/LF line endings)' '
619+
620+
scissors="# ------------------------ >8 ------------------------" &&
621+
test_write_lines >text \
622+
"$scissors" \
623+
"# Remove this comment and any following lines" &&
624+
cp text /tmp/test2-text &&
625+
git commit --cleanup=scissors -e -F text --allow-empty --allow-empty-message &&
626+
git cat-file -p HEAD >raw &&
627+
sed -e "1,/^\$/d" raw >actual &&
628+
test_must_be_empty actual
629+
'
630+
589631
test_expect_success 'cleanup commit messages (strip option,-F)' '
590632
591633
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 */
@@ -1004,15 +1004,22 @@ static void wt_longstatus_print_other(struct wt_status *s,
10041004
status_printf_ln(s, GIT_COLOR_NORMAL, "%s", "");
10051005
}
10061006

1007+
static inline int starts_with_newline(const char *p)
1008+
{
1009+
return *p == '\n' || (*p == '\r' && p[1] == '\n');
1010+
}
1011+
10071012
size_t wt_status_locate_end(const char *s, size_t len)
10081013
{
10091014
const char *p;
10101015
struct strbuf pattern = STRBUF_INIT;
10111016

10121017
strbuf_addf(&pattern, "\n%c %s", comment_line_char, cut_line);
1013-
if (starts_with(s, pattern.buf + 1))
1018+
if (starts_with(s, pattern.buf + 1) &&
1019+
starts_with_newline(s + pattern.len - 1))
10141020
len = 0;
1015-
else if ((p = strstr(s, pattern.buf)))
1021+
else if ((p = strstr(s, pattern.buf)) &&
1022+
starts_with_newline(p + pattern.len))
10161023
len = p - s + 1;
10171024
strbuf_release(&pattern);
10181025
return len;

0 commit comments

Comments
 (0)