Skip to content

Commit a17f9f8

Browse files
lbonanomidscho
authored andcommitted
commit: accept "scissors" with CR/LF line endings
This change enhances `git commit --cleanup=scissors` by detecting scissors lines ending in either LF (UNIX-style) or CR/LF (DOS-style). Regression tests are included to specifically test for trailing comments after a CR/LF-terminated scissors line. Signed-off-by: Luke Bonanomi <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent b48c1c1 commit a17f9f8

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

4242
static const char cut_line[] =
43-
"------------------------ >8 ------------------------\n";
43+
"------------------------ >8 ------------------------";
4444

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

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

11041109
strbuf_addf(&pattern, "\n%s %s", comment_line_str, cut_line);
1105-
if (starts_with(s, pattern.buf + 1))
1110+
if (starts_with(s, pattern.buf + 1) &&
1111+
starts_with_newline(s + pattern.len - 1))
11061112
len = 0;
1107-
else if ((p = strstr(s, pattern.buf))) {
1113+
else if ((p = strstr(s, pattern.buf)) &&
1114+
starts_with_newline(p + pattern.len)) {
11081115
size_t newlen = p - s + 1;
11091116
if (newlen < len)
11101117
len = newlen;

0 commit comments

Comments
 (0)