Re: "git add $ignored_file" fail

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Wed, 17 May 2006, Jakub Narebski wrote:
> 
> The changes in docummentation are nice and dandy, but it would be even nicer
> if "git add" told us about "git update-index --add" when it adds no files,
> as it is certainly the case when something is wrong (perhaps user
> expectations, but still...).

Well, with the new-and-improved builtin "git add", you could probably do 
something like the appended (on top of my most recent patch).

It says

	No added files - did you perhaps mean to do a 'git update-index'?

whenever it finds that "git add" has ignored a file and not actually added 
anything. That, btw, can happen either because it refused to see the file 
in the first place (ie it was ignored), or because all the files listed 
were already added.

In both cases the warning may or may not be sensible.

Anyway, I dunno. I don't have any strong opinions on this.

		Linus

---
diff --git a/builtin-add.c b/builtin-add.c
index 82e8f44..8641137 100644
--- a/builtin-add.c
+++ b/builtin-add.c
@@ -12,6 +12,8 @@ #include "dir.h"
 static const char builtin_add_usage[] =
 "git-add [-n] [-v] <filepattern>...";
 
+static int ignored;
+
 static int common_prefix(const char **pathspec)
 {
 	const char *path, *slash, *next;
@@ -123,8 +125,10 @@ static void prune_directory(struct dir_s
 
 		/* Existing file? We must have ignored it */
 		match = pathspec[i];
-		if (!lstat(match, &st))
+		if (!lstat(match, &st)) {
+			ignored = 1;
 			continue;
+		}
 		die("pathspec '%s' did not match any files", match);
 	}
 }
@@ -257,6 +261,9 @@ int cmd_add(int argc, const char **argv,
 	for (i = 0; i < dir.nr; i++)
 		add_file_to_index(dir.entries[i]->name, verbose);
 
+	if (ignored && !active_cache_changed)
+		fprintf(stderr, "No added files - did you perhaps mean to do a 'git update-index'?\n");
+
 	if (active_cache_changed) {
 		if (write_cache(newfd, active_cache, active_nr) ||
 		    commit_index_file(&cache_file))
-
: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]