Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions src/status.c
Original file line number Diff line number Diff line change
Expand Up @@ -575,14 +575,22 @@ status_update_write(struct io *io, struct status *status, enum line_type type)
}
}

static bool
status_is_untracked_dir(const struct status *status, enum line_type type)
{
const char *name = status->new.name;

return type == LINE_STAT_UNTRACKED && !suffixcmp(name, strlen(name), "/");
}

bool
status_update_file(struct status *status, enum line_type type)
{
const char *name = status->new.name;
struct io io;
bool result;

if (type == LINE_STAT_UNTRACKED && !suffixcmp(name, strlen(name), "/")) {
if (status_is_untracked_dir(status, type)) {
const char *add_argv[] = { "git", "add", "--", name, NULL };

return io_run_bg(add_argv, repo.exec_dir);
Expand All @@ -606,17 +614,31 @@ status_update_files(struct view *view, struct line *line)
int file, done;
int cursor_y = -1, cursor_x = -1;

/* Stage collapsed directories before opening the update-index batch. */
for (pos = line; view_has_line(view, pos) && pos->data; pos++) {
if (status_is_untracked_dir(pos->data, pos->type)) {
if (!status_update_file(pos->data, pos->type))
return false;
} else {
files++;
}
}

if (!files)
return true;

if (!status_update_prepare(&io, line->type))
return false;

for (pos = line; view_has_line(view, pos) && pos->data; pos++)
files++;

string_copy(buf, view->ref);
get_cursor_pos(cursor_y, cursor_x);
for (file = 0, done = 5; result && file < files; line++, file++) {
int almost_done = file * 100 / files;
for (file = 0, done = 5; result && file < files; line++) {
int almost_done;

if (status_is_untracked_dir(line->data, line->type))
continue;

almost_done = file * 100 / files;
if (almost_done > done && view_is_displayed(view)) {
done = almost_done;
string_format(view->ref, "updating file %d of %d (%d%% done)",
Expand All @@ -626,6 +648,7 @@ status_update_files(struct view *view, struct line *line)
doupdate();
}
result = status_update_write(&io, line->data, line->type);
file++;
}
string_copy(view->ref, buf);

Expand Down
24 changes: 24 additions & 0 deletions test/status/stage-untracked-dirs-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh

. libtest.sh

tigrc <<EOF
set status-show-untracked-dirs = no
EOF

steps '
:6
:status-update
'

in_work_dir git init -q .
in_work_dir mkdir 'new dir'
in_work_dir touch 'new dir/file' standalone

test_tig status

in_work_dir git ls-files > staged
assert_equals 'staged' strict <<EOF
new dir/file
standalone
EOF
Loading