From: Junio C Hamano <junkio@cox.net>
To: git@vger.kernel.org
Subject: [PATCH 5/5] git-add: add ignored files when asked explicitly.
Date: Mon, 25 Dec 2006 03:13:45 -0800 [thread overview]
Message-ID: <7vbqlskz2u.fsf@assigned-by-dhcp.cox.net> (raw)
One thing many people found confusing about git-add was that a
file whose name matches an ignored pattern could not be added to
the index. With this, such a file can be added by explicitly
spelling its name to git-add.
Fileglobs and recursive behaviour do not add ignored files to
the index. That is, if a pattern '*.o' is in .gitignore, and
two files foo.o, bar/baz.o are in the working tree:
$ git add foo.o
$ git add '*.o'
$ git add bar
Only the first form adds foo.o to the index.
Signed-off-by: Junio C Hamano <junkio@cox.net>
---
Documentation/git-add.txt | 11 ++++++++---
builtin-add.c | 11 ++++++++++-
2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt
index d86c0e7..a8ed459 100644
--- a/Documentation/git-add.txt
+++ b/Documentation/git-add.txt
@@ -25,8 +25,9 @@ the commit.
The 'git status' command can be used to obtain a summary of what is included
for the next commit.
-This command only adds non-ignored files, to add ignored files use
-"git update-index --add".
+This command can be used to add ignored files, but they have to be
+explicitly and exactly specified from the command line. File globbing
+and recursive behaviour do not add ignored files.
Please see gitlink:git-commit[1] for alternative ways to add content to a
commit.
@@ -35,7 +36,11 @@ commit.
OPTIONS
-------
<file>...::
- Files to add content from.
+ Files to add content from. Fileglobs (e.g. `*.c`) can
+ be given to add all matching files. Also a
+ leading directory name (e.g. `dir` to add `dir/file1`
+ and `dir/file2`) can be given to add all files in the
+ directory, recursively.
-n::
Don't actually add the file(s), just show if they exist.
diff --git a/builtin-add.c b/builtin-add.c
index f306f82..389c106 100644
--- a/builtin-add.c
+++ b/builtin-add.c
@@ -25,7 +25,14 @@ static void prune_directory(struct dir_struct *dir, const char **pathspec, int p
i = dir->nr;
while (--i >= 0) {
struct dir_entry *entry = *src++;
- if (!match_pathspec(pathspec, entry->name, entry->len, prefix, seen)) {
+ int how = match_pathspec(pathspec, entry->name, entry->len,
+ prefix, seen);
+ /*
+ * ignored entries can be added with exact match,
+ * but not with glob nor recursive.
+ */
+ if (!how ||
+ (entry->ignored_entry && how != MATCHED_EXACTLY)) {
free(entry);
continue;
}
@@ -54,6 +61,8 @@ static void fill_directory(struct dir_struct *dir, const char **pathspec)
/* Set up the default git porcelain excludes */
memset(dir, 0, sizeof(*dir));
+ if (pathspec)
+ dir->show_both = 1;
dir->exclude_per_dir = ".gitignore";
path = git_path("info/exclude");
if (!access(path, R_OK))
--
1.4.4.3.g50da
next reply other threads:[~2006-12-25 11:13 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-12-25 11:13 Junio C Hamano [this message]
2006-12-25 13:47 ` [PATCH 5/5] git-add: add ignored files when asked explicitly Johannes Schindelin
2006-12-25 17:27 ` Junio C Hamano
2006-12-25 18:39 ` [PATCH] git-add: warn when adding an ignored file with an explicit request Junio C Hamano
2006-12-25 22:24 ` Jakub Narebski
2006-12-26 16:19 ` Johannes Schindelin
2006-12-25 19:57 ` [PATCH 5/5] git-add: add ignored files when asked explicitly Nicolas Pitre
2006-12-26 15:34 ` Johannes Schindelin
2006-12-26 19:05 ` Junio C Hamano
2006-12-26 22:48 ` Johannes Schindelin
2007-01-04 13:58 ` Andreas Ericsson
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=7vbqlskz2u.fsf@assigned-by-dhcp.cox.net \
--to=junkio@cox.net \
--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).