Skip to content

Commit ebd3154

Browse files
committed
Merge branch 'sl/commit-dry-run-with-short-output-fix' into pu
Under discussion. cf. <xmqqpnzlpyux.fsf@gitster-ct.c.googlers.com> * sl/commit-dry-run-with-short-output-fix: commit: fix exit code for --short/--porcelain wt-status: teach wt_status_collect about merges in progress t7501: add merge conflict tests for dry run
2 parents dd70a6a + e67b2c5 commit ebd3154

File tree

5 files changed

+208
-149
lines changed

5 files changed

+208
-149
lines changed

Diff for: builtin/commit.c

+19-13
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix
485485
static int run_status(FILE *fp, const char *index_file, const char *prefix, int nowarn,
486486
struct wt_status *s)
487487
{
488+
struct wt_status_state state;
488489
struct object_id oid;
489490

490491
if (s->relative_paths)
@@ -504,10 +505,12 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
504505
s->status_format = status_format;
505506
s->ignore_submodule_arg = ignore_submodule_arg;
506507

507-
wt_status_collect(s);
508-
wt_status_print(s);
508+
wt_status_get_state(s, &state);
509+
wt_status_collect(s, &state);
510+
wt_status_print(s, &state);
511+
wt_status_clear_state(&state);
509512

510-
return s->commitable;
513+
return s->committable;
511514
}
512515

