@matheusbsbs / matheus-bagliano / commits / 6a1ad32519
Fork 0

git-add -f: allow adding otherwise ignored files.

Instead of just warning, refuse to add otherwise ignored files by default, and allow it with an -f option. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Dec 25, 2006 at 17:46 UTC 6a1ad32519898a8fa4400e081c2d61fd3af42e2c
2 files changed +35 -7
Documentation/git-add.txt
+6 -2
@@ -7,7 +7,7 @@ git-add - Add file contents to the changeset to be committed next
7
8 SYNOPSIS
9 --------
10 -'git-add' [-n] [-v] [--interactive] [--] <file>...
10 +'git-add' [-n] [-v] [-f] [--interactive] [--] <file>...
11
12 DESCRIPTION
13 -----------
@@ -25,7 +25,8 @@ the commit.
25 The 'git status' command can be used to obtain a summary of what is included
26 for the next commit.
27
28 -This command can be used to add ignored files, but they have to be
28 +This command can be used to add ignored files with `-f` (force)
29 +option, but they have to be
30 explicitly and exactly specified from the command line. File globbing
31 and recursive behaviour do not add ignored files.
32
@@ -48,6 +49,9 @@ OPTIONS
49 -v::
50 Be verbose.
51
52 +-f::
53 + Allow adding otherwise ignored files.
54 +
55 \--interactive::
56 Add modified contents in the working tree interactively to
57 the index.
builtin-add.c
+29 -5
@@ -10,7 +10,7 @@
10 #include "cache-tree.h"
11
12 static const char builtin_add_usage[] =
13 -"git-add [-n] [-v] [--interactive] [--] <filepattern>...";
13 +"git-add [-n] [-v] [-f] [--interactive] [--] <filepattern>...";
14
15 static void prune_directory(struct dir_struct *dir, const char **pathspec, int prefix)
16 {
@@ -37,9 +37,6 @@ static void prune_directory(struct dir_struct *dir, const char **pathspec, int p
37 free(entry);
38 continue;
39 }
40 - if (entry->ignored_entry)
41 - fprintf(stderr, "warning: '%s' is an ignored path.\n",
42 - entry->name);
40 *dst++ = entry;
41 }
42 dir->nr = dst - dir->entries;
@@ -94,10 +91,13 @@ static void fill_directory(struct dir_struct *dir, const char **pathspec)
91
92 static struct lock_file lock_file;
93
94 +static const char ignore_warning[] =
95 +"The following paths are ignored by one of your .gitignore files:\n";
96 +
97 int cmd_add(int argc, const char **argv, const char *prefix)
98 {
99 int i, newfd;
100 - int verbose = 0, show_only = 0;
100 + int verbose = 0, show_only = 0, ignored_too = 0;
101 const char **pathspec;
102 struct dir_struct dir;
103 int add_interactive = 0;
@@ -132,6 +132,10 @@ int cmd_add(int argc, const char **argv, const char *prefix)
132 show_only = 1;
133 continue;
134 }
135 + if (!strcmp(arg, "-f")) {
136 + ignored_too = 1;
137 + continue;
138 + }
139 if (!strcmp(arg, "-v")) {
140 verbose = 1;
141 continue;
@@ -150,6 +154,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)
154 if (show_only) {
155 const char *sep = "", *eof = "";
156 for (i = 0; i < dir.nr; i++) {
157 + if (!ignored_too && dir.entries[i]->ignored_entry)
158 + continue;
159 printf("%s%s", sep, dir.entries[i]->name);
160 sep = " ";
161 eof = "\n";
@@ -161,6 +167,24 @@ int cmd_add(int argc, const char **argv, const char *prefix)
167 if (read_cache() < 0)
168 die("index file corrupt");
169
170 + if (!ignored_too) {
171 + int has_ignored = -1;
172 + for (i = 0; has_ignored < 0 && i < dir.nr; i++)
173 + if (dir.entries[i]->ignored_entry)
174 + has_ignored = i;
175 + if (0 <= has_ignored) {
176 + fprintf(stderr, ignore_warning);
177 + for (i = has_ignored; i < dir.nr; i++) {
178 + if (!dir.entries[i]->ignored_entry)
179 + continue;
180 + fprintf(stderr, "%s\n", dir.entries[i]->name);
181 + }
182 + fprintf(stderr,
183 + "Use -f if you really want to add them.\n");
184 + exit(1);
185 + }
186 + }
187 +
188 for (i = 0; i < dir.nr; i++)
189 add_file_to_index(dir.entries[i]->name, verbose);
190