Skip to content

Commit accd43b

Browse files
committed
Merge pull request #2714 from lbonanomi/crlf-scissors
Rationalize line endings for scissors-cleanup
2 parents 595bcd2 + dcde9bf commit accd43b

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
@@ -605,6 +605,48 @@ test_expect_success 'cleanup commit messages (scissors option,-F,-e, scissors on
605605
test_must_be_empty actual
606606
'
607607

608+
test_expect_success 'helper-editor' '
609+
610+
write_script lf-to-crlf.sh <<-\EOF
611+
sed "s/\$/Q/" <"$1" | tr Q "\\015" >"$1".new &&
612+
mv -f "$1".new "$1"
613+
EOF
614+
'
615+
616+
test_expect_success 'cleanup commit messages (scissors option,-F,-e, CR/LF line endings)' '
617+
618+
test_config core.editor "\"$PWD/lf-to-crlf.sh\"" &&
619+
scissors="# ------------------------ >8 ------------------------" &&
620+
621+
test_write_lines >text \
622+
"# Keep this comment" "" " $scissors" \
623+
"# Keep this comment, too" "$scissors" \
624+
"# Remove this comment" "$scissors" \
625+
"Remove this comment, too" &&
626+
627+
test_write_lines >expect \
628+
"# Keep this comment" "" " $scissors" \
629+
"# Keep this comment, too" &&
630+
631+
git commit --cleanup=scissors -e -F text --allow-empty &&
632+
git cat-file -p HEAD >raw &&
633+
sed -e "1,/^\$/d" raw >actual &&
634+
test_cmp expect actual
635+
'
636+
637+
test_expect_success 'cleanup commit messages (scissors option,-F,-e, scissors on first line, CR/LF line endings)' '
638+
639+
scissors="# ------------------------ >8 ------------------------" &&
640+
test_write_lines >text \
641+
"$scissors" \
642+
"# Remove this comment and any following lines" &&
643+
cp text /tmp/test2-text &&
644+
git commit --cleanup=scissors -e -F text --allow-empty --allow-empty-message &&
645+
git cat-file -p HEAD >raw &&
646+
sed -e "1,/^\$/d" raw >actual &&
647+
test_must_be_empty actual
648+
'
649+
608650
test_expect_success 'cleanup commit messages (strip option,-F)' '
609651
610652
echo >>negative &&

wt-status.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#define UF_DELAY_WARNING_IN_MS (2 * 1000)
3737

3838
static const char cut_line[] =
39-
"------------------------ >8 ------------------------\n";
39+
"------------------------ >8 ------------------------";
4040

4141
static char default_wt_status_colors[][COLOR_MAXLEN] = {
4242
GIT_COLOR_NORMAL, /* WT_STATUS_HEADER */
@@ -1084,15 +1084,22 @@ static void wt_longstatus_print_other(struct wt_status *s,
10841084
status_printf_ln(s, GIT_COLOR_NORMAL, "%s", "");
10851085
}
10861086

1087+
static inline int starts_with_newline(const char *p)
1088+
{
1089+
return *p == '\n' || (*p == '\r' && p[1] == '\n');
1090+
}
1091+
10871092
size_t wt_status_locate_end(const char *s, size_t len)
10881093
{
10891094
const char *p;
10901095
struct strbuf pattern = STRBUF_INIT;
10911096

10921097
strbuf_addf(&pattern, "\n%c %s", comment_line_char, cut_line);
1093-
if (starts_with(s, pattern.buf + 1))
1098+
if (starts_with(s, pattern.buf + 1) &&
1099+
starts_with_newline(s + pattern.len - 1))
10941100
len = 0;
1095-
else if ((p = strstr(s, pattern.buf)))
1101+
else if ((p = strstr(s, pattern.buf)) &&
1102+
starts_with_newline(p + pattern.len))
10961103
len = p - s + 1;
10971104
strbuf_release(&pattern);
10981105
return len;

0 commit comments

Comments
 (0)