* [PATCH 0/2] git-add: -s flag (silently ignore files) @ 2012-10-01 7:14 Olaf Klischat 2012-10-01 7:14 ` [PATCH 1/2] git-add: -s flag added " Olaf Klischat ` (2 more replies) 0 siblings, 3 replies; 6+ messages in thread From: Olaf Klischat @ 2012-10-01 7:14 UTC (permalink / raw) To: git, olaf; +Cc: gitster This adds an -s|--silent-ignore option to git-add, which causes ignored files that were specified explicitly on the command line to be silently ignored, rather than abandoning the command. I found this useful for scenarios where you want to feed the file list into git add via find or other external commands (`find .... | xargs git add'), which you wouldn't want to carefully tune so they don't output any ignored files. git ls-files doesn't have find's filtering capabilities, and using it in place of find would kind of violate "one job one tool" anyway. I'm not really a git guru, so maybe I'm missing something, and I'm unsure how useful this new option is for a general audience. OTOH the patch is trivial. Check it out. The update applies on top of "master" (261b5119). Olaf Klischat (2): git-add: -s flag added (silently ignore files) git-add: -s flag: documentation added Documentation/git-add.txt | 15 +++++++++++---- builtin/add.c | 14 +++++++++++--- t/t3700-add.sh | 17 ++++++++++++++++- 3 files changed, 38 insertions(+), 8 deletions(-) -- 1.7.10.4 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] git-add: -s flag added (silently ignore files) 2012-10-01 7:14 [PATCH 0/2] git-add: -s flag (silently ignore files) Olaf Klischat @ 2012-10-01 7:14 ` Olaf Klischat 2012-10-01 17:59 ` Junio C Hamano 2012-10-01 7:15 ` [PATCH 2/2] git-add: -s flag: documentation added Olaf Klischat 2012-10-01 18:32 ` [PATCH 0/2] git-add: -s flag (silently ignore files) Junio C Hamano 2 siblings, 1 reply; 6+ messages in thread From: Olaf Klischat @ 2012-10-01 7:14 UTC (permalink / raw) To: git, olaf; +Cc: gitster Signed-off-by: Olaf Klischat <olaf.klischat@gmail.com> --- builtin/add.c | 14 +++++++++++--- t/t3700-add.sh | 17 ++++++++++++++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/builtin/add.c b/builtin/add.c index e664100..61bb9ce 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -313,7 +313,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, ignore_missing, silent_ignores = 0; static struct option builtin_add_options[] = { OPT__DRY_RUN(&show_only, N_("dry run")), @@ -329,6 +329,7 @@ static struct option builtin_add_options[] = { OPT_BOOLEAN( 0 , "refresh", &refresh_only, N_("don't add, only refresh the index")), OPT_BOOLEAN( 0 , "ignore-errors", &ignore_add_errors, N_("just skip files which cannot be added because of errors")), OPT_BOOLEAN( 0 , "ignore-missing", &ignore_missing, N_("check if - even missing - files are ignored in dry run")), + OPT_BOOLEAN('s', "silent-ignores", &silent_ignores, N_("don't fail when ignored files are specified on the command line (ignore them silently)")), OPT_END(), }; @@ -339,6 +340,11 @@ static int add_config(const char *var, const char *value, void *cb) ignore_add_errors = git_config_bool(var, value); return 0; } + if (!strcmp(var, "add.silentignores") || + !strcmp(var, "add.silent-ignores")) { + silent_ignores = git_config_bool(var, value); + return 0; + } return git_default_config(var, value, cb); } @@ -346,11 +352,11 @@ static int add_files(struct dir_struct *dir, int flags) { int i, exit_status = 0; - if (dir->ignored_nr) { + if (dir->ignored_nr && !silent_ignores) { fprintf(stderr, _(ignore_error)); for (i = 0; i < dir->ignored_nr; i++) fprintf(stderr, "%s\n", dir->ignored[i]->name); - fprintf(stderr, _("Use -f if you really want to add them.\n")); + fprintf(stderr, _("Use -f if you really want to add them, or -s to ignore them silently.\n")); die(_("no files added")); } @@ -390,6 +396,8 @@ int cmd_add(int argc, const char **argv, const char *prefix) if (addremove && take_worktree_changes) die(_("-A and -u are mutually incompatible")); + if (ignored_too && silent_ignores) + die(_("-f and -s 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) { diff --git a/t/t3700-add.sh b/t/t3700-add.sh index 874b3a6..1e17ae2 100755 --- a/t/t3700-add.sh +++ b/t/t3700-add.sh @@ -294,7 +294,7 @@ test_expect_success 'git add --dry-run of an existing file output' " 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. +Use -f if you really want to add them, or -s to ignore them silently. fatal: no files added EOF cat >expect.out <<\EOF @@ -310,4 +310,19 @@ test_expect_success 'git add --dry-run --ignore-missing of non-existing file out test_i18ncmp expect.err actual.err ' +cat >expect.err <<\EOF +EOF +cat >expect.out <<\EOF +add 'track-this' +EOF + +test_expect_success 'git add --dry-run --silent-ignore --ignore-missing of non-existing file' ' + git add --dry-run --silent-ignore --ignore-missing track-this ignored-file >actual.out 2>actual.err +' + +test_expect_success 'git add --dry-run --silent-ignore --ignore-missing of non-existing file output' ' + test_i18ncmp expect.out actual.out && + test_i18ncmp expect.err actual.err +' + test_done -- 1.7.10.4 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] git-add: -s flag added (silently ignore files) 2012-10-01 7:14 ` [PATCH 1/2] git-add: -s flag added " Olaf Klischat @ 2012-10-01 17:59 ` Junio C Hamano 2012-10-01 18:04 ` Matthieu Moy 0 siblings, 1 reply; 6+ messages in thread From: Junio C Hamano @ 2012-10-01 17:59 UTC (permalink / raw) To: Olaf Klischat; +Cc: git, olaf Olaf Klischat <olaf.klischat@gmail.com> writes: > Signed-off-by: Olaf Klischat <olaf.klischat@gmail.com> > --- I am personally not sympathetic to the reasoning stated in the proposed commit log message above your signed-off-by line; the change is not justified at all. But I'll comment on the code changes anyway. > builtin/add.c | 14 +++++++++++--- > t/t3700-add.sh | 17 ++++++++++++++++- > 2 files changed, 27 insertions(+), 4 deletions(-) > > diff --git a/builtin/add.c b/builtin/add.c > index e664100..61bb9ce 100644 > --- a/builtin/add.c > +++ b/builtin/add.c > @@ -313,7 +313,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, ignore_missing, silent_ignores = 0; > > static struct option builtin_add_options[] = { > OPT__DRY_RUN(&show_only, N_("dry run")), > @@ -329,6 +329,7 @@ static struct option builtin_add_options[] = { > OPT_BOOLEAN( 0 , "refresh", &refresh_only, N_("don't add, only refresh the index")), > OPT_BOOLEAN( 0 , "ignore-errors", &ignore_add_errors, N_("just skip files which cannot be added because of errors")), > OPT_BOOLEAN( 0 , "ignore-missing", &ignore_missing, N_("check if - even missing - files are ignored in dry run")), > + OPT_BOOLEAN('s', "silent-ignores", &silent_ignores, N_("don't fail when ignored files are specified on the command line (ignore them silently)")), I'd prefer not to see a new option whose worth hasn't been proven in the field to squat on any short-and-sweet single letter option name and would suggest replacing that 's' with 0, at least for now. > @@ -339,6 +340,11 @@ static int add_config(const char *var, const char *value, void *cb) > ignore_add_errors = git_config_bool(var, value); > return 0; > } > + if (!strcmp(var, "add.silentignores") || > + !strcmp(var, "add.silent-ignores")) { The second variant is unwarranted. We may have a variable or two that are accepted with '-' or '_' in their names, but they are backward compatibility measures, only to cover previous mistakes that named them in these letters in the first place. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] git-add: -s flag added (silently ignore files) 2012-10-01 17:59 ` Junio C Hamano @ 2012-10-01 18:04 ` Matthieu Moy 0 siblings, 0 replies; 6+ messages in thread From: Matthieu Moy @ 2012-10-01 18:04 UTC (permalink / raw) To: Junio C Hamano; +Cc: Olaf Klischat, git, olaf Junio C Hamano <gitster@pobox.com> writes: >> static struct option builtin_add_options[] = { >> OPT__DRY_RUN(&show_only, N_("dry run")), >> @@ -329,6 +329,7 @@ static struct option builtin_add_options[] = { >> OPT_BOOLEAN( 0 , "refresh", &refresh_only, N_("don't add, only refresh the index")), >> OPT_BOOLEAN( 0 , "ignore-errors", &ignore_add_errors, N_("just skip files which cannot be added because of errors")), >> OPT_BOOLEAN( 0 , "ignore-missing", &ignore_missing, N_("check if - even missing - files are ignored in dry run")), >> + OPT_BOOLEAN('s', "silent-ignores", &silent_ignores, N_("don't fail when ignored files are specified on the command line (ignore them silently)")), > > I'd prefer not to see a new option whose worth hasn't been proven in > the field to squat on any short-and-sweet single letter option > name and would suggest replacing that 's' with 0, at least for now. Another option would be a -k (--keep-going) that would ignore the files, but not silently. "git mv" has such an option already. -- Matthieu Moy http://www-verimag.imag.fr/~moy/ ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/2] git-add: -s flag: documentation added 2012-10-01 7:14 [PATCH 0/2] git-add: -s flag (silently ignore files) Olaf Klischat 2012-10-01 7:14 ` [PATCH 1/2] git-add: -s flag added " Olaf Klischat @ 2012-10-01 7:15 ` Olaf Klischat 2012-10-01 18:32 ` [PATCH 0/2] git-add: -s flag (silently ignore files) Junio C Hamano 2 siblings, 0 replies; 6+ messages in thread From: Olaf Klischat @ 2012-10-01 7:15 UTC (permalink / raw) To: git, olaf; +Cc: gitster Signed-off-by: Olaf Klischat <olaf.klischat@gmail.com> --- Documentation/git-add.txt | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt index fd9e36b..a5a1cd1 100644 --- a/Documentation/git-add.txt +++ b/Documentation/git-add.txt @@ -38,10 +38,12 @@ files have changes that are staged for the next commit. The `git add` command will not add ignored files by default. If any ignored files were explicitly specified on the command line, `git add` -will fail with a list of ignored files. Ignored files reached by -directory recursion or filename globbing performed by Git (quote your -globs before the shell) will be silently ignored. The 'git add' command can -be used to add ignored files with the `-f` (force) option. +will fail with a list of ignored files unless the `-s` (silent-ignore) +option was given. Ignored files reached by directory recursion or +filename globbing performed by Git (quote your globs before the shell) +will always be silently ignored. The 'git add' command can be used to +add ignored files with the `-f` (force) option (which is mutually +exclusive with `-s`). Please see linkgit:git-commit[1] for alternative ways to add content to a commit. @@ -69,6 +71,11 @@ OPTIONS --force:: Allow adding otherwise ignored files. +-s:: +--silent-ignore:: + Don't fail if ignored files were specified explicitly; ignore them + silently and continue. + -i:: --interactive:: Add modified contents in the working tree interactively to -- 1.7.10.4 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] git-add: -s flag (silently ignore files) 2012-10-01 7:14 [PATCH 0/2] git-add: -s flag (silently ignore files) Olaf Klischat 2012-10-01 7:14 ` [PATCH 1/2] git-add: -s flag added " Olaf Klischat 2012-10-01 7:15 ` [PATCH 2/2] git-add: -s flag: documentation added Olaf Klischat @ 2012-10-01 18:32 ` Junio C Hamano 2 siblings, 0 replies; 6+ messages in thread From: Junio C Hamano @ 2012-10-01 18:32 UTC (permalink / raw) To: Olaf Klischat; +Cc: git, olaf Olaf Klischat <olaf.klischat@gmail.com> writes: > ... scenarios where you want to feed the file list into git add > via find or other external commands (`find .... | xargs git add'), > which you wouldn't want to carefully tune... Can you explain this kind of thing in the actual commit log message when you reroll (if you will do so)? I also cannot help but find that `scenario` an artificially made-up one. The description did not feel convincing enough, even if it were in the proposed commit log message, to justify such an option. A few questions. - What were the kind of patterns useful in the above `find` in your real life example? - The use of `find` means giving pathspecs from the command line, e.g. "git add foo/ \*.rb", wouldn't have been sufficient. Are there something we could improve this in more direct way? - Why was it too cumbersome to add the idiomatic \( -name '*.o' -o -name '*~' \) -prune -o or something like that in front of whatever patterns were used? - Perhaps a filter that takes a list of paths and emits only the ignored paths (or only the unignored paths) would be a more generic approach? You could feed the output from `find` to such a filter, and then drive not just "git add" but other commands that take paths if you solved it that way. ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-10-01 18:32 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2012-10-01 7:14 [PATCH 0/2] git-add: -s flag (silently ignore files) Olaf Klischat 2012-10-01 7:14 ` [PATCH 1/2] git-add: -s flag added " Olaf Klischat 2012-10-01 17:59 ` Junio C Hamano 2012-10-01 18:04 ` Matthieu Moy 2012-10-01 7:15 ` [PATCH 2/2] git-add: -s flag: documentation added Olaf Klischat 2012-10-01 18:32 ` [PATCH 0/2] git-add: -s flag (silently ignore files) Junio C Hamano
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).