Some of the feedback of folks trying out sparse-checkouts at $dayjob is that sparse checkouts can sometimes be disorienting; users can forget that they had a sparse-checkout and then wonder where files went. This series adds some output to 'git status' and modifies git-prompt slightly as an attempt to help. Note that as per discussion on v1, we may want to later add a git sparse-checkout subcommand named something like 'stats' or 'info' or 'status' that provides more detailed information for users to dig deeper. That would be an additional improvement for helping users find out more information once they realize or remember they are in a sparse checkout, this is just aimed at giving them a simple reminder. Changes since v1: * Replaced the -1 magic constant with SPARSE_CHECKOUT_DISABLED * Fixed a possible division by 0 (when there are no entries in the index AND sparse checkout is enabled; not sure when that'd ever happen but still better to guard against...) * Slight wording tweaks for the git-prompt commit message * Removed the RFC label Elijah Newren (2): wt-status: show sparse checkout status as well git-prompt: include sparsity state as well contrib/completion/git-prompt.sh | 7 +++++- wt-status.c | 41 ++++++++++++++++++++++++++++++++ wt-status.h | 2 ++ 3 files changed, 49 insertions(+), 1 deletion(-) base-commit: b3d7a52fac39193503a0b6728771d1bf6a161464 Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-808%2Fnewren%2Fsparse-checkout-status-v2 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-808/newren/sparse-checkout-status-v2 Pull-Request: https://github.com/git/git/pull/808 Range-diff vs v1: 1: 462cee857ef ! 1: e266bc39d99 [RFC] wt-status: show sparse checkout status as well @@ Metadata Author: Elijah Newren <newren@xxxxxxxxx> ## Commit message ## - [RFC] wt-status: show sparse checkout status as well + wt-status: show sparse checkout status as well Some of the early feedback of folks trying out sparse-checkouts at $dayjob is that sparse checkouts can sometimes be disorienting; users @@ wt-status.c: static void show_bisect_in_progress(struct wt_status *s, +static void show_sparse_checkout_in_use(struct wt_status *s, + const char *color) +{ -+ if (s->state.sparse_checkout_percentage != -1) -+ status_printf_ln(s, color, -+ _("You are in a sparse checkout with %d%% of tracked files present."), -+ s->state.sparse_checkout_percentage); ++ if (s->state.sparse_checkout_percentage == SPARSE_CHECKOUT_DISABLED) ++ return; ++ ++ status_printf_ln(s, color, ++ _("You are in a sparse checkout with %d%% of tracked files present."), ++ s->state.sparse_checkout_percentage); + wt_longstatus_print_trailer(s); +} + @@ wt-status.c: int wt_status_check_bisect(const struct worktree *wt, + int skip_worktree = 0; + int i; + -+ if (!core_apply_sparse_checkout) { -+ state->sparse_checkout_percentage = -1; ++ if (!core_apply_sparse_checkout || r->index->cache_nr == 0) { ++ /* ++ * Don't compute percentage of checked out files if we ++ * aren't in a sparse checkout or would get division by 0. ++ */ ++ state->sparse_checkout_percentage = SPARSE_CHECKOUT_DISABLED; + return; + } + @@ wt-status.c: static void wt_longstatus_print_state(struct wt_status *s) if (state->bisect_in_progress) show_bisect_in_progress(s, state_color); + -+ if (state->sparse_checkout_percentage != -1) ++ if (state->sparse_checkout_percentage != SPARSE_CHECKOUT_DISABLED) + show_sparse_checkout_in_use(s, state_color); } static void wt_longstatus_print(struct wt_status *s) ## wt-status.h ## +@@ wt-status.h: enum wt_status_format { + + #define HEAD_DETACHED_AT _("HEAD detached at ") + #define HEAD_DETACHED_FROM _("HEAD detached from ") ++#define SPARSE_CHECKOUT_DISABLED -1 + + struct wt_status_state { + int merge_in_progress; @@ wt-status.h: struct wt_status_state { int bisect_in_progress; int revert_in_progress; int detached_at; -+ int sparse_checkout_percentage; /* -1 == not in sparse checkout */ ++ int sparse_checkout_percentage; /* SPARSE_CHECKOUT_DISABLED if not sparse */ char *branch; char *onto; char *detached_from; 2: 64613ad7ad6 ! 2: 17254b30a5b [RFC] git-prompt: include sparsity state as well @@ Metadata Author: Elijah Newren <newren@xxxxxxxxx> ## Commit message ## - [RFC] git-prompt: include sparsity state as well + git-prompt: include sparsity state as well - The current git prompt includes a lot of possible state information, from - various flavors of rebases to cherry-picks, or merges, or bisects. Add + The current git prompt includes a lot of possible state information from + cherry-picks, merges, bisects, and various flavors of rebases. Add sparsity as another state flavor (though one which can be present simultaneously with any of rebase/cherry-pick/merge/bisect). This extra state is shown with an extra |SPARSE - substring before the other states. (Sparsity is probably not going to - change much within a repository, while temporary operations will. So we - want the temporary operation related state changes to be listed last, to - make them appear closer to where the user types and make them more - likely to be noticed.) Thus, for example, the prompt might look like: + substring before the other states, providing a prompt that looks like: (branchname|SPARSE|REBASE 6/10) + The reason for showing the "|SPARSE" substring before other states is to + emphasize those other states. Sparsity is probably not going to change + much within a repository, while temporary operations will. So we want + the state changes related to temporary operations to be listed last, to + make them appear closer to where the user types and make them more + likely to be noticed. + Signed-off-by: Elijah Newren <newren@xxxxxxxxx> ## contrib/completion/git-prompt.sh ## -- gitgitgadget