Skip to content

Commit 3932ccb

Browse files
committed
Merge pull request #2714 from lbonanomi/crlf-scissors
Rationalize line endings for scissors-cleanup
2 parents 9cb2c86 + 684f5ca commit 3932ccb

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
@@ -39,7 +39,7 @@
3939
#define UF_DELAY_WARNING_IN_MS (2 * 1000)
4040

4141
static const char cut_line[] =
42-
"------------------------ >8 ------------------------\n";
42+
"------------------------ >8 ------------------------";
4343

4444
static char default_wt_status_colors[][COLOR_MAXLEN] = {
4545
GIT_COLOR_NORMAL, /* WT_STATUS_HEADER */
@@ -1095,15 +1095,22 @@ static void wt_longstatus_print_other(struct wt_status *s,
10951095
status_printf_ln(s, GIT_COLOR_NORMAL, "%s", "");
10961096
}
10971097

1098+
static inline int starts_with_newline(const char *p)
1099+
{
1100+
return *p == '\n' || (*p == '\r' && p[1] == '\n');
1101+
}
1102+
10981103
size_t wt_status_locate_end(const char *s, size_t len)
10991104
{
11001105
const char *p;
11011106
struct strbuf pattern = STRBUF_INIT;
11021107

11031108
strbuf_addf(&pattern, "\n%s %s", comment_line_str, cut_line);
1104-
if (starts_with(s, pattern.buf + 1))
1109+
if (starts_with(s, pattern.buf + 1) &&
1110+
starts_with_newline(s + pattern.len - 1))
11051111
len = 0;
1106-
else if ((p = strstr(s, pattern.buf))) {
1112+
else if ((p = strstr(s, pattern.buf)) &&
1113+
starts_with_newline(p + pattern.len)) {
11071114
size_t newlen = p - s + 1;
11081115
if (newlen < len)
11091116
len = newlen;

0 commit comments

Comments
 (0)