Skip to content

Commit 798ddfc

Browse files
committed
Merge branch 'jt/commit-redundant-scissors-fix'
"git commit -v --cleanup=scissors" used to add the scissors line twice in the log message buffer, which has been corrected. * jt/commit-redundant-scissors-fix: commit: unify logic to avoid multiple scissors lines when merging commit: avoid redundant scissor line with --cleanup=scissors -v
2 parents ae46d5f + e90cc07 commit 798ddfc

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

builtin/commit.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,6 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
738738
const char *hook_arg2 = NULL;
739739
int clean_message_contents = (cleanup_mode != COMMIT_MSG_CLEANUP_NONE);
740740
int old_display_comment_prefix;
741-
int merge_contains_scissors = 0;
742741
int invoked_hook;
743742

744743
/* This checks and barfs if author is badly specified */
@@ -842,7 +841,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
842841
wt_status_locate_end(sb.buf + merge_msg_start,
843842
sb.len - merge_msg_start) <
844843
sb.len - merge_msg_start)
845-
merge_contains_scissors = 1;
844+
s->added_cut_line = 1;
846845
} else if (!stat(git_path_squash_msg(the_repository), &statbuf)) {
847846
if (strbuf_read_file(&sb, git_path_squash_msg(the_repository), 0) < 0)
848847
die_errno(_("could not read SQUASH_MSG"));
@@ -925,9 +924,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
925924
" yourself if you want to.\n"
926925
"An empty message aborts the commit.\n");
927926
if (whence != FROM_COMMIT) {
928-
if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS &&
929-
!merge_contains_scissors)
930-
wt_status_add_cut_line(s->fp);
927+
if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS)
928+
wt_status_add_cut_line(s);
931929
status_printf_ln(
932930
s, GIT_COLOR_NORMAL,
933931
whence == FROM_MERGE ?
@@ -947,8 +945,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
947945
if (cleanup_mode == COMMIT_MSG_CLEANUP_ALL)
948946
status_printf(s, GIT_COLOR_NORMAL, hint_cleanup_all, comment_line_char);
949947
else if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS) {
950-
if (whence == FROM_COMMIT && !merge_contains_scissors)
951-
wt_status_add_cut_line(s->fp);
948+
if (whence == FROM_COMMIT)
949+
wt_status_add_cut_line(s);
952950
} else /* COMMIT_MSG_CLEANUP_SPACE, that is. */
953951
status_printf(s, GIT_COLOR_NORMAL, hint_cleanup_space, comment_line_char);
954952

t/t7502-commit-porcelain.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,11 @@ test_expect_success 'message shows date when it is explicitly set' '
736736
.git/COMMIT_EDITMSG
737737
'
738738

739+
test_expect_success 'message does not have multiple scissors lines' '
740+
git commit --cleanup=scissors -v --allow-empty -e -m foo &&
741+
test $(grep -c -e "--- >8 ---" .git/COMMIT_EDITMSG) -eq 1
742+
'
743+
739744
test_expect_success AUTOIDENT 'message shows committer when it is automatic' '
740745
741746
echo >>negative &&

wt-status.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,12 +1107,15 @@ void wt_status_append_cut_line(struct strbuf *buf)
11071107
strbuf_add_commented_lines(buf, explanation, strlen(explanation), comment_line_char);
11081108
}
11091109

1110-
void wt_status_add_cut_line(FILE *fp)
1110+
void wt_status_add_cut_line(struct wt_status *s)
11111111
{
11121112
struct strbuf buf = STRBUF_INIT;
11131113

1114+
if (s->added_cut_line)
1115+
return;
1116+
s->added_cut_line = 1;
11141117
wt_status_append_cut_line(&buf);
1115-
fputs(buf.buf, fp);
1118+
fputs(buf.buf, s->fp);
11161119
strbuf_release(&buf);
11171120
}
11181121

@@ -1143,11 +1146,12 @@ static void wt_longstatus_print_verbose(struct wt_status *s)
11431146
* file (and even the "auto" setting won't work, since it
11441147
* will have checked isatty on stdout). But we then do want
11451148
* to insert the scissor line here to reliably remove the
1146-
* diff before committing.
1149+
* diff before committing, if we didn't already include one
1150+
* before.
11471151
*/
11481152
if (s->fp != stdout) {
11491153
rev.diffopt.use_color = 0;
1150-
wt_status_add_cut_line(s->fp);
1154+
wt_status_add_cut_line(s);
11511155
}
11521156
if (s->verbose > 1 && s->committable) {
11531157
/* print_updated() printed a header, so do we */

wt-status.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ struct wt_status {
130130
int rename_score;
131131
int rename_limit;
132132
enum wt_status_format status_format;
133+
unsigned char added_cut_line; /* boolean */
133134
struct wt_status_state state;
134135
struct object_id oid_commit; /* when not Initial */
135136

@@ -147,7 +148,7 @@ struct wt_status {
147148

148149
size_t wt_status_locate_end(const char *s, size_t len);
149150
void wt_status_append_cut_line(struct strbuf *buf);
150-
void wt_status_add_cut_line(FILE *fp);
151+
void wt_status_add_cut_line(struct wt_status *s);
151152
void wt_status_prepare(struct repository *r, struct wt_status *s);
152153
void wt_status_print(struct wt_status *s);
153154
void wt_status_collect(struct wt_status *s);

0 commit comments

Comments
 (0)