Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rationalize line endings for scissors-cleanup #2714

Merged
merged 1 commit into from
Jul 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions t/t7502-commit-porcelain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,48 @@ test_expect_success 'cleanup commit messages (scissors option,-F,-e, scissors on
test_must_be_empty actual
'

test_expect_success 'helper-editor' '
write_script lf-to-crlf.sh <<-\EOF
sed "s/\$/Q/" <"$1" | tr Q "\\015" >"$1".new &&
mv -f "$1".new "$1"
EOF
lbonanomi marked this conversation as resolved.
Show resolved Hide resolved
'

test_expect_success 'cleanup commit messages (scissors option,-F,-e, CR/LF line endings)' '
test_config core.editor "\"$PWD/lf-to-crlf.sh\"" &&
scissors="# ------------------------ >8 ------------------------" &&
test_write_lines >text \
"# Keep this comment" "" " $scissors" \
"# Keep this comment, too" "$scissors" \
"# Remove this comment" "$scissors" \
"Remove this comment, too" &&
test_write_lines >expect \
"# Keep this comment" "" " $scissors" \
"# Keep this comment, too" &&
git commit --cleanup=scissors -e -F text --allow-empty &&
git cat-file -p HEAD >raw &&
sed -e "1,/^\$/d" raw >actual &&
test_cmp expect actual
'

test_expect_success 'cleanup commit messages (scissors option,-F,-e, scissors on first line, CR/LF line endings)' '
scissors="# ------------------------ >8 ------------------------" &&
test_write_lines >text \
"$scissors" \
"# Remove this comment and any following lines" &&
cp text /tmp/test2-text &&
git commit --cleanup=scissors -e -F text --allow-empty --allow-empty-message &&
git cat-file -p HEAD >raw &&
sed -e "1,/^\$/d" raw >actual &&
test_must_be_empty actual
'

test_expect_success 'cleanup commit messages (strip option,-F)' '
echo >>negative &&
Expand Down
13 changes: 10 additions & 3 deletions wt-status.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#define AB_DELAY_WARNING_IN_MS (2 * 1000)

static const char cut_line[] =
"------------------------ >8 ------------------------\n";
"------------------------ >8 ------------------------";

static char default_wt_status_colors[][COLOR_MAXLEN] = {
GIT_COLOR_NORMAL, /* WT_STATUS_HEADER */
Expand Down Expand Up @@ -1001,15 +1001,22 @@ static void wt_longstatus_print_other(struct wt_status *s,
status_printf_ln(s, GIT_COLOR_NORMAL, "%s", "");
}

static inline int starts_with_newline(const char *p)
{
return *p == '\n' || (*p == '\r' && p[1] == '\n');
}

size_t wt_status_locate_end(const char *s, size_t len)
{
const char *p;
struct strbuf pattern = STRBUF_INIT;

strbuf_addf(&pattern, "\n%c %s", comment_line_char, cut_line);
if (starts_with(s, pattern.buf + 1))
if (starts_with(s, pattern.buf + 1) &&
starts_with_newline(s + pattern.len - 1))
len = 0;
else if ((p = strstr(s, pattern.buf)))
else if ((p = strstr(s, pattern.buf)) &&
starts_with_newline(p + pattern.len))
len = p - s + 1;
strbuf_release(&pattern);
return len;
Expand Down