From: Leila Muhtasib <muhtasib@gmail.com>
To: git@vger.kernel.org
Cc: Leila Muhtasib <muhtasib@gmail.com>
Subject: [PATCH] git-status: Show empty directories
Date: Sat, 9 Jun 2012 15:40:06 -0400 [thread overview]
Message-ID: <1339270806-65013-1-git-send-email-muhtasib@gmail.com> (raw)
git-status now lists empty directories under the untracked header. Before this
modification, git status did not list empty directories. The header changed
from 'Untracked files' to instead display 'Untracked files and directories'.
A helpful reminder is also added after empty directories indicating they cannot
be added/staged if they are empty. git status -u is unchanged, and will still
only show untracked files just as before. As a result, no need for
documentation change.
Empty dirs are work in progress. They result because of one of the following:
user forgot to add files to dir, user forgot to clean up dir, user under
impression dir is staged and will be committed or is already committed. Last
item might occur as some users setup project and dir structures before adding files.
So this patch servers as a helpful reminder to users that they have an empty dir
so they can act upon it. Plus it clarifies git behavior to the user that empty
dirs can't be tracked.
Signed-off-by: Leila Muhtasib <muhtasib@gmail.com>
---
I ran into this issue myself where I thought my dir was already tracked, and
when I googled and found other people were confused and asking the same question.
Why don't empty dirs appear under git status when they aren't tracked? So I came
up with this patch.
In my commit message, I compiled a list of arguments in favor of this patch.
But I've also thought about arguments against, however I didn't think they were
compelling enough to not have this patch. So I've also included my own rebuttal
below :)
1) Direcories can't be tracked, so why show them under untracked?
Because it is a helpful reminder. See reasons in the commit message above for
how it is helpful. This would make git more user friendly.
Plus untracked does not mean 'it can be tracked', it just means it's not currently
tracked by git.
2) Empty directories should be ignored
If someone really wants to ignore something, they can put it in the .gitignore
file. Otherwise, the benefits above out weight this.
wt-status.c | 24 +++++++++++++++++++-----
1 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/wt-status.c b/wt-status.c
index 9ffc535..81bf1aa 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -184,7 +184,12 @@ static void wt_status_print_other_header(struct wt_status *s,
const char *how)
{
const char *c = color(WT_STATUS_HEADER, s);
- status_printf_ln(s, c, _("%s files:"), what);
+
+ if (s->show_untracked_files == SHOW_NORMAL_UNTRACKED_FILES)
+ status_printf_ln(s, c, _("%s files and directories:"), what);
+ else if (s->show_untracked_files == SHOW_ALL_UNTRACKED_FILES)
+ status_printf_ln(s, c, _("%s files:"), what);
+
if (!advice_status_hints)
return;
status_printf_ln(s, c, _(" (use \"git %s <file>...\" to include in what will be committed)"), how);
@@ -464,16 +469,25 @@ static void wt_status_collect_untracked(struct wt_status *s)
return;
memset(&dir, 0, sizeof(dir));
if (s->show_untracked_files != SHOW_ALL_UNTRACKED_FILES)
- dir.flags |=
- DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES;
+ dir.flags |=
+ DIR_SHOW_OTHER_DIRECTORIES;
setup_standard_excludes(&dir);
fill_directory(&dir, s->pathspec);
for (i = 0; i < dir.nr; i++) {
struct dir_entry *ent = dir.entries[i];
if (cache_name_is_other(ent->name, ent->len) &&
- match_pathspec(s->pathspec, ent->name, ent->len, 0, NULL))
- string_list_insert(&s->untracked, ent->name);
+ match_pathspec(s->pathspec, ent->name, ent->len, 0, NULL)) {
+ if (is_empty_dir(ent->name)) {
+ struct strbuf buf_name = STRBUF_INIT;
+ strbuf_addstr(&buf_name, ent->name);
+ strbuf_addstr(&buf_name, " (empty directories cannot be added)");
+ string_list_insert(&s->untracked, buf_name.buf);
+ strbuf_release(&buf_name);
+ }
+ else
+ string_list_insert(&s->untracked, ent->name);
+ }
free(ent);
}
--
1.7.7.5 (Apple Git-26)
next reply other threads:[~2012-06-09 19:40 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-09 19:40 Leila Muhtasib [this message]
2012-06-09 20:13 ` [PATCH] git-status: Show empty directories konglu
2012-06-09 21:08 ` Leila
2012-06-09 21:14 ` Thomas Rast
2012-06-09 21:24 ` Leila
2012-06-09 21:47 ` konglu
2012-06-10 9:01 ` Thomas Rast
2012-06-10 9:46 ` konglu
2012-06-10 14:20 ` Leila
2012-06-11 15:08 ` Junio C Hamano
2012-06-10 7:15 ` Junio C Hamano
2012-06-10 16:02 ` Leila
2012-06-10 18:12 ` konglu
2012-06-10 18:17 ` Leila
2012-06-11 16:57 ` Junio C Hamano
2012-06-11 18:51 ` Leila
2012-06-11 19:00 ` Leila
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1339270806-65013-1-git-send-email-muhtasib@gmail.com \
--to=muhtasib@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).