Skip to content

Commit 66ef726

Browse files
dschoGit for Windows Build Agent
authored andcommitted
Merge pull request #2714 from lbonanomi/crlf-scissors
Rationalize line endings for scissors-cleanup
2 parents 83ba9a6 + bc4e0cc commit 66ef726

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
@@ -25,7 +25,7 @@
2525
#define UF_DELAY_WARNING_IN_MS (2 * 1000)
2626

2727
static const char cut_line[] =
28-
"------------------------ >8 ------------------------\n";
28+
"------------------------ >8 ------------------------";
2929

3030
static char default_wt_status_colors[][COLOR_MAXLEN] = {
3131
GIT_COLOR_NORMAL, /* WT_STATUS_HEADER */
@@ -1073,15 +1073,22 @@ static void wt_longstatus_print_other(struct wt_status *s,
10731073
status_printf_ln(s, GIT_COLOR_NORMAL, "%s", "");
10741074
}
10751075

1076+
static inline int starts_with_newline(const char *p)
1077+
{
1078+
return *p == '\n' || (*p == '\r' && p[1] == '\n');
1079+
}
1080+
10761081
size_t wt_status_locate_end(const char *s, size_t len)
10771082
{
10781083
const char *p;
10791084
struct strbuf pattern = STRBUF_INIT;
10801085

10811086
strbuf_addf(&pattern, "\n%c %s", comment_line_char, cut_line);
1082-
if (starts_with(s, pattern.buf + 1))
1087+
if (starts_with(s, pattern.buf + 1) &&
1088+
starts_with_newline(s + pattern.len - 1))
10831089
len = 0;
1084-
else if ((p = strstr(s, pattern.buf)))
1090+
else if ((p = strstr(s, pattern.buf)) &&
1091+
starts_with_newline(p + pattern.len))
10851092
len = p - s + 1;
10861093
strbuf_release(&pattern);
10871094
return len;

0 commit comments

Comments
 (0)