Skip to content

Commit

Permalink
Add options to not show untracked files in the status view
Browse files Browse the repository at this point in the history
Fixes #562
  • Loading branch information
jonas committed Feb 6, 2017
1 parent cef17fc commit 2745085
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 33 deletions.
9 changes: 9 additions & 0 deletions NEWS.adoc
Expand Up @@ -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:

Expand Down
7 changes: 6 additions & 1 deletion doc/tigrc.5.adoc
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion include/tig/options.h
Expand Up @@ -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) \
Expand Down
72 changes: 50 additions & 22 deletions src/options.c
Expand Up @@ -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");
Expand All @@ -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]);
}
}
}

{
Expand Down Expand Up @@ -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" },
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
26 changes: 20 additions & 6 deletions src/status.c
Expand Up @@ -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). */
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/tig.c
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions test/status/untracked-files-test
Expand Up @@ -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' \
<<EXPECTED_SCREEN
On branch master
Changes to be committed:
(no files)
Changes not staged for commit:
M .j
M a
M b.c
M e/f
M g h
Untracked files:
(not shown)
[status] Nothing to update 100%
EXPECTED_SCREEN

Expand Down
5 changes: 4 additions & 1 deletion test/tigrc/compat-error-test
Expand Up @@ -78,6 +78,8 @@ set main-view-date = custom
set main-view-date-format = "%Y-%m-%d %H:%M"
set cmdline-args = --all
set status-untracked-dirs = true
EOF

steps ":quit"
Expand Down Expand Up @@ -122,7 +124,7 @@ tig warning: ~/.tigrc:46: toggle-id has been replaced by \`:toggle id'
tig warning: ~/.tigrc:47: toggle-files has been replaced by \`:toggle file-filter'
tig warning: ~/.tigrc:48: toggle-title-overflow has been replaced by \`:toggle commit-title-overflow'
tig warning: ~/.tigrc:49: toggle-file-size has been replaced by \`:toggle file-size'
tig warning: ~/.tigrc:50: toggle-untracked-dirs has been replaced by \`:toggle status-untracked-dirs'
tig warning: ~/.tigrc:50: toggle-untracked-dirs has been replaced by \`:toggle status-show-untracked-dirs'
tig warning: ~/.tigrc:53: main-revgraph is obsolete
tig warning: ~/.tigrc:56: tree-head has been replaced by tree.header
tig warning: ~/.tigrc:57: tree-dir has been replaced by tree.directory
Expand All @@ -133,5 +135,6 @@ tig warning: ~/.tigrc:61: help-keymap has been replaced by help.section
tig warning: ~/.tigrc:64: 'local' is no longer supported for date-display, use the 'date-local' column option
tig warning: ~/.tigrc:68: 'short' is no longer supported for date-display, use the 'custom' display mode and set 'date-format'
tig warning: ~/.tigrc:72: cmdline-args is obsolete; use view-specific options instead, e.g. main-options
tig warning: ~/.tigrc:74: status-untracked-dirs has been renamed to status-show-untracked-dirs
tig warning: Errors while loading HOME/.tigrc.
EOF
3 changes: 2 additions & 1 deletion tigrc
Expand Up @@ -90,7 +90,8 @@ set reference-format = [branch] <tag> {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)
Expand Down

0 comments on commit 2745085

Please sign in to comment.