From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH/WIP 01/11] Introduce "check-attr --excluded" as a replacement for "add --ignore-missing"
Date: Mon, 24 Oct 2011 17:36:06 +1100 [thread overview]
Message-ID: <1319438176-7304-2-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1319438176-7304-1-git-send-email-pclouds@gmail.com>
--ignore-missing is used by submodule to check if a path may be
ignored by .gitignore files. It does not really fit in git-add (git
add takes pathspec, but --ignore-missing takes only paths)
Google reckons that --ignore-missing is not used anywhere but
git-submodule.sh. Remove --ignore-missing and introduce "check-attr
--excluded" as a replacement.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
Documentation/git-check-attr.txt | 4 ++++
builtin/add.c | 14 +++-----------
builtin/check-attr.c | 26 ++++++++++++++++++++++++++
git-submodule.sh | 2 +-
t/t3700-add.sh | 19 -------------------
5 files changed, 34 insertions(+), 31 deletions(-)
diff --git a/Documentation/git-check-attr.txt b/Documentation/git-check-attr.txt
index 5abdbaa..94d2068 100644
--- a/Documentation/git-check-attr.txt
+++ b/Documentation/git-check-attr.txt
@@ -11,6 +11,7 @@ SYNOPSIS
[verse]
'git check-attr' [-a | --all | attr...] [--] pathname...
'git check-attr' --stdin [-z] [-a | --all | attr...] < <list-of-paths>
+'git check-attr' --excluded pathname...
DESCRIPTION
-----------
@@ -34,6 +35,9 @@ OPTIONS
Only meaningful with `--stdin`; paths are separated with a
NUL character instead of a linefeed character.
+--excluded::
+ Check if given paths are excluded by standard .gitignore rules.
+
\--::
Interpret all preceding arguments as attributes and all following
arguments as path names.
diff --git a/builtin/add.c b/builtin/add.c
index c59b0c9..23ad4b8 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -310,7 +310,7 @@ static const char ignore_error[] =
N_("The following paths are ignored by one of your .gitignore files:\n");
static int verbose = 0, show_only = 0, ignored_too = 0, refresh_only = 0;
-static int ignore_add_errors, addremove, intent_to_add, ignore_missing = 0;
+static int ignore_add_errors, addremove, intent_to_add;
static struct option builtin_add_options[] = {
OPT__DRY_RUN(&show_only, "dry run"),
@@ -325,7 +325,6 @@ static struct option builtin_add_options[] = {
OPT_BOOLEAN('A', "all", &addremove, "add changes from all tracked and untracked files"),
OPT_BOOLEAN( 0 , "refresh", &refresh_only, "don't add, only refresh the index"),
OPT_BOOLEAN( 0 , "ignore-errors", &ignore_add_errors, "just skip files which cannot be added because of errors"),
- OPT_BOOLEAN( 0 , "ignore-missing", &ignore_missing, "check if - even missing - files are ignored in dry run"),
OPT_END(),
};
@@ -387,8 +386,6 @@ int cmd_add(int argc, const char **argv, const char *prefix)
if (addremove && take_worktree_changes)
die(_("-A and -u are mutually incompatible"));
- if (!show_only && ignore_missing)
- die(_("Option --ignore-missing can only be used together with --dry-run"));
if ((addremove || take_worktree_changes) && !argc) {
static const char *here[2] = { ".", NULL };
argc = 1;
@@ -446,13 +443,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)
for (i = 0; pathspec[i]; i++) {
if (!seen[i] && pathspec[i][0]
&& !file_exists(pathspec[i])) {
- if (ignore_missing) {
- int dtype = DT_UNKNOWN;
- if (excluded(&dir, pathspec[i], &dtype))
- dir_add_ignored(&dir, pathspec[i], strlen(pathspec[i]));
- } else
- die(_("pathspec '%s' did not match any files"),
- pathspec[i]);
+ die(_("pathspec '%s' did not match any files"),
+ pathspec[i]);
}
}
free(seen);
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index 44c421e..4c17ccc 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -2,11 +2,13 @@
#include "cache.h"
#include "attr.h"
#include "quote.h"
+#include "dir.h"
#include "parse-options.h"
static int all_attrs;
static int cached_attrs;
static int stdin_paths;
+static int exclude;
static const char * const check_attr_usage[] = {
"git check-attr [-a | --all | attr...] [--] pathname...",
"git check-attr --stdin [-a | --all | attr...] < <list-of-paths>",
@@ -21,6 +23,7 @@ static const struct option check_attr_options[] = {
OPT_BOOLEAN(0 , "stdin", &stdin_paths, "read file names from stdin"),
OPT_BOOLEAN('z', NULL, &null_term_line,
"input paths are terminated by a null character"),
+ OPT_BOOLEAN(0, "excluded", &exclude, "check exclude patterns"),
OPT_END()
};
@@ -43,6 +46,16 @@ static void output_attr(int cnt, struct git_attr_check *check,
}
}
+static void check_exclude(struct dir_struct *dir, const char *prefix, const char *file)
+{
+ char *full_path =
+ prefix_path(prefix, prefix ? strlen(prefix) : 0, file);
+ int dtype = DT_UNKNOWN;
+ if (excluded(dir, full_path, &dtype))
+ die("%s is ignored by one of your .gitignore files", full_path);
+ free(full_path);
+}
+
static void check_attr(const char *prefix, int cnt,
struct git_attr_check *check, const char *file)
{
@@ -103,6 +116,19 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
die("invalid cache");
}
+ if (exclude) {
+ struct dir_struct dir;
+
+ if (stdin_paths)
+ die("--excluded cannot be used with --stdin (yet)");
+
+ memset(&dir, 0, sizeof(dir));
+ setup_standard_excludes(&dir);
+ for (i = 0; i < argc; i++)
+ check_exclude(&dir, prefix, argv[i]);
+ return 0;
+ }
+
if (cached_attrs)
git_attr_set_direction(GIT_ATTR_INDEX, NULL);
diff --git a/git-submodule.sh b/git-submodule.sh
index 928a62f..0bc3762 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -262,7 +262,7 @@ cmd_add()
git ls-files --error-unmatch "$path" > /dev/null 2>&1 &&
die "$(eval_gettext "'\$path' already exists in the index")"
- if test -z "$force" && ! git add --dry-run --ignore-missing "$path" > /dev/null 2>&1
+ if test -z "$force" && ! git check-attr --excluded "$path" > /dev/null 2>&1
then
eval_gettextln "The following path is ignored by one of your .gitignore files:
\$path
diff --git a/t/t3700-add.sh b/t/t3700-add.sh
index 575d950..23ff998 100755
--- a/t/t3700-add.sh
+++ b/t/t3700-add.sh
@@ -276,23 +276,4 @@ test_expect_success 'git add --dry-run of an existing file output' "
test_i18ncmp expect actual
"
-cat >expect.err <<\EOF
-The following paths are ignored by one of your .gitignore files:
-ignored-file
-Use -f if you really want to add them.
-fatal: no files added
-EOF
-cat >expect.out <<\EOF
-add 'track-this'
-EOF
-
-test_expect_success 'git add --dry-run --ignore-missing of non-existing file' '
- test_must_fail git add --dry-run --ignore-missing track-this ignored-file >actual.out 2>actual.err
-'
-
-test_expect_success 'git add --dry-run --ignore-missing of non-existing file output' '
- test_i18ncmp expect.out actual.out &&
- test_i18ncmp expect.err actual.err
-'
-
test_done
--
1.7.3.1.256.g2539c.dirty
next prev parent reply other threads:[~2011-10-24 6:38 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-24 6:36 [PATCH/WIP 00/11] read_directory() rewrite to support struct pathspec Nguyễn Thái Ngọc Duy
2011-10-24 6:36 ` Nguyễn Thái Ngọc Duy [this message]
2011-10-27 18:08 ` [PATCH/WIP 01/11] Introduce "check-attr --excluded" as a replacement for "add --ignore-missing" Junio C Hamano
2011-10-28 20:51 ` Nguyen Thai Ngoc Duy
2011-10-24 6:36 ` [PATCH/WIP 02/11] notes-merge: use opendir/readdir instead of using read_directory() Nguyễn Thái Ngọc Duy
2011-10-25 19:27 ` Junio C Hamano
2011-10-26 0:08 ` Nguyen Thai Ngoc Duy
2011-10-26 17:37 ` Junio C Hamano
2011-10-27 7:51 ` Nguyen Thai Ngoc Duy
2011-10-27 17:23 ` Junio C Hamano
2011-10-28 20:47 ` Nguyen Thai Ngoc Duy
2012-03-12 14:47 ` [PATCH 1/2] t3310: Add testcase demonstrating failure to --commit from within another dir Johan Herland
2012-03-12 14:47 ` [PATCH 2/2] notes-merge: use opendir/readdir instead of using read_directory() Johan Herland
2012-03-12 14:53 ` Nguyen Thai Ngoc Duy
2012-03-14 8:39 ` [PATCH jh/notes-merge-in-git-dir-worktree] fixup! t3310 on Windows Johannes Sixt
2012-03-14 11:39 ` Johan Herland
2012-03-14 11:59 ` Johannes Sixt
2012-03-14 12:20 ` David Bremner
2012-03-14 12:56 ` Johan Herland
2012-03-14 17:44 ` Junio C Hamano
2012-03-14 23:55 ` [PATCH 3/2] notes-merge: Don't remove .git/NOTES_MERGE_WORKTREE; it may be the user's cwd Johan Herland
2012-03-15 7:02 ` Junio C Hamano
2012-03-15 7:16 ` Junio C Hamano
2012-03-15 7:39 ` Johan Herland
2012-03-15 8:04 ` Re* " Junio C Hamano
2012-03-15 8:12 ` Junio C Hamano
2012-03-15 8:12 ` Johannes Sixt
2011-10-24 6:36 ` [PATCH/WIP 03/11] t5403: avoid doing "git add foo/bar" where foo/.git exists Nguyễn Thái Ngọc Duy
2011-10-25 19:19 ` Junio C Hamano
2011-10-26 0:18 ` Nguyen Thai Ngoc Duy
2011-10-26 17:26 ` Junio C Hamano
2011-10-27 8:06 ` Nguyen Thai Ngoc Duy
2011-10-27 17:41 ` Junio C Hamano
2011-10-30 5:55 ` Nguyen Thai Ngoc Duy
2011-10-30 7:08 ` Junio C Hamano
2011-10-30 9:55 ` Nguyen Thai Ngoc Duy
2011-10-30 23:47 ` Junio C Hamano
2011-10-24 6:36 ` [PATCH/WIP 04/11] tree-walk.c: do not leak internal structure in tree_entry_len() Nguyễn Thái Ngọc Duy
2011-10-25 19:20 ` Junio C Hamano
2011-10-24 6:36 ` [PATCH/WIP 05/11] symbolize return values of tree_entry_interesting() Nguyễn Thái Ngọc Duy
2011-10-25 19:24 ` Junio C Hamano
2011-10-27 18:36 ` Junio C Hamano
2011-10-30 9:17 ` Nguyen Thai Ngoc Duy
2011-10-24 6:36 ` [PATCH/WIP 06/11] read_directory_recursive: reduce one indentation level Nguyễn Thái Ngọc Duy
2011-10-24 6:36 ` [PATCH/WIP 07/11] tree_entry_interesting: make use of local pointer "item" Nguyễn Thái Ngọc Duy
2011-10-24 6:36 ` [PATCH/WIP 08/11] tree-walk: mark useful pathspecs Nguyễn Thái Ngọc Duy
2011-10-24 6:36 ` [PATCH/WIP 09/11] tree_entry_interesting: differentiate partial vs full match Nguyễn Thái Ngọc Duy
2011-10-24 6:36 ` [PATCH/WIP 10/11] read-dir: stop using path_simplify code in favor of tree_entry_interesting() Nguyễn Thái Ngọc Duy
2011-10-24 6:36 ` [PATCH/WIP 11/11] dir.c: remove dead code after read_directory() rewrite Nguyễn Thái Ngọc Duy
2011-10-24 17:10 ` [PATCH/WIP 00/11] read_directory() rewrite to support struct pathspec Junio C Hamano
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=1319438176-7304-2-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.