Skip to content

Commit 010cd45

Browse files
dschoGit for Windows Build Agent
authored andcommitted
Merge pull request #2714 from lbonanomi/main
Rationalize line endings for scissors-cleanup
2 parents 6e99304 + 5b5a34b commit 010cd45

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 */
@@ -1054,15 +1054,22 @@ static void wt_longstatus_print_other(struct wt_status *s,
10541054
status_printf_ln(s, GIT_COLOR_NORMAL, "%s", "");
10551055
}
10561056

1057+
static inline int starts_with_newline(const char *p)
1058+
{
1059+
return *p == '\n' || (*p == '\r' && p[1] == '\n');
1060+
}
1061+
10571062
size_t wt_status_locate_end(const char *s, size_t len)
10581063
{
10591064
const char *p;
10601065
struct strbuf pattern = STRBUF_INIT;
10611066

10621067
strbuf_addf(&pattern, "\n%c %s", comment_line_char, cut_line);
1063-
if (starts_with(s, pattern.buf + 1))
1068+
if (starts_with(s, pattern.buf + 1) &&
1069+
starts_with_newline(s + pattern.len - 1))
10641070
len = 0;
1065-
else if ((p = strstr(s, pattern.buf)))
1071+
else if ((p = strstr(s, pattern.buf)) &&
1072+
starts_with_newline(p + pattern.len))
10661073
len = p - s + 1;
10671074
strbuf_release(&pattern);
10681075
return len;

0 commit comments

Comments
 (0)