git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [RFC/PATCH] git-add: Don't exclude explicitly-specified tracked files
@ 2010-08-11  7:03 Greg Brockman
  2010-08-11 12:24 ` Ævar Arnfjörð Bjarmason
                   ` (2 more replies)
  0 siblings, 3 replies; 28+ messages in thread
From: Greg Brockman @ 2010-08-11  7:03 UTC (permalink / raw)
  To: git, gitster, Jens.Lehmann; +Cc: Greg Brockman

Currently, 'git add' will complain about excluded files, even if they
are already tracked:

$ mkdir dir && touch dir/file && cat > .gitignore <<< dir
$ git add -f dir/file
$ git status
  ...
  new file:   dir/file
  ...
$ git add dir/file
The following paths are ignored by one of your .gitignore files:
dir
Use -f if you really want to add them.
fatal: no files added

This commit changes 'git add' to disregard excludes for tracked files
whose paths are explicitly specified on the command-line.  So in the
above example, 'git add dir/file' no longer requires a '-f'.  However,
'git add dir' does.

Signed-off-by: Greg Brockman <gdb@mit.edu>
---
 builtin/add.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

What do people think of this behavior?  My motivation in writing this patch is
that I sometimes track files in an ignored directory, and it can be cumbersome
to remember to pass '-f' when adding them.  Related commands such as 'git add -p'
and 'git commit -a' do not require a '-f' in this case, so it feels natural to me not
to require extra user confirmation when an explicit path has been provided.

As always, thanks in advance for your comments.

diff --git a/builtin/add.c b/builtin/add.c
index 56a4e0a..46b1fdb 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -423,8 +423,27 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 		/* Set up the default git porcelain excludes */
 		memset(&dir, 0, sizeof(dir));
 		if (!ignored_too) {
+			const char **tracked = xmalloc(sizeof(char *) * (argc + 1));
+			const char **p;
+			int tidx = 0;
+			int pidx = 0;
+
 			dir.flags |= DIR_COLLECT_IGNORED;
 			setup_standard_excludes(&dir);
+
+			for (p = pathspec; *p; p++) {
+				if ((*p)[0] && cache_name_exists(*p, strlen(*p), 0))
+					tracked[tidx++] = *p;
+				else
+					pathspec[pidx++] = *p;
+			}
+
+			tracked[tidx] = NULL;
+			pathspec[pidx] = NULL;
+			exit_status |= add_files_to_cache(prefix, tracked, flags);
+			/* All files were tracked */
+			if (pidx == 0)
+				goto finish;
 		}
 
 		/* This picks up the paths that are not tracked */
-- 
1.7.0.4

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

end of thread, other threads:[~2010-08-29 18:29 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-11  7:03 [RFC/PATCH] git-add: Don't exclude explicitly-specified tracked files Greg Brockman
2010-08-11 12:24 ` Ævar Arnfjörð Bjarmason
2010-08-11 20:50   ` Jens Lehmann
2010-08-12  2:11     ` Greg Brockman
2010-08-11 18:22 ` Junio C Hamano
2010-08-11 18:36   ` Greg Brockman
2010-08-12  2:59     ` Junio C Hamano
2010-08-12  3:19       ` Greg Brockman
2010-08-12  8:30 ` Matthieu Moy
2010-08-12 15:54   ` Greg Brockman
2010-08-12 16:31     ` Matthieu Moy
2010-08-12 20:00     ` Junio C Hamano
2010-08-12 20:19       ` Greg Brockman
2010-08-12 20:40         ` Jonathan Nieder
2010-08-12 20:26     ` Ævar Arnfjörð Bjarmason
2010-08-18  9:07       ` Greg Brockman
2010-08-18  9:29         ` [RFC/PATCH] Add test case for dealing with a tracked file in an ignored directory Greg Brockman
2010-08-18  9:43           ` Greg Brockman
2010-08-18  9:50           ` Matthieu Moy
2010-08-19  7:52             ` Greg Brockman
2010-08-19  8:50               ` Matthieu Moy
2010-08-18 13:43           ` Ævar Arnfjörð Bjarmason
2010-08-18 13:47             ` Matthieu Moy
2010-08-18 14:02               ` Ævar Arnfjörð Bjarmason
2010-08-19  0:00               ` Jonathan Nieder
2010-08-19  0:24                 ` Ævar Arnfjörð Bjarmason
2010-08-25  3:13                   ` Jonathan Nieder
2010-08-29 18:27                     ` Ævar Arnfjörð Bjarmason

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).