Skip to content

Commit

Permalink
Show untracked files in the default view jonas#762
Browse files Browse the repository at this point in the history
  • Loading branch information
koutcher committed Dec 2, 2018
1 parent 2da9448 commit b2dc966
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 10 deletions.
4 changes: 4 additions & 0 deletions doc/tigrc.5.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ The following variables can be set:
reference is passed to `git show --notes=`. Notes are enabled by
default.
'show-untracked' (bool)::
Whether to show untracked changes in the main view.
'show-changes' (bool)::
Whether to show staged and unstaged changes in the main view.
Expand Down
1 change: 1 addition & 0 deletions include/tig/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct main_state {
bool first_parent;
bool add_changes_staged;
bool add_changes_unstaged;
bool add_changes_untracked;
};

bool main_get_column_data(struct view *view, const struct line *line, struct view_column_data *column_data);
Expand Down
1 change: 1 addition & 0 deletions include/tig/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ typedef struct view_column *view_settings;
_(send_child_enter, bool, VIEW_NO_FLAGS) \
_(show_changes, bool, VIEW_NO_FLAGS) \
_(show_notes, bool, VIEW_NO_FLAGS) \
_(show_untracked, bool, VIEW_NO_FLAGS) \
_(split_view_height, double, VIEW_RESET_DISPLAY) \
_(split_view_width, double, VIEW_RESET_DISPLAY) \
_(stage_view, view_settings, VIEW_NO_FLAGS) \
Expand Down
11 changes: 7 additions & 4 deletions include/tig/watch.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ enum watch_trigger {
WATCH_INDEX_STAGED_NO = 1 << 1,
WATCH_INDEX_UNSTAGED_YES = 1 << 2,
WATCH_INDEX_UNSTAGED_NO = 1 << 3,
WATCH_HEAD = 1 << 4,
WATCH_STASH = 1 << 5,
WATCH_REFS = 1 << 6,
WATCH_INDEX_UNTRACKED_YES = 1 << 4,
WATCH_INDEX_UNTRACKED_NO = 1 << 5,
WATCH_HEAD = 1 << 6,
WATCH_STASH = 1 << 7,
WATCH_REFS = 1 << 8,

WATCH_INDEX_STAGED = WATCH_INDEX_STAGED_YES | WATCH_INDEX_STAGED_NO,
WATCH_INDEX_UNSTAGED = WATCH_INDEX_UNSTAGED_YES | WATCH_INDEX_UNSTAGED_NO,
WATCH_INDEX = WATCH_INDEX_STAGED | WATCH_INDEX_UNSTAGED,
WATCH_INDEX_UNTRACKED = WATCH_INDEX_UNTRACKED_YES | WATCH_INDEX_UNTRACKED_NO,
WATCH_INDEX = WATCH_INDEX_STAGED | WATCH_INDEX_UNSTAGED | WATCH_INDEX_UNTRACKED,
};

