From 2745085087f77b6dffc5d227e53ceef93ec7a3dd Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Sun, 5 Feb 2017 22:38:18 -0500 Subject: [PATCH] Add options to not show untracked files in the status view Fixes #562 --- NEWS.adoc | 9 ++++ doc/tigrc.5.adoc | 7 +++- include/tig/options.h | 3 +- src/options.c | 72 ++++++++++++++++++++++---------- src/status.c | 26 +++++++++--- src/tig.c | 2 +- test/status/untracked-files-test | 27 ++++++++++++ test/tigrc/compat-error-test | 5 ++- tigrc | 3 +- 9 files changed, 121 insertions(+), 33 deletions(-) diff --git a/NEWS.adoc b/NEWS.adoc index c6341a17f..d2708adea 100644 --- a/NEWS.adoc +++ b/NEWS.adoc @@ -4,10 +4,19 @@ Release notes master ------ +Upgrade instructions: + + - The `status-untracked-dirs` option was renamed to + `status-show-untracked-dirs` to match the new `status-show-untracked-files` + option. + Improvements: - Use `diff-options` when preparing the diff in the stage view to make the diff state configurable. (GH #545) + - Add 'status-show-untracked-files' option mirroring git's + 'status.showUntrackedFiles' to toggle display of untracked files. in the + status view. On by default. (GH #562) Bug fixes: diff --git a/doc/tigrc.5.adoc b/doc/tigrc.5.adoc index fbddda8a4..3824aab01 100644 --- a/doc/tigrc.5.adoc +++ b/doc/tigrc.5.adoc @@ -237,11 +237,16 @@ The following variables can be set: ensured that the smaller of the views is at least four columns wide. The default is '50%'. -'status-untracked-dirs' (bool):: +'status-show-untracked-dirs' (bool):: Show untracked directories contents in the status view (analog to `git ls-files --directory` option). On by default. +'status-show-untracked-files' (bool):: + + Show untracked files in the status view (mirrors git's + `status.showUntrackedFiles` option). On by default. + 'tab-size' (int):: Number of spaces per tab. The default is 8 spaces. diff --git a/include/tig/options.h b/include/tig/options.h index 5b46c4d50..737672709 100644 --- a/include/tig/options.h +++ b/include/tig/options.h @@ -70,7 +70,8 @@ typedef struct view_column *view_settings; _(split_view_width, double, VIEW_RESET_DISPLAY) \ _(stage_view, view_settings, VIEW_NO_FLAGS) \ _(stash_view, view_settings, VIEW_NO_FLAGS) \ - _(status_untracked_dirs, bool, VIEW_STATUS_LIKE) \ + _(status_show_untracked_dirs, bool, VIEW_STATUS_LIKE) \ + _(status_show_untracked_files, bool, VIEW_STATUS_LIKE) \ _(status_view, view_settings, VIEW_NO_FLAGS) \ _(tab_size, int, VIEW_NO_FLAGS) \ _(tree_view, view_settings, VIEW_NO_FLAGS) \ diff --git a/src/options.c b/src/options.c index dfbf013c0..366a59dc1 100644 --- a/src/options.c +++ b/src/options.c @@ -679,12 +679,38 @@ parse_view_settings(struct view_column **view_column, const char *name_, const c return parse_view_config(view_column, name, argv); } +static enum status_code +option_update(struct option_info *option, int argc, const char *argv[]) +{ + enum status_code code; + + if (option->seen) + return SUCCESS; + + if (!strcmp(option->type, "const char **")) + return parse_args(option->value, argv + 2); + + if (argc < 3) + return error("Invalid set command: set option = value"); + + if (!strcmp(option->type, "view_settings")) + return parse_view_settings(option->value, argv[0], argv + 2); + + if (!strcmp(option->type, "struct ref_format **")) + return parse_ref_formats(option->value, argv + 2); + + code = parse_option(option, "", argv[2]); + if (code == SUCCESS && argc != 3) + return error("Option %s only takes one value", argv[0]); + + return code; +} + /* Wants: name = value */ static enum status_code option_set_command(int argc, const char *argv[]) { struct option_info *option; - enum status_code code; if (argc < 2) return error("Invalid set command: set option = value"); @@ -693,28 +719,26 @@ option_set_command(int argc, const char *argv[]) return error("No value assigned to %s", argv[0]); option = find_option_info(option_info, ARRAY_SIZE(option_info), "", argv[0]); - if (option) { - if (option->seen) - return SUCCESS; - - if (!strcmp(option->type, "const char **")) - return parse_args(option->value, argv + 2); - - if (argc < 3) - return error("Invalid set command: set option = value"); - - if (!strcmp(option->type, "view_settings")) - return parse_view_settings(option->value, argv[0], argv + 2); - - if (!strcmp(option->type, "struct ref_format **")) - return parse_ref_formats(option->value, argv + 2); - - code = parse_option(option, "", argv[2]); - if (code == SUCCESS && argc != 3) - return error("Option %s only takes one value", argv[0]); + if (option) + return option_update(option, argc, argv); - return code; + { + const char *obsolete[][2] = { + { "status-untracked-dirs", "status-show-untracked-dirs" }, + }; + int index = find_remapped(obsolete, ARRAY_SIZE(obsolete), argv[0]); + if (index != -1) { + option = find_option_info(option_info, ARRAY_SIZE(option_info), "", obsolete[index][1]); + if (option) { + enum status_code code = option_update(option, argc, argv); + + if (code != SUCCESS) + return code; + return error("%s has been renamed to %s", + obsolete[index][0], obsolete[index][1]); + } + } } { @@ -788,6 +812,7 @@ option_bind_command(int argc, const char *argv[]) { "diff-context-down", "diff-context" }, { "diff-context-up", "diff-context" }, { "stage-next", ":/^@@" }, + { "status-untracked-dirs", "status-show-untracked-dirs" }, { "toggle-author", "author" }, { "toggle-changes", "show-changes" }, { "toggle-commit-order", "show-commit-order" }, @@ -806,7 +831,7 @@ option_bind_command(int argc, const char *argv[]) { "toggle-sort-field", "sort-field" }, { "toggle-sort-order", "sort-order" }, { "toggle-title-overflow", "commit-title-overflow" }, - { "toggle-untracked-dirs", "status-untracked-dirs" }, + { "toggle-untracked-dirs", "status-show-untracked-dirs" }, { "toggle-vertical-split", "show-vertical-split" }, }; int alias; @@ -1413,6 +1438,9 @@ read_repo_config_option(char *name, size_t namelen, char *value, size_t valuelen else if (!strcmp(name, "diff.noprefix")) parse_bool(&opt_diff_noprefix, value); + else if (!strcmp(name, "status.showUntrackedFiles")) + parse_bool(&opt_status_show_untracked_files, value); + else if (!prefixcmp(name, "tig.color.")) set_repo_config_option(name + 10, value, option_color_command); diff --git a/src/status.c b/src/status.c index 09a6e2654..be00f6921 100644 --- a/src/status.c +++ b/src/status.c @@ -332,6 +332,21 @@ status_update_onbranch(void) string_copy(status_onbranch, "Not currently on any branch"); } +static bool +status_read_untracked(struct view *view) +{ + if (!opt_status_show_untracked_files) + return add_line_nodata(view, LINE_STAT_UNTRACKED) + && add_line_nodata(view, LINE_STAT_NONE); + + status_list_other_argv[ARRAY_SIZE(status_list_other_argv) - 3] = + opt_status_show_untracked_dirs ? NULL : "--directory"; + status_list_other_argv[ARRAY_SIZE(status_list_other_argv) - 2] = + opt_status_show_untracked_dirs ? NULL : "--no-empty-directory"; + + return status_run(view, status_list_other_argv, '?', LINE_STAT_UNTRACKED); +} + /* First parse staged info using git-diff-index(1), then parse unstaged * info using git-diff-files(1), and finally untracked files using * git-ls-files(1). */ @@ -355,14 +370,9 @@ status_open(struct view *view, enum open_flags flags) update_index(); - status_list_other_argv[ARRAY_SIZE(status_list_other_argv) - 3] = - opt_status_untracked_dirs ? NULL : "--directory"; - status_list_other_argv[ARRAY_SIZE(status_list_other_argv) - 2] = - opt_status_untracked_dirs ? NULL : "--no-empty-directory"; - if (!status_run(view, staged_argv, staged_status, LINE_STAT_STAGED) || !status_run(view, status_diff_files_argv, 0, LINE_STAT_UNSTAGED) || - !status_run(view, status_list_other_argv, '?', LINE_STAT_UNTRACKED)) + !status_read_untracked(view)) return error("Failed to load status data"); /* Restore the exact position or use the specialized restore @@ -403,6 +413,10 @@ status_get_column_data(struct view *view, const struct line *line, struct view_c case LINE_STAT_NONE: type = LINE_DEFAULT; text = " (no files)"; + if (!opt_status_show_untracked_files + && view->line < line + && line[-1].type == LINE_STAT_UNTRACKED) + text = " (not shown)"; break; case LINE_HEADER: diff --git a/src/tig.c b/src/tig.c index 89ef4a5f3..7cd143ada 100644 --- a/src/tig.c +++ b/src/tig.c @@ -99,7 +99,7 @@ view_request(struct view *view, enum request request) _('X', "commit ID display", "id"), \ _('%', "file filtering", "file-filter"), \ _('$', "commit title overflow display", "commit-title-overflow"), \ - _('d', "untracked directory info", "status-untracked-dirs"), \ + _('d', "untracked directory info", "status-show-untracked-dirs"), \ _('|', "view split", "vertical-split"), \ static void diff --git a/test/status/untracked-files-test b/test/status/untracked-files-test index 6daa26cf3..1675cdc44 100755 --- a/test/status/untracked-files-test +++ b/test/status/untracked-files-test @@ -73,6 +73,33 @@ Untracked files: ? root.4 ? root.5 +[status] Nothing to update 100% +EXPECTED_SCREEN + +test_case 'status-show-untracked-files-option-off' \ + --args='status' \ + --script=':toggle status-show-untracked-files' \ +< {remote} ~replace~ # Settings controlling how content is read from Git set commit-order = auto # Enum: auto, default, topo, date, reverse (main) -set status-untracked-dirs = yes # Show files in untracked directories? (status) +set status-show-untracked-dirs = yes # Show files in untracked directories? (status) +set status-show-untracked-files = yes # Show untracked files? set ignore-space = no # Enum: no, all, some, at-eol (diff) set show-notes = yes # When non-bool passed as `--show-notes=...` (diff) #set diff-context = 3 # Number of lines to show around diff changes (diff)