git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] git-status: Show empty directories
@ 2012-06-09 19:40 Leila Muhtasib
  2012-06-09 20:13 ` konglu
  2012-06-10  7:15 ` Junio C Hamano
  0 siblings, 2 replies; 17+ messages in thread
From: Leila Muhtasib @ 2012-06-09 19:40 UTC (permalink / raw)
  To: git; +Cc: Leila Muhtasib

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)

^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2012-06-11 19:00 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-09 19:40 [PATCH] git-status: Show empty directories Leila Muhtasib
2012-06-09 20:13 ` 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

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).