wt-status.c: set the committable flag in the collect phase

In an update to fix a bug with "commit --dry-run" it was found that the committable flag was broken. The update was, at the time, accepted as it was better than the previous version. [1] Since the setting of the committable flag had been done in wt_longstatus_print_updated, move it to wt_status_collect_updated_cb. Set the committable flag in wt_status_collect_changes_initial to keep from introducing a rebase regression. Instead of setting the committable flag in show_merge_in_progress, in wt_status_cllect check for a merge that has not been committed. If present then set the committable flag. Change the tests to expect success since updates to the wt-status broken code section is being fixed. [1] https://public-inbox.org/git/xmqqr3gcj9i5.fsf@gitster.mtv.corp.google.com/ Signed-off-by: Stephen P. Smith <ischis2@cox.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stephen P. Smith committed Sep 5, 2018 at 17:53 UTC f3bd35fa0dd6fcc8aaab1f9281d98cee5add2e4f
2 files changed +14 -5
t/t7501-commit.sh
+3 -3
@@ -99,12 +99,12 @@ test_expect_success '--dry-run with stuff to commit returns ok' '
99 git commit -m next -a --dry-run
100 '
101
102 -test_expect_failure '--short with stuff to commit returns ok' '
102 +test_expect_success '--short with stuff to commit returns ok' '
103 echo bongo bongo bongo >>file &&
104 git commit -m next -a --short
105 '
106
107 -test_expect_failure '--porcelain with stuff to commit returns ok' '
107 +test_expect_success '--porcelain with stuff to commit returns ok' '
108 echo bongo bongo bongo >>file &&
109 git commit -m next -a --porcelain
110 '
@@ -682,7 +682,7 @@ test_expect_success '--dry-run with conflicts fixed from a merge' '
682 git commit -m "conflicts fixed from merge."
683 '
684
685 -test_expect_failure '--dry-run --short' '
685 +test_expect_success '--dry-run --short' '
686 >test-file &&
687 git add test-file &&
688 git commit --dry-run --short
wt-status.c
+11 -2
@@ -540,10 +540,12 @@ static void wt_status_collect_updated_cb(struct diff_queue_struct *q,
540 /* Leave {mode,oid}_head zero for an add. */
541 d->mode_index = p->two->mode;
542 oidcpy(&d->oid_index, &p->two->oid);
543 + s->committable = 1;
544 break;
545 case DIFF_STATUS_DELETED:
546 d->mode_head = p->one->mode;
547 oidcpy(&d->oid_head, &p->one->oid);
548 + s->committable = 1;
549 /* Leave {mode,oid}_index zero for a delete. */
550 break;
551
@@ -561,6 +563,7 @@ static void wt_status_collect_updated_cb(struct diff_queue_struct *q,
563 d->mode_index = p->two->mode;
564 oidcpy(&d->oid_head, &p->one->oid);
565 oidcpy(&d->oid_index, &p->two->oid);
566 + s->committable = 1;
567 break;
568 case DIFF_STATUS_UNMERGED:
569 d->stagemask = unmerged_mask(p->two->path);
@@ -665,11 +668,13 @@ static void wt_status_collect_changes_initial(struct wt_status *s)
668 * code will output the stage values directly and not use the
669 * values in these fields.
670 */
671 + s->committable = 1;
672 } else {
673 d->index_status = DIFF_STATUS_ADDED;
674 /* Leave {mode,oid}_head zero for adds. */
675 d->mode_index = ce->ce_mode;
676 oidcpy(&d->oid_index, &ce->oid);
677 + s->committable = 1;
678 }
679 }
680 }
@@ -739,6 +744,7 @@ static int has_unmerged(struct wt_status *s)
744
745 void wt_status_collect(struct wt_status *s)
746 {
747 + struct wt_status_state state;
748 wt_status_collect_changes_worktree(s);
749
750 if (s->is_initial)
@@ -746,6 +752,11 @@ void wt_status_collect(struct wt_status *s)
752 else
753 wt_status_collect_changes_index(s);
754 wt_status_collect_untracked(s);
755 +
756 + memset(&state, 0, sizeof(state));
757 + wt_status_get_state(&state, s->branch && !strcmp(s->branch, "HEAD"));
758 + if (state.merge_in_progress && !has_unmerged(s))
759 + s->committable = 1;
760 }
761
762 static void wt_longstatus_print_unmerged(struct wt_status *s)
@@ -786,7 +797,6 @@ static void wt_longstatus_print_updated(struct wt_status *s)
797 continue;
798 if (!shown_header) {
799 wt_longstatus_print_cached_header(s);
789 - s->committable = 1;
800 shown_header = 1;
801 }
802 wt_longstatus_print_change_data(s, WT_STATUS_UPDATED, it);
@@ -1089,7 +1099,6 @@ static void show_merge_in_progress(struct wt_status *s,
1099 _(" (use \"git merge --abort\" to abort the merge)"));
1100 }
1101 } else {
1092 - s-> committable = 1;
1102 status_printf_ln(s, color,
1103 _("All conflicts fixed but you are still merging."));
1104 if (s->hints)