Skip to content

Commit a94594d

Browse files
committed
Merge branch 'sg/commit-cleanup-scissors' into maint
"git commit --cleanup=scissors" was not careful enough to protect against getting fooled by a line that looked like scissors. * sg/commit-cleanup-scissors: commit: cope with scissors lines in commit message
2 parents ca00f80 + fbfa097 commit a94594d

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

t/t7502-commit.sh

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,36 @@ test_expect_success 'cleanup commit messages (scissors option,-F,-e)' '
229229
cat >text <<EOF &&
230230
231231
# to be kept
232+
233+
# ------------------------ >8 ------------------------
234+
# to be kept, too
232235
# ------------------------ >8 ------------------------
233236
to be removed
237+
# ------------------------ >8 ------------------------
238+
to be removed, too
239+
EOF
240+
241+
cat >expect <<EOF &&
242+
# to be kept
243+
244+
# ------------------------ >8 ------------------------
245+
# to be kept, too
234246
EOF
235-
echo "# to be kept" >expect &&
236247
git commit --cleanup=scissors -e -F text -a &&
237248
git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
238249
test_cmp expect actual
250+
'
239251

252+
test_expect_success 'cleanup commit messages (scissors option,-F,-e, scissors on first line)' '
253+
254+
echo >>negative &&
255+
cat >text <<EOF &&
256+
# ------------------------ >8 ------------------------
257+
to be removed
258+
EOF
259+
git commit --cleanup=scissors -e -F text -a --allow-empty-message &&
260+
git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
261+
test_must_be_empty actual
240262
'
241263

242264
test_expect_success 'cleanup commit messages (strip option,-F)' '

wt-status.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -823,10 +823,11 @@ void wt_status_truncate_message_at_cut_line(struct strbuf *buf)
823823
const char *p;
824824
struct strbuf pattern = STRBUF_INIT;
825825

826-
strbuf_addf(&pattern, "%c %s", comment_line_char, cut_line);
827-
p = strstr(buf->buf, pattern.buf);
828-
if (p && (p == buf->buf || p[-1] == '\n'))
829-
strbuf_setlen(buf, p - buf->buf);
826+
strbuf_addf(&pattern, "\n%c %s", comment_line_char, cut_line);
827+
if (starts_with(buf->buf, pattern.buf + 1))
828+
strbuf_setlen(buf, 0);
829+
else if ((p = strstr(buf->buf, pattern.buf)))
830+
strbuf_setlen(buf, p - buf->buf + 1);
830831
strbuf_release(&pattern);
831832
}
832833

0 commit comments

Comments
 (0)