23
GIT_COLOR_GREEN, /* WT_STATUS_LOCAL_BRANCH */
24
GIT_COLOR_RED, /* WT_STATUS_REMOTE_BRANCH */
25
GIT_COLOR_NIL, /* WT_STATUS_ONBRANCH */
26
+ GIT_COLOR_NORMAL, /* WT_STATUS_IN_PROGRESS */
27
};
28
29
static const char *color(int slot, struct wt_status *s)
729
color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
730
}
731
732
+static int has_unmerged(struct wt_status *s)
733
+{
734
+ int i;
735
+
736
+ for (i = 0; i < s->change.nr; i++) {
737
+ struct wt_status_change_data *d;
738
+ d = s->change.items[i].util;
739
+ if (d->stagemask)
740
+ return 1;
741
+ }
742
+ return 0;
743
+}
744
+
745
+static void show_merge_in_progress(struct wt_status *s,
746
+ struct wt_status_state *state,
747
+ const char *color)
748
+{
749
+ if (has_unmerged(s)) {
750
+ status_printf_ln(s, color, _("You have unmerged paths."));
751
+ if (advice_status_hints)
752
+ status_printf_ln(s, color,
753
+ _(" (fix conflicts and run \"git commit\")"));
754
+ } else {
755
+ status_printf_ln(s, color,
756
+ _("All conflicts fixed but you are still merging."));
757
+ if (advice_status_hints)
758
+ status_printf_ln(s, color,
759
+ _(" (use \"git commit\" to conclude merge)"));
760
+ }
761
+ wt_status_print_trailer(s);
762
+}
763
+
764
+static void show_am_in_progress(struct wt_status *s,
765
+ struct wt_status_state *state,
766
+ const char *color)
767
+{
768
+ status_printf_ln(s, color,
769
+ _("You are in the middle of an am session."));
770
+ if (state->am_empty_patch)
771
+ status_printf_ln(s, color,
772
+ _("The current patch is empty."));
773
+ if (advice_status_hints) {
774
+ if (!state->am_empty_patch)
775
+ status_printf_ln(s, color,
776
+ _(" (fix conflicts and then run \"git am --resolved\")"));
777
+ status_printf_ln(s, color,
778
+ _(" (use \"git am --skip\" to skip this patch)"));
779
+ status_printf_ln(s, color,
780
+ _(" (use \"git am --abort\" to restore the original branch)"));
781
+ }
782
+ wt_status_print_trailer(s);
783
+}
784
+
785
+static void show_rebase_in_progress(struct wt_status *s,
786
+ struct wt_status_state *state,
787
+ const char *color)
788
+{
789
+ struct stat st;
790
+
791
+ if (has_unmerged(s)) {
792
+ status_printf_ln(s, color, _("You are currently rebasing."));
793
+ if (advice_status_hints) {
794
+ status_printf_ln(s, color,
795
+ _(" (fix conflicts and then run \"git rebase --continue\")"));
796
+ status_printf_ln(s, color,
797
+ _(" (use \"git rebase --skip\" to skip this patch)"));
798
+ status_printf_ln(s, color,
799
+ _(" (use \"git rebase --abort\" to check out the original branch)"));
800
+ }
801
+ } else if (state->rebase_in_progress || !stat(git_path("MERGE_MSG"), &st)) {
802
+ status_printf_ln(s, color, _("You are currently rebasing."));
803
+ if (advice_status_hints)
804
+ status_printf_ln(s, color,
805
+ _(" (all conflicts fixed: run \"git rebase --continue\")"));
806
+ } else {
807
+ status_printf_ln(s, color, _("You are currently editing a commit during a rebase."));
808
+ if (advice_status_hints && !s->amend) {
809
+ status_printf_ln(s, color,
810
+ _(" (use \"git commit --amend\" to amend the current commit)"));
811
+ status_printf_ln(s, color,
812
+ _(" (use \"git rebase --continue\" once you are satisfied with your changes)"));
813
+ }
814
+ }
815
+ wt_status_print_trailer(s);
816
+}
817
+
818
+static void show_cherry_pick_in_progress(struct wt_status *s,
819
+ struct wt_status_state *state,
820
+ const char *color)
821
+{
822
+ status_printf_ln(s, color, _("You are currently cherry-picking."));
823
+ if (advice_status_hints) {
824
+ if (has_unmerged(s))
825
+ status_printf_ln(s, color,
826
+ _(" (fix conflicts and run \"git commit\")"));
827
+ else
828
+ status_printf_ln(s, color,
829
+ _(" (all conflicts fixed: run \"git commit\")"));
830
+ }
831
+ wt_status_print_trailer(s);
832
+}
833
+
834
+static void show_bisect_in_progress(struct wt_status *s,
835
+ struct wt_status_state *state,
836
+ const char *color)
837
+{
838
+ status_printf_ln(s, color, _("You are currently bisecting."));
839
+ if (advice_status_hints)
840
+ status_printf_ln(s, color,
841
+ _(" (use \"git bisect reset\" to get back to the original branch)"));
842
+ wt_status_print_trailer(s);
843
+}
844
+
845
+static void wt_status_print_state(struct wt_status *s)
846
+{
847
+ const char *state_color = color(WT_STATUS_IN_PROGRESS, s);
848
+ struct wt_status_state state;
849
+ struct stat st;
850
+
851
+ memset(&state, 0, sizeof(state));
852
+
853
+ if (!stat(git_path("MERGE_HEAD"), &st)) {
854
+ state.merge_in_progress = 1;
855
+ } else if (!stat(git_path("rebase-apply"), &st)) {
856
+ if (!stat(git_path("rebase-apply/applying"), &st)) {
857
+ state.am_in_progress = 1;
858
+ if (!stat(git_path("rebase-apply/patch"), &st) && !st.st_size)
859
+ state.am_empty_patch = 1;
860
+ } else {
861
+ state.rebase_in_progress = 1;
862
+ }
863
+ } else if (!stat(git_path("rebase-merge"), &st)) {
864
+ if (!stat(git_path("rebase-merge/interactive"), &st))
865
+ state.rebase_interactive_in_progress = 1;
866
+ else
867
+ state.rebase_in_progress = 1;
868
+ } else if (!stat(git_path("CHERRY_PICK_HEAD"), &st)) {
869
+ state.cherry_pick_in_progress = 1;
870
+ }
871
+ if (!stat(git_path("BISECT_LOG"), &st))
872
+ state.bisect_in_progress = 1;
873
+
874
+ if (state.merge_in_progress)
875
+ show_merge_in_progress(s, &state, state_color);
876
+ else if (state.am_in_progress)
877
+ show_am_in_progress(s, &state, state_color);
878
+ else if (state.rebase_in_progress || state.rebase_interactive_in_progress)
879
+ show_rebase_in_progress(s, &state, state_color);
880
+ else if (state.cherry_pick_in_progress)
881
+ show_cherry_pick_in_progress(s, &state, state_color);
882
+ if (state.bisect_in_progress)
883
+ show_bisect_in_progress(s, &state, state_color);
884
+}
885
+
886
void wt_status_print(struct wt_status *s)
887
{
888
const char *branch_color = color(WT_STATUS_ONBRANCH, s);
905
wt_status_print_tracking(s);
906
}
907
908
+ wt_status_print_state(s);
909
if (s->is_initial) {
910
status_printf_ln(s, color(WT_STATUS_HEADER, s), "");
911
status_printf_ln(s, color(WT_STATUS_HEADER, s), _("Initial commit"));