struct watch {
Expand Down
29 changes: 24 additions & 5 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ main_status_exists(struct view *view, enum line_type type)
return true;
if (type == LINE_STAT_UNSTAGED && state->add_changes_unstaged)
return true;
if (type == LINE_STAT_UNTRACKED && state->add_changes_untracked)
return true;

return false;
}
Expand All @@ -60,9 +62,9 @@ main_register_commit(struct view *view, struct commit *commit, const char *ids,
string_copy_rev(commit->id, ids);

/* FIXME: lazily check index state here instead of in main_open. */
if ((state->add_changes_unstaged || state->add_changes_staged) && is_head_commit(commit->id)) {
if ((state->add_changes_untracked || state->add_changes_unstaged || state->add_changes_staged) && is_head_commit(commit->id)) {
main_add_changes(view, state, ids);
state->add_changes_unstaged = state->add_changes_staged = false;
state->add_changes_untracked = state->add_changes_unstaged = state->add_changes_staged = false;
}

if (state->with_graph)
Expand Down Expand Up @@ -147,9 +149,16 @@ main_check_index(struct view *view, struct main_state *state)
{
struct index_diff diff;

if (!index_diff(&diff, false, false))
if (!index_diff(&diff, opt_show_untracked, false))
return false;

if (!diff.untracked) {
watch_apply(&view->watch, WATCH_INDEX_UNTRACKED_NO);
} else {
watch_apply(&view->watch, WATCH_INDEX_UNTRACKED_YES);
state->add_changes_untracked = true;
}

if (!diff.unstaged) {
watch_apply(&view->watch, WATCH_INDEX_UNSTAGED_NO);
} else {
Expand All @@ -172,6 +181,7 @@ main_add_changes(struct view *view, struct main_state *state, const char *parent
{
const char *staged_parent = parent;
const char *unstaged_parent = NULL_ID;
const char *untracked_parent = NULL_ID;

if (!state->add_changes_staged) {
staged_parent = NULL;
Expand All @@ -180,9 +190,16 @@ main_add_changes(struct view *view, struct main_state *state, const char *parent

if (!state->add_changes_unstaged) {
unstaged_parent = NULL;
if (!state->add_changes_staged)
untracked_parent = parent;
}

if (!state->add_changes_untracked) {
untracked_parent = NULL;
}

return main_add_changes_commit(view, LINE_STAT_UNSTAGED, unstaged_parent, "Unstaged changes")
return main_add_changes_commit(view, LINE_STAT_UNTRACKED, untracked_parent, "Untracked changes")
&& main_add_changes_commit(view, LINE_STAT_UNSTAGED, unstaged_parent, "Unstaged changes")
&& main_add_changes_commit(view, LINE_STAT_STAGED, staged_parent, "Staged changes");
}

Expand Down Expand Up @@ -528,6 +545,8 @@ main_request(struct view *view, enum request request, struct line *line)
if (line->type == LINE_STAT_UNSTAGED
|| line->type == LINE_STAT_STAGED)
open_stage_view(view, NULL, line->type, flags);
else if (line->type == LINE_STAT_UNTRACKED)
open_status_view(view, flags);
else
open_diff_view(view, flags);
break;
Expand Down Expand Up @@ -558,7 +577,7 @@ main_select(struct view *view, struct line *line)
{
struct commit *commit = line->data;

if (line->type == LINE_STAT_STAGED || line->type == LINE_STAT_UNSTAGED) {
if (line->type == LINE_STAT_STAGED || line->type == LINE_STAT_UNSTAGED || line->type == LINE_STAT_UNTRACKED) {
string_ncopy(view->ref, commit->title, strlen(commit->title));
status_stage_info(view->env->status, line->type, NULL);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/repo.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ index_diff(struct index_diff *diff, bool untracked, bool count_all)
/* Ignore staged but unmerged entries. */
else if (buf.data[0] != ' ' && buf.data[0] != 'U')
diff->staged++;
if (buf.data[1] != ' ')
if (buf.data[1] != ' ' && buf.data[1] != '?')
diff->unstaged++;
if (!count_all && diff->staged && diff->unstaged &&
(!untracked || diff->untracked))
Expand Down
1 change: 1 addition & 0 deletions test/diff/editor-test
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
. libgit.sh

tigrc <<EOF
set show-untracked = no
set line-graphics = ascii
set diff-view-line-number = yes
set stage-view-line-number = yes
Expand Down
1 change: 1 addition & 0 deletions test/diff/submodule-editor-test
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ executable exec-env <<EOF
EOF

tigrc <<EOF
set show-untracked = no
set line-graphics = ascii
set diff-view-line-number = yes
set stage-view-line-number = yes
Expand Down
1 change: 1 addition & 0 deletions test/diff/worktree-editor-test
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ executable exec-env <<EOF
EOF

tigrc <<EOF
set show-untracked = no
set line-graphics = ascii
set diff-view-line-number = yes
set stage-view-line-number = yes
Expand Down
1 change: 1 addition & 0 deletions test/main/mailmap-test
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Full Throttle <[email protected]> Max Power <[email protected]>"
EOF

tigrc <<EOF
set show-untracked = no
set mailmap = yes
# set diff-options = --use-mailmap
# set main-options = --use-mailmap
Expand Down
67 changes: 67 additions & 0 deletions test/main/untracked-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/sh

. libtest.sh
. libgit.sh
. "$source_dir/util.sh"

export LINES=20

steps '
:save-display start.screen
<Enter>
:save-display result.screen
'

tigrc <<EOF
set vertical-split = no
EOF

in_work_dir create_dirty_workdir
in_work_dir git add .j
in_work_dir touch z

test_tig

assert_equals 'start.screen' <<EOF
$YYY_MM_DD_HH_MM +0000 Unknown o Untracked changes
$YYY_MM_DD_HH_MM +0000 Unknown o Unstaged changes
$YYY_MM_DD_HH_MM +0000 Unknown o Staged changes
2009-02-13 23:31 +0000 A. U. Thor I [master] Initial commit
[main] Untracked changes 100%
EOF

assert_equals 'result.screen' <<EOF
$YYY_MM_DD_HH_MM +0000 Unknown o Untracked changes
$YYY_MM_DD_HH_MM +0000 Unknown o Unstaged changes
$YYY_MM_DD_HH_MM +0000 Unknown o Staged changes
2009-02-13 23:31 +0000 A. U. Thor I [master] Initial commit
[main] Untracked changes 100%
On branch master
Changes to be committed:
M .j
Changes not staged for commit:
M a
M b.c
M e/f
M g h
Untracked files:
? z
[status] Nothing to update 100%
EOF
1 change: 1 addition & 0 deletions tigrc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ set blob-view = line-number:no,interval=5 text
set diff-view = line-number:no,interval=5 text:yes,commit-title-overflow=no

# UI display settings
set show-untracked = yes # Show untracked commit in the main view?
set show-changes = yes # Show changes commits in the main view?
set wrap-lines = no # Wrap long lines in pager views?
set tab-size = 8 # Number of spaces to use when expanding tabs
Expand Down

0 comments on commit b2dc966

Please sign in to comment.