Skip to content

Commit fc6d4ad

Browse files
committed
Merge pull request #2714 from lbonanomi/crlf-scissors
Rationalize line endings for scissors-cleanup
2 parents 04e1624 + 4ffb4f7 commit fc6d4ad

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
@@ -623,6 +623,48 @@ test_expect_success 'cleanup commit messages (scissors option,-F,-e, scissors on
623623
test_must_be_empty actual
624624
'
625625

626+
test_expect_success 'helper-editor' '
627+
628+
write_script lf-to-crlf.sh <<-\EOF
629+
sed "s/\$/Q/" <"$1" | tr Q "\\015" >"$1".new &&
630+
mv -f "$1".new "$1"
631+
EOF
632+
'
633+
634+
test_expect_success 'cleanup commit messages (scissors option,-F,-e, CR/LF line endings)' '
635+
636+
test_config core.editor "\"$PWD/lf-to-crlf.sh\"" &&
637+
scissors="# ------------------------ >8 ------------------------" &&
638+
639+
test_write_lines >text \
640+
"# Keep this comment" "" " $scissors" \
641+
"# Keep this comment, too" "$scissors" \
642+
"# Remove this comment" "$scissors" \
643+
"Remove this comment, too" &&
644+
645+
test_write_lines >expect \
646+
"# Keep this comment" "" " $scissors" \
647+
"# Keep this comment, too" &&
648+
649+
git commit --cleanup=scissors -e -F text --allow-empty &&
650+
git cat-file -p HEAD >raw &&
651+
sed -e "1,/^\$/d" raw >actual &&
652+
test_cmp expect actual
653+
'
654+
655+
test_expect_success 'cleanup commit messages (scissors option,-F,-e, scissors on first line, CR/LF line endings)' '
656+
657+
scissors="# ------------------------ >8 ------------------------" &&
658+
test_write_lines >text \
659+
"$scissors" \
660+
"# Remove this comment and any following lines" &&
661+
cp text /tmp/test2-text &&
662+
git commit --cleanup=scissors -e -F text --allow-empty --allow-empty-message &&
663+
git cat-file -p HEAD >raw &&
664+
sed -e "1,/^\$/d" raw >actual &&
665+
test_must_be_empty actual
666+
'
667+
626668
test_expect_success 'cleanup commit messages (strip option,-F)' '
627669
628670
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 */
@@ -1085,15 +1085,22 @@ static void wt_longstatus_print_other(struct wt_status *s,
10851085
status_printf_ln(s, GIT_COLOR_NORMAL, "%s", "");
10861086
}
10871087

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

10931098
strbuf_addf(&pattern, "\n%c %s", comment_line_char, cut_line);
1094-
if (starts_with(s, pattern.buf + 1))
1099+
if (starts_with(s, pattern.buf + 1) &&
1100+
starts_with_newline(s + pattern.len - 1))
10951101
len = 0;
1096-
else if ((p = strstr(s, pattern.buf)))
1102+
else if ((p = strstr(s, pattern.buf)) &&
1103+
starts_with_newline(p + pattern.len))
10971104
len = p - s + 1;
10981105
strbuf_release(&pattern);
10991106
return len;

0 commit comments

Comments
 (0)