513516
static int is_a_merge(const struct commit *current_head)
@@ -653,7 +656,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
653656
{
654657
struct stat statbuf;
655658
struct strbuf committer_ident = STRBUF_INIT;
656-
int commitable;
659+
int committable;
657660
struct strbuf sb = STRBUF_INIT;
658661
const char *hook_arg1 = NULL;
659662
const char *hook_arg2 = NULL;
@@ -870,7 +873,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
870873

871874
saved_color_setting = s->use_color;
872875
s->use_color = 0;
873-
commitable = run_status(s->fp, index_file, prefix, 1, s);
876+
committable = run_status(s->fp, index_file, prefix, 1, s);
874877
s->use_color = saved_color_setting;
875878
} else {
876879
struct object_id oid;
@@ -888,7 +891,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
888891
for (i = 0; i < active_nr; i++)
889892
if (ce_intent_to_add(active_cache[i]))
890893
ita_nr++;
891-
commitable = active_nr - ita_nr > 0;
894+
committable = active_nr - ita_nr > 0;
892895
} else {
893896
/*
894897
* Unless the user did explicitly request a submodule
@@ -904,7 +907,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
904907
if (ignore_submodule_arg &&
905908
!strcmp(ignore_submodule_arg, "all"))
906909
flags.ignore_submodules = 1;
907-
commitable = index_differs_from(parent, &flags, 1);
910+
committable = index_differs_from(parent, &flags, 1);
908911
}
909912
}
910913
strbuf_release(&committer_ident);
@@ -916,7 +919,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
916919
* explicit --allow-empty. In the cherry-pick case, it may be
917920
* empty due to conflict resolution, which the user should okay.
918921
*/
919-
if (!commitable && whence != FROM_MERGE && !allow_empty &&
922+
if (!committable && whence != FROM_MERGE && !allow_empty &&
920923
!(amend && is_a_merge(current_head))) {
921924
s->display_comment_prefix = old_display_comment_prefix;
922925
run_status(stdout, index_file, prefix, 0, s);
@@ -1186,14 +1189,14 @@ static int parse_and_validate_options(int argc, const char *argv[],
11861189
static int dry_run_commit(int argc, const char **argv, const char *prefix,
11871190
const struct commit *current_head, struct wt_status *s)
11881191
{
1189-
int commitable;
1192+
int committable;
11901193
const char *index_file;
11911194

11921195
index_file = prepare_index(argc, argv, prefix, current_head, 1);
1193-
commitable = run_status(stdout, index_file, prefix, 0, s);
1196+
committable = run_status(stdout, index_file, prefix, 0, s);
11941197
rollback_index_files();
11951198

1196-
return commitable ? 0 : 1;
1199+
return committable ? 0 : 1;
11971200
}
11981201

11991202
define_list_config_array_extra(color_status_slots, {"added"});
@@ -1295,6 +1298,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
12951298
static int no_renames = -1;
12961299
static const char *rename_score_arg = (const char *)-1;
12971300
static struct wt_status s;
1301+
struct wt_status_state state;
12981302
int fd;
12991303
struct object_id oid;
13001304
static struct option builtin_status_options[] = {
@@ -1379,15 +1383,17 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13791383
s.rename_score = parse_rename_score(&rename_score_arg);
13801384
}
13811385

1382-
wt_status_collect(&s);
1386+
wt_status_get_state(&s, &state);
1387+
wt_status_collect(&s, &state);
13831388

13841389
if (0 <= fd)
13851390
update_index_if_able(&the_index, &index_lock);
13861391

13871392
if (s.relative_paths)
13881393
s.prefix = prefix;
13891394

1390-
wt_status_print(&s);
1395+
wt_status_print(&s, &state);
1396+
wt_status_clear_state(&state);
13911397
return 0;
13921398
}
13931399

Diff for: ref-filter.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -1408,8 +1408,7 @@ char *get_head_description(void)
14081408
{
14091409
struct strbuf desc = STRBUF_INIT;
14101410
struct wt_status_state state;
1411-
memset(&state, 0, sizeof(state));
1412-
wt_status_get_state(&state, 1);
1411+
wt_status_get_state(NULL, &state);
14131412
if (state.rebase_in_progress ||
14141413
state.rebase_interactive_in_progress) {
14151414
if (state.branch)

Diff for: t/t7501-commit.sh

+42-7
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ test_expect_success '--dry-run with stuff to commit returns ok' '
9999
git commit -m next -a --dry-run
100100
'
101101

102-
test_expect_failure '--short with stuff to commit returns ok' '
102+
test_expect_success '--short with stuff to commit returns ok' '
103103
echo bongo bongo bongo >>file &&
104104
git commit -m next -a --short
105105
'
106106

107-
test_expect_failure '--porcelain with stuff to commit returns ok' '
107+
test_expect_success '--porcelain with stuff to commit returns ok' '
108108
echo bongo bongo bongo >>file &&
109109
git commit -m next -a --porcelain
110110
'
@@ -664,7 +664,8 @@ test_expect_success '--only works on to-be-born branch' '
664664
test_cmp expected actual
665665
'
666666

667-
test_expect_success '--dry-run with conflicts fixed from a merge' '
667+
# set up env for tests of --dry-run given fixed/unfixed merge conflicts
668+
test_expect_success 'setup env with unfixed merge conflicts' '
668669
# setup two branches with conflicting information
669670
# in the same file, resolve the conflict,
670671
# call commit with --dry-run
@@ -677,11 +678,45 @@ test_expect_success '--dry-run with conflicts fixed from a merge' '
677678
git checkout -b branch-2 HEAD^1 &&
678679
echo "commit-2-state" >test-file &&
679680
git commit -m "commit 2" -i test-file &&
680-
! $(git merge --no-commit commit-1) &&
681-
echo "commit-2-state" >test-file &&
681+
test_expect_code 1 git merge --no-commit commit-1
682+
'
683+
684+
test_expect_success '--dry-run with unfixed merge conflicts' '
685+
test_expect_code 1 git commit --dry-run
686+
'
687+
688+
test_expect_success '--short with unfixed merge conflicts' '
689+
test_expect_code 1 git commit --short
690+
'
691+
692+
test_expect_success '--porcelain with unfixed merge conflicts' '
693+
test_expect_code 1 git commit --porcelain
694+
'
695+
696+
test_expect_success '--long with unfixed merge conflicts' '
697+
test_expect_code 1 git commit --long
698+
'
699+
700+
test_expect_success '--dry-run with conflicts fixed from a merge' '
701+
echo "merge-conflicts-fixed" >test-file &&
682702
git add test-file &&
683-
git commit --dry-run &&
684-
git commit -m "conflicts fixed from merge."
703+
git commit --dry-run
704+
'
705+
706+
test_expect_success '--short with conflicts fixed from a merge' '
707+
git commit --short
708+
'
709+
710+
test_expect_success '--porcelain with conflicts fixed from a merge' '
711+
git commit --porcelain
712+
'
713+
714+
test_expect_success '--long with conflicts fixed from a merge' '
715+
git commit --long
716+
'
717+
718+
test_expect_success '--message with conflicts fixed from a merge' '
719+
git commit --message "conflicts fixed from merge."
685720
'
686721

687722
test_done

0 commit comments

Comments
 (0)