* [PATCH] clean: new option --exclude-from @ 2015-11-26 14:44 James 2015-11-30 2:24 ` Eric Sunshine 2015-12-02 0:53 ` [PATCH] clean: new option --exclude-from Jeff King 0 siblings, 2 replies; 21+ messages in thread From: James @ 2015-11-26 14:44 UTC (permalink / raw) To: git; +Cc: James Rouzier From: James Rouzier <rouzier@gmail.com> Specify a file to read for exclude patterns. --- Documentation/git-clean.txt | 5 ++++- builtin/clean.c | 15 ++++++++++++++- t/t7300-clean.sh | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/Documentation/git-clean.txt b/Documentation/git-clean.txt index 641681f..ccd0aa4 100644 --- a/Documentation/git-clean.txt +++ b/Documentation/git-clean.txt @@ -8,7 +8,7 @@ git-clean - Remove untracked files from the working tree SYNOPSIS -------- [verse] -'git clean' [-d] [-f] [-i] [-n] [-q] [-e <pattern>] [-x | -X] [--] <path>... +'git clean' [-d] [-f] [-i] [-n] [-q] [-e <pattern>] [--exclude-from <file>] [-x | -X] [--] <path>... DESCRIPTION ----------- @@ -61,6 +61,9 @@ OPTIONS $GIT_DIR/info/exclude, also consider these patterns to be in the set of the ignore rules in effect. +--exclude-from=<file>:: + Read exclude patterns from <file>; 1 per line. + -x:: Don't use the standard ignore rules read from .gitignore (per directory) and $GIT_DIR/info/exclude, but do still use the ignore diff --git a/builtin/clean.c b/builtin/clean.c index d7acb94..e4995a3 100644 --- a/builtin/clean.c +++ b/builtin/clean.c @@ -875,6 +875,16 @@ static void interactive_main_loop(void) } } +static int option_parse_exclude_from(const struct option *opt, + const char *arg, int unset) +{ + struct dir_struct *dir = opt->value; + + add_excludes_from_file(dir, arg); + + return 0; +} + int cmd_clean(int argc, const char **argv, const char *prefix) { int i, res; @@ -898,11 +908,15 @@ int cmd_clean(int argc, const char **argv, const char *prefix) N_("remove whole directories")), { OPTION_CALLBACK, 'e', "exclude", &exclude_list, N_("pattern"), N_("add <pattern> to ignore rules"), PARSE_OPT_NONEG, exclude_cb }, + { OPTION_CALLBACK, 0, "exclude-from", &dir, N_("file"), + N_("exclude patterns are read from <file>"), + 0, option_parse_exclude_from }, OPT_BOOL('x', NULL, &ignored, N_("remove ignored files, too")), OPT_BOOL('X', NULL, &ignored_only, N_("remove only ignored files")), OPT_END() }; + memset(&dir, 0, sizeof(dir)); git_config(git_clean_config, NULL); if (force < 0) @@ -913,7 +927,6 @@ int cmd_clean(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, prefix, options, builtin_clean_usage, 0); - memset(&dir, 0, sizeof(dir)); if (ignored_only) dir.flags |= DIR_SHOW_IGNORED; diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh index 86ceb38..9b648b9 100755 --- a/t/t7300-clean.sh +++ b/t/t7300-clean.sh @@ -630,6 +630,41 @@ test_expect_success 'git clean -e' ' ) ' +test_expect_success 'git clean --exclude-from' ' + rm -fr repo && + mkdir repo && + ( + cd repo && + git init && + touch known 1 2 3 && + git add known && + echo 1 >> .git/clean-exclude && + echo 2 >> .git/clean-exclude && + git clean -f --exclude-from=.git/clean-exclude && + test -e 1 && + test -e 2 && + ! (test -e 3) && + test -e known + ) +' + +test_expect_success 'git clean -e --exclude-from' ' + rm -fr repo && + mkdir repo && + ( + cd repo && + git init && + touch known 1 2 3 && + git add known && + echo 1 >> .git/clean-exclude && + git clean -f -e 2 --exclude-from=.git/clean-exclude && + test -e 1 && + test -e 2 && + ! (test -e 3) && + test -e known + ) +' + test_expect_success SANITY 'git clean -d with an unreadable empty directory' ' mkdir foo && chmod a= foo && -- 2.3.6 ^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [PATCH] clean: new option --exclude-from 2015-11-26 14:44 [PATCH] clean: new option --exclude-from James @ 2015-11-30 2:24 ` Eric Sunshine [not found] ` <CAGjXF72PgdjBw03ERVYxj+atvsBXK0LeJ6O3zTZgi3-kv9BWsw@mail.gmail.com> 2015-12-02 0:53 ` [PATCH] clean: new option --exclude-from Jeff King 1 sibling, 1 reply; 21+ messages in thread From: Eric Sunshine @ 2015-11-30 2:24 UTC (permalink / raw) To: James; +Cc: Git List On Thu, Nov 26, 2015 at 9:44 AM, James <rouzier@gmail.com> wrote: > From: James Rouzier <rouzier@gmail.com> > > Specify a file to read for exclude patterns. > --- > diff --git a/Documentation/git-clean.txt b/Documentation/git-clean.txt > @@ -8,7 +8,7 @@ git-clean - Remove untracked files from the working tree > SYNOPSIS > -------- > [verse] > -'git clean' [-d] [-f] [-i] [-n] [-q] [-e <pattern>] [-x | -X] [--] <path>... > +'git clean' [-d] [-f] [-i] [-n] [-q] [-e <pattern>] [--exclude-from <file>] [-x | -X] [--] <path>... Common practice seems to be to include the '=' in the synopsis: [--exclude-from=<file>] > DESCRIPTION > ----------- > @@ -61,6 +61,9 @@ OPTIONS > $GIT_DIR/info/exclude, also consider these patterns to be in the > set of the ignore rules in effect. > > +--exclude-from=<file>:: > + Read exclude patterns from <file>; 1 per line. s/;/,/ maybe? > diff --git a/builtin/clean.c b/builtin/clean.c > @@ -875,6 +875,16 @@ static void interactive_main_loop(void) > +static int option_parse_exclude_from(const struct option *opt, > + const char *arg, int unset) For consistency with the other callback function in this file, you'd probably want to name this function exclude_from_cb(). > +{ > + struct dir_struct *dir = opt->value; > + > + add_excludes_from_file(dir, arg); > + > + return 0; Style: You can drop the blank line before 'return'. > +} > @@ -898,11 +908,15 @@ int cmd_clean(int argc, const char **argv, const char *prefix) > N_("remove whole directories")), > { OPTION_CALLBACK, 'e', "exclude", &exclude_list, N_("pattern"), > N_("add <pattern> to ignore rules"), PARSE_OPT_NONEG, exclude_cb }, > + { OPTION_CALLBACK, 0, "exclude-from", &dir, N_("file"), > + N_("exclude patterns are read from <file>"), The existing descriptions all use imperative mood. This probably ought to follow suit: N_("read exclude patterns from file"), > + 0, option_parse_exclude_from }, > OPT_BOOL('x', NULL, &ignored, N_("remove ignored files, too")), > OPT_BOOL('X', NULL, &ignored_only, > N_("remove only ignored files")), > OPT_END() > }; > + memset(&dir, 0, sizeof(dir)); Style: Leave a blank line after the final declaration (before the memset). Also, why move the memset() all the way up here as opposed, say, to moving it just before the parse_options() invocation? Is it just to make it easier for the next person who comes along wanting to manipulate 'dir' early on (before git_config(), for instance)? > git_config(git_clean_config, NULL); > if (force < 0) > @@ -913,7 +927,6 @@ int cmd_clean(int argc, const char **argv, const char *prefix) > argc = parse_options(argc, argv, prefix, options, builtin_clean_usage, > 0); > > - memset(&dir, 0, sizeof(dir)); > if (ignored_only) > dir.flags |= DIR_SHOW_IGNORED; > > diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh > @@ -630,6 +630,41 @@ test_expect_success 'git clean -e' ' > +test_expect_success 'git clean --exclude-from' ' > + rm -fr repo && > + mkdir repo && > + ( > + cd repo && > + git init && > + touch known 1 2 3 && Unless the timestamp is significant, we normally avoid using 'touch' and instead just use redirection to create empty files: >1 >2 >3 In this case, though, you're merely matching existing style in this script, so 'touch' may be okay. > + git add known && > + echo 1 >> .git/clean-exclude && > + echo 2 >> .git/clean-exclude && Style: no space after redirection operator. A here-doc may be cleaner and easier to maintain: cat >.git/clean-exclude <<-\EOF 1 2 EOF > + git clean -f --exclude-from=.git/clean-exclude && > + test -e 1 && > + test -e 2 && > + ! (test -e 3) && I see that you copied this from the "git clean -e" test, but it's not obvious why parentheses are needed or wanted, and none of the other tests use parentheses when negating the return of 'test', thus they probably ought to be dropped. > + test -e known Modern scripts would normally use test_path_is_file() and test_path_is_missing() instead of 'test -e', however, you are again matching existing style in this script, so 'test -e' may be reasonable. > + ) > +' > + > +test_expect_success 'git clean -e --exclude-from' ' > + rm -fr repo && > + mkdir repo && > + ( > + cd repo && > + git init && > + touch known 1 2 3 && > + git add known && > + echo 1 >> .git/clean-exclude && > + git clean -f -e 2 --exclude-from=.git/clean-exclude && > + test -e 1 && > + test -e 2 && > + ! (test -e 3) && > + test -e known > + ) > +' Should a test be added which uses --exclude-from multiple times in the same git-clean invocation? Would it make sense add a test checking the behavior when the file named by --exclude-from doesn't exist or is otherwise unusable as an exclusion file? > test_expect_success SANITY 'git clean -d with an unreadable empty directory' ' > mkdir foo && > chmod a= foo && > -- > 2.3.6 ^ permalink raw reply [flat|nested] 21+ messages in thread
[parent not found: <CAGjXF72PgdjBw03ERVYxj+atvsBXK0LeJ6O3zTZgi3-kv9BWsw@mail.gmail.com>]
* Re: [PATCH] clean: new option --exclude-from [not found] ` <CAGjXF72PgdjBw03ERVYxj+atvsBXK0LeJ6O3zTZgi3-kv9BWsw@mail.gmail.com> @ 2015-12-01 22:25 ` Eric Sunshine 2015-12-06 14:58 ` [PATCH v2 1/2] modernize t7300 James 0 siblings, 1 reply; 21+ messages in thread From: Eric Sunshine @ 2015-12-01 22:25 UTC (permalink / raw) To: James Rouzier, Git List On Tue, Dec 1, 2015 at 4:36 PM, James Rouzier <rouzier@gmail.com> wrote: > Eric thank you for the feedback. [re-adding git@vger.kernel.org to recipient list since this response was likely intended to be public] > On Sun, Nov 29, 2015 at 9:24 PM, Eric Sunshine <sunshine@sunshineco.com> > wrote: >> On Thu, Nov 26, 2015 at 9:44 AM, James <rouzier@gmail.com> wrote: >> > From: James Rouzier <rouzier@gmail.com> >> > >> > Specify a file to read for exclude patterns. >> > --- >> > @@ -61,6 +61,9 @@ OPTIONS >> > $GIT_DIR/info/exclude, also consider these patterns to be in the >> > set of the ignore rules in effect. >> > >> > +--exclude-from=<file>:: >> > + Read exclude patterns from <file>; 1 per line. >> >> s/;/,/ maybe? > > I copied this from Documentation/git-ls-files.txt to try and keep the > documentation style consistent. > However if it is believed to be better I will change it here and also in a > separate patch for Documentation/git-ls-files.txt I don't feel strongly about it. Existing precedence may be a good argument in its favor. >> Also, why move the memset() all the way up here as opposed, say, to >> moving it just before the parse_options() invocation? Is it just to >> make it easier for the next person who comes along wanting to >> manipulate 'dir' early on (before git_config(), for instance)? > > Yes I want to make sure that the 'dir' is initialized before any usage. > >> > + git clean -f --exclude-from=.git/clean-exclude && >> > + test -e 1 && >> > + test -e 2 && >> > + ! (test -e 3) && >> >> I see that you copied this from the "git clean -e" test, but it's not >> obvious why parentheses are needed or wanted, and none of the other >> tests use parentheses when negating the return of 'test', thus they >> probably ought to be dropped. > > Ok will do > >> > + test -e known >> >> Modern scripts would normally use test_path_is_file() and >> test_path_is_missing() instead of 'test -e', however, you are again >> matching existing style in this script, so 'test -e' may be >> reasonable. > > Since it is the standard I could just take the time to upgrade 'test -e' in > this test file to use newer standard. This test script is probably relatively quiescent right now, so such cleanup may be reasonable. Since it is conceptually distinct from the purpose of the current patch, you would want to do the cleanup as a preparatory patch, thus making this a 2-patch series. >> > +test_expect_success 'git clean -e --exclude-from' ' >> > + rm -fr repo && >> > + mkdir repo && >> > + ( >> > + cd repo && >> > + git init && >> > + touch known 1 2 3 && >> > + git add known && >> > + echo 1 >> .git/clean-exclude && >> > + git clean -f -e 2 --exclude-from=.git/clean-exclude && >> > + test -e 1 && >> > + test -e 2 && >> > + ! (test -e 3) && >> > + test -e known >> > + ) >> > +' >> >> Should a test be added which uses --exclude-from multiple times in the >> same git-clean invocation? > > That does make sense will do. > >> Would it make sense add a test checking the behavior when the file >> named by --exclude-from doesn't exist or is otherwise unusable as an >> exclusion file? > > At the moment the add_excludes_from_file function will exit the program if > there is a problem loading the exclude file. > I could add a test for that behavior. In case in the future this behavior is > changed. ^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH v2 1/2] modernize t7300 2015-12-01 22:25 ` Eric Sunshine @ 2015-12-06 14:58 ` James 2015-12-06 14:58 ` [PATCH v2 2/2] clean: new option --exclude-from James ` (2 more replies) 0 siblings, 3 replies; 21+ messages in thread From: James @ 2015-12-06 14:58 UTC (permalink / raw) To: git; +Cc: James Rouzier, sunshine From: James Rouzier <rouzier@gmail.com> --- t/t7300-clean.sh | 382 +++++++++++++++++++++++++++---------------------------- 1 file changed, 190 insertions(+), 192 deletions(-) diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh index 86ceb38..d555bb6 100755 --- a/t/t7300-clean.sh +++ b/t/t7300-clean.sh @@ -28,15 +28,15 @@ test_expect_success 'git clean with skip-worktree .gitignore' ' mkdir -p build docs && touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && git clean && - test -f Makefile && - test -f README && - test -f src/part1.c && - test -f src/part2.c && - test ! -f a.out && - test ! -f src/part3.c && - test -f docs/manual.txt && - test -f obj.o && - test -f build/lib.so && + test_path_is_file Makefile && + test_path_is_file README && + test_path_is_file src/part1.c && + test_path_is_file src/part2.c && + test_path_is_missing a.out && + test_path_is_missing src/part3.c && + test_path_is_file docs/manual.txt && + test_path_is_file obj.o && + test_path_is_file build/lib.so && git update-index --no-skip-worktree .gitignore && git checkout .gitignore ' @@ -46,15 +46,15 @@ test_expect_success 'git clean' ' mkdir -p build docs && touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && git clean && - test -f Makefile && - test -f README && - test -f src/part1.c && - test -f src/part2.c && - test ! -f a.out && - test ! -f src/part3.c && - test -f docs/manual.txt && - test -f obj.o && - test -f build/lib.so + test_path_is_file Makefile && + test_path_is_file README && + test_path_is_file src/part1.c && + test_path_is_file src/part2.c && + test_path_is_missing a.out && + test_path_is_missing src/part3.c && + test_path_is_file docs/manual.txt && + test_path_is_file obj.o && + test_path_is_file build/lib.so ' @@ -63,15 +63,15 @@ test_expect_success 'git clean src/' ' mkdir -p build docs && touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && git clean src/ && - test -f Makefile && - test -f README && - test -f src/part1.c && - test -f src/part2.c && - test -f a.out && - test ! -f src/part3.c && - test -f docs/manual.txt && - test -f obj.o && - test -f build/lib.so + test_path_is_file Makefile && + test_path_is_file README && + test_path_is_file src/part1.c && + test_path_is_file src/part2.c && + test_path_is_file a.out && + test_path_is_missing src/part3.c && + test_path_is_file docs/manual.txt && + test_path_is_file obj.o && + test_path_is_file build/lib.so ' @@ -80,15 +80,15 @@ test_expect_success 'git clean src/ src/' ' mkdir -p build docs && touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && git clean src/ src/ && - test -f Makefile && - test -f README && - test -f src/part1.c && - test -f src/part2.c && - test -f a.out && - test ! -f src/part3.c && - test -f docs/manual.txt && - test -f obj.o && - test -f build/lib.so + test_path_is_file Makefile && + test_path_is_file README && + test_path_is_file src/part1.c && + test_path_is_file src/part2.c && + test_path_is_file a.out && + test_path_is_missing src/part3.c && + test_path_is_file docs/manual.txt && + test_path_is_file obj.o && + test_path_is_file build/lib.so ' @@ -97,16 +97,16 @@ test_expect_success 'git clean with prefix' ' mkdir -p build docs src/test && touch a.out src/part3.c docs/manual.txt obj.o build/lib.so src/test/1.c && (cd src/ && git clean) && - test -f Makefile && - test -f README && - test -f src/part1.c && - test -f src/part2.c && - test -f a.out && - test ! -f src/part3.c && - test -f src/test/1.c && - test -f docs/manual.txt && - test -f obj.o && - test -f build/lib.so + test_path_is_file Makefile && + test_path_is_file README && + test_path_is_file src/part1.c && + test_path_is_file src/part2.c && + test_path_is_file a.out && + test_path_is_missing src/part3.c && + test_path_is_file src/test/1.c && + test_path_is_file docs/manual.txt && + test_path_is_file obj.o && + test_path_is_file build/lib.so ' @@ -160,16 +160,16 @@ test_expect_success 'git clean -d with prefix and path' ' mkdir -p build docs src/feature && touch a.out src/part3.c src/feature/file.c docs/manual.txt obj.o build/lib.so && (cd src/ && git clean -d feature/) && - test -f Makefile && - test -f README && - test -f src/part1.c && - test -f src/part2.c && - test -f a.out && - test -f src/part3.c && - test ! -f src/feature/file.c && - test -f docs/manual.txt && - test -f obj.o && - test -f build/lib.so + test_path_is_file Makefile && + test_path_is_file README && + test_path_is_file src/part1.c && + test_path_is_file src/part2.c && + test_path_is_file a.out && + test_path_is_file src/part3.c && + test_path_is_missing src/feature/file.c && + test_path_is_file docs/manual.txt && + test_path_is_file obj.o && + test_path_is_file build/lib.so ' @@ -179,16 +179,16 @@ test_expect_success SYMLINKS 'git clean symbolic link' ' touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && ln -s docs/manual.txt src/part4.c && git clean && - test -f Makefile && - test -f README && - test -f src/part1.c && - test -f src/part2.c && - test ! -f a.out && - test ! -f src/part3.c && - test ! -f src/part4.c && - test -f docs/manual.txt && - test -f obj.o && - test -f build/lib.so + test_path_is_file Makefile && + test_path_is_file README && + test_path_is_file src/part1.c && + test_path_is_file src/part2.c && + test_path_is_missing a.out && + test_path_is_missing src/part3.c && + test_path_is_missing src/part4.c && + test_path_is_file docs/manual.txt && + test_path_is_file obj.o && + test_path_is_file build/lib.so ' @@ -196,13 +196,13 @@ test_expect_success 'git clean with wildcard' ' touch a.clean b.clean other.c && git clean "*.clean" && - test -f Makefile && - test -f README && - test -f src/part1.c && - test -f src/part2.c && - test ! -f a.clean && - test ! -f b.clean && - test -f other.c + test_path_is_file Makefile && + test_path_is_file README && + test_path_is_file src/part1.c && + test_path_is_file src/part2.c && + test_path_is_missing a.clean && + test_path_is_missing b.clean && + test_path_is_file other.c ' @@ -211,15 +211,15 @@ test_expect_success 'git clean -n' ' mkdir -p build docs && touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && git clean -n && - test -f Makefile && - test -f README && - test -f src/part1.c && - test -f src/part2.c && - test -f a.out && - test -f src/part3.c && - test -f docs/manual.txt && - test -f obj.o && - test -f build/lib.so + test_path_is_file Makefile && + test_path_is_file README && + test_path_is_file src/part1.c && + test_path_is_file src/part2.c && + test_path_is_file a.out && + test_path_is_file src/part3.c && + test_path_is_file docs/manual.txt && + test_path_is_file obj.o && + test_path_is_file build/lib.so ' @@ -228,15 +228,15 @@ test_expect_success 'git clean -d' ' mkdir -p build docs && touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && git clean -d && - test -f Makefile && - test -f README && - test -f src/part1.c && - test -f src/part2.c && - test ! -f a.out && - test ! -f src/part3.c && - test ! -d docs && - test -f obj.o && - test -f build/lib.so + test_path_is_file Makefile && + test_path_is_file README && + test_path_is_file src/part1.c && + test_path_is_file src/part2.c && + test_path_is_missing a.out && + test_path_is_missing src/part3.c && + test_path_is_missing docs && + test_path_is_file obj.o && + test_path_is_file build/lib.so ' @@ -245,16 +245,16 @@ test_expect_success 'git clean -d src/ examples/' ' mkdir -p build docs examples && touch a.out src/part3.c docs/manual.txt obj.o build/lib.so examples/1.c && git clean -d src/ examples/ && - test -f Makefile && - test -f README && - test -f src/part1.c && - test -f src/part2.c && - test -f a.out && - test ! -f src/part3.c && - test ! -f examples/1.c && - test -f docs/manual.txt && - test -f obj.o && - test -f build/lib.so + test_path_is_file Makefile && + test_path_is_file README && + test_path_is_file src/part1.c && + test_path_is_file src/part2.c && + test_path_is_file a.out && + test_path_is_missing src/part3.c && + test_path_is_missing examples/1.c && + test_path_is_file docs/manual.txt && + test_path_is_file obj.o && + test_path_is_file build/lib.so ' @@ -263,15 +263,15 @@ test_expect_success 'git clean -x' ' mkdir -p build docs && touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && git clean -x && - test -f Makefile && - test -f README && - test -f src/part1.c && - test -f src/part2.c && - test ! -f a.out && - test ! -f src/part3.c && - test -f docs/manual.txt && - test ! -f obj.o && - test -f build/lib.so + test_path_is_file Makefile && + test_path_is_file README && + test_path_is_file src/part1.c && + test_path_is_file src/part2.c && + test_path_is_missing a.out && + test_path_is_missing src/part3.c && + test_path_is_file docs/manual.txt && + test_path_is_missing obj.o && + test_path_is_file build/lib.so ' @@ -280,15 +280,15 @@ test_expect_success 'git clean -d -x' ' mkdir -p build docs && touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && git clean -d -x && - test -f Makefile && - test -f README && - test -f src/part1.c && - test -f src/part2.c && - test ! -f a.out && - test ! -f src/part3.c && - test ! -d docs && - test ! -f obj.o && - test ! -d build + test_path_is_file Makefile && + test_path_is_file README && + test_path_is_file src/part1.c && + test_path_is_file src/part2.c && + test_path_is_missing a.out && + test_path_is_missing src/part3.c && + test_path_is_missing docs && + test_path_is_missing obj.o && + test_path_is_missing build ' @@ -297,15 +297,15 @@ test_expect_success 'git clean -d -x with ignored tracked directory' ' mkdir -p build docs && touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && git clean -d -x -e src && - test -f Makefile && - test -f README && - test -f src/part1.c && - test -f src/part2.c && - test ! -f a.out && - test -f src/part3.c && - test ! -d docs && - test ! -f obj.o && - test ! -d build + test_path_is_file Makefile && + test_path_is_file README && + test_path_is_file src/part1.c && + test_path_is_file src/part2.c && + test_path_is_missing a.out && + test_path_is_file src/part3.c && + test_path_is_missing docs && + test_path_is_missing obj.o && + test_path_is_missing build ' @@ -314,15 +314,15 @@ test_expect_success 'git clean -X' ' mkdir -p build docs && touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && git clean -X && - test -f Makefile && - test -f README && - test -f src/part1.c && - test -f src/part2.c && - test -f a.out && - test -f src/part3.c && - test -f docs/manual.txt && - test ! -f obj.o && - test -f build/lib.so + test_path_is_file Makefile && + test_path_is_file README && + test_path_is_file src/part1.c && + test_path_is_file src/part2.c && + test_path_is_file a.out && + test_path_is_file src/part3.c && + test_path_is_file docs/manual.txt && + test_path_is_missing obj.o && + test_path_is_file build/lib.so ' @@ -331,15 +331,15 @@ test_expect_success 'git clean -d -X' ' mkdir -p build docs && touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && git clean -d -X && - test -f Makefile && - test -f README && - test -f src/part1.c && - test -f src/part2.c && - test -f a.out && - test -f src/part3.c && - test -f docs/manual.txt && - test ! -f obj.o && - test ! -d build + test_path_is_file Makefile && + test_path_is_file README && + test_path_is_file src/part1.c && + test_path_is_file src/part2.c && + test_path_is_file a.out && + test_path_is_file src/part3.c && + test_path_is_file docs/manual.txt && + test_path_is_missing obj.o && + test_path_is_missing build ' @@ -348,15 +348,15 @@ test_expect_success 'git clean -d -X with ignored tracked directory' ' mkdir -p build docs && touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && git clean -d -X -e src && - test -f Makefile && - test -f README && - test -f src/part1.c && - test -f src/part2.c && - test -f a.out && - test ! -f src/part3.c && - test -f docs/manual.txt && - test ! -f obj.o && - test ! -d build + test_path_is_file Makefile && + test_path_is_file README && + test_path_is_file src/part1.c && + test_path_is_file src/part2.c && + test_path_is_file a.out && + test_path_is_missing src/part3.c && + test_path_is_file docs/manual.txt && + test_path_is_missing obj.o && + test_path_is_missing build ' @@ -379,29 +379,29 @@ test_expect_success 'clean.requireForce and -n' ' mkdir -p build docs && touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && git clean -n && - test -f Makefile && - test -f README && - test -f src/part1.c && - test -f src/part2.c && - test -f a.out && - test -f src/part3.c && - test -f docs/manual.txt && - test -f obj.o && - test -f build/lib.so + test_path_is_file Makefile && + test_path_is_file README && + test_path_is_file src/part1.c && + test_path_is_file src/part2.c && + test_path_is_file a.out && + test_path_is_file src/part3.c && + test_path_is_file docs/manual.txt && + test_path_is_file obj.o && + test_path_is_file build/lib.so ' test_expect_success 'clean.requireForce and -f' ' git clean -f && - test -f README && - test -f src/part1.c && - test -f src/part2.c && - test ! -f a.out && - test ! -f src/part3.c && - test -f docs/manual.txt && - test -f obj.o && - test -f build/lib.so + test_path_is_file README && + test_path_is_file src/part1.c && + test_path_is_file src/part2.c && + test_path_is_missing a.out && + test_path_is_missing src/part3.c && + test_path_is_file docs/manual.txt && + test_path_is_file obj.o && + test_path_is_file build/lib.so ' @@ -444,11 +444,11 @@ test_expect_success 'nested git work tree' ' test_commit deeply.nested deeper.world ) && git clean -f -d && - test -f foo/.git/index && - test -f foo/hello.world && - test -f baz/boo/.git/index && - test -f baz/boo/deeper.world && - ! test -d bar + test_path_is_file foo/.git/index && + test_path_is_file foo/hello.world && + test_path_is_file baz/boo/.git/index && + test_path_is_file baz/boo/deeper.world && + test_path_is_missing bar ' test_expect_success 'should clean things that almost look like git but are not' ' @@ -609,32 +609,30 @@ test_expect_success 'force removal of nested git work tree' ' test_commit deeply.nested deeper.world ) && git clean -f -f -d && - ! test -d foo && - ! test -d bar && - ! test -d baz + test_path_is_missing foo && + test_path_is_missing bar && + test_path_is_missing baz ' test_expect_success 'git clean -e' ' rm -fr repo && mkdir repo && - ( - cd repo && - git init && - touch known 1 2 3 && - git add known && - git clean -f -e 1 -e 2 && - test -e 1 && - test -e 2 && - ! (test -e 3) && - test -e known - ) + cd repo && + git init && + touch known 1 2 3 && + git add known && + git clean -f -e 1 -e 2 && + test_path_is_file 1 && + test_path_is_file 2 && + test_path_is_missing 3 && + test_path_is_file known ' test_expect_success SANITY 'git clean -d with an unreadable empty directory' ' mkdir foo && chmod a= foo && git clean -dfx foo && - ! test -d foo + test_path_is_missing foo ' test_expect_success 'git clean -d respects pathspecs (dir is prefix of pathspec)' ' -- 2.3.6 ^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v2 2/2] clean: new option --exclude-from 2015-12-06 14:58 ` [PATCH v2 1/2] modernize t7300 James @ 2015-12-06 14:58 ` James 2015-12-07 20:56 ` Jeff King ` (2 more replies) 2015-12-07 21:40 ` [PATCH v2 1/2] modernize t7300 Junio C Hamano 2015-12-07 22:43 ` Eric Sunshine 2 siblings, 3 replies; 21+ messages in thread From: James @ 2015-12-06 14:58 UTC (permalink / raw) To: git; +Cc: James Rouzier, sunshine From: James Rouzier <rouzier@gmail.com> Specify a file to read for exclude patterns. --- Documentation/git-clean.txt | 5 +++- builtin/clean.c | 15 ++++++++++-- t/t7300-clean.sh | 60 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 3 deletions(-) diff --git a/Documentation/git-clean.txt b/Documentation/git-clean.txt index 641681f..ef5dc41 100644 --- a/Documentation/git-clean.txt +++ b/Documentation/git-clean.txt @@ -8,7 +8,7 @@ git-clean - Remove untracked files from the working tree SYNOPSIS -------- [verse] -'git clean' [-d] [-f] [-i] [-n] [-q] [-e <pattern>] [-x | -X] [--] <path>... +'git clean' [-d] [-f] [-i] [-n] [-q] [-e <pattern>] [--exclude-from=<file>] [-x | -X] [--] <path>... DESCRIPTION ----------- @@ -61,6 +61,9 @@ OPTIONS $GIT_DIR/info/exclude, also consider these patterns to be in the set of the ignore rules in effect. +--exclude-from=<file>:: + Read exclude patterns from <file>; 1 per line. + -x:: Don't use the standard ignore rules read from .gitignore (per directory) and $GIT_DIR/info/exclude, but do still use the ignore diff --git a/builtin/clean.c b/builtin/clean.c index d7acb94..8e652f8 100644 --- a/builtin/clean.c +++ b/builtin/clean.c @@ -22,7 +22,7 @@ static struct string_list del_list = STRING_LIST_INIT_DUP; static unsigned int colopts; static const char *const builtin_clean_usage[] = { - N_("git clean [-d] [-f] [-i] [-n] [-q] [-e <pattern>] [-x | -X] [--] <paths>..."), + N_("git clean [-d] [-f] [-i] [-n] [-q] [-e <pattern>] [--exclude-from=<file>] [-x | -X] [--] <paths>..."), NULL }; @@ -875,6 +875,14 @@ static void interactive_main_loop(void) } } +static int exclude_from_cb(const struct option *opt, + const char *arg, int unset) +{ + struct dir_struct *dir = opt->value; + add_excludes_from_file(dir, arg); + return 0; +} + int cmd_clean(int argc, const char **argv, const char *prefix) { int i, res; @@ -898,12 +906,16 @@ int cmd_clean(int argc, const char **argv, const char *prefix) N_("remove whole directories")), { OPTION_CALLBACK, 'e', "exclude", &exclude_list, N_("pattern"), N_("add <pattern> to ignore rules"), PARSE_OPT_NONEG, exclude_cb }, + { OPTION_CALLBACK, 0, "exclude-from", &dir, N_("file"), + N_("read exclude patterns from <file>"), + 0, exclude_from_cb }, OPT_BOOL('x', NULL, &ignored, N_("remove ignored files, too")), OPT_BOOL('X', NULL, &ignored_only, N_("remove only ignored files")), OPT_END() }; + memset(&dir, 0, sizeof(dir)); git_config(git_clean_config, NULL); if (force < 0) force = 0; @@ -913,7 +925,6 @@ int cmd_clean(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, prefix, options, builtin_clean_usage, 0); - memset(&dir, 0, sizeof(dir)); if (ignored_only) dir.flags |= DIR_SHOW_IGNORED; diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh index d555bb6..c6bfdda 100755 --- a/t/t7300-clean.sh +++ b/t/t7300-clean.sh @@ -628,6 +628,66 @@ test_expect_success 'git clean -e' ' test_path_is_file known ' +test_expect_success 'git clean --exclude-from' ' + rm -fr repo && + mkdir repo && + cd repo && + git init && + touch known 1 2 3 && + git add known && + cat >.git/clean-exclude <<-\EOF && + 1 + 2 + EOF + git clean -f --exclude-from=.git/clean-exclude && + test_path_is_file 1 && + test_path_is_file 2 && + test_path_is_missing 3 && + test_path_is_file known +' + +test_expect_success 'git clean -e --exclude-from' ' + rm -fr repo && + mkdir repo && + cd repo && + git init && + touch known 1 2 3 && + git add known && + echo 1 >> .git/clean-exclude && + git clean -f -e 2 --exclude-from=.git/clean-exclude && + test_path_is_file 1 && + test_path_is_file 2 && + test_path_is_missing 3 && + test_path_is_file known +' + +test_expect_success 'git clean --exclude-from --exclude-from' ' + rm -fr repo && + mkdir repo && + git init && + touch known 1 2 3 && + git add known && + cat >.git/clean-exclude1 <<-\EOF && + 1 + EOF + cat >.git/clean-exclude2 <<-\EOF && + 2 + EOF + git clean -f --exclude-from=.git/clean-exclude1 --exclude-from=.git/clean-exclude2 && + test_path_is_file 1 && + test_path_is_file 2 && + test_path_is_missing 3 && + test_path_is_file known +' + +test_expect_success 'git clean --exclude-from=BADFILE' ' + rm -fr repo && + mkdir repo && + cd repo && + git init && + test_expect_code 128 git clean -f --exclude-from=.git/clean-exclude-not-there +' + test_expect_success SANITY 'git clean -d with an unreadable empty directory' ' mkdir foo && chmod a= foo && -- 2.3.6 ^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [PATCH v2 2/2] clean: new option --exclude-from 2015-12-06 14:58 ` [PATCH v2 2/2] clean: new option --exclude-from James @ 2015-12-07 20:56 ` Jeff King 2015-12-07 21:44 ` Junio C Hamano 2015-12-07 22:53 ` Eric Sunshine 2 siblings, 0 replies; 21+ messages in thread From: Jeff King @ 2015-12-07 20:56 UTC (permalink / raw) To: James; +Cc: git, sunshine On Sun, Dec 06, 2015 at 09:58:26AM -0500, James wrote: > +test_expect_success 'git clean -e --exclude-from' ' > + rm -fr repo && > + mkdir repo && > + cd repo && > + git init && > + touch known 1 2 3 && > + git add known && > + echo 1 >> .git/clean-exclude && > + git clean -f -e 2 --exclude-from=.git/clean-exclude && > + test_path_is_file 1 && > + test_path_is_file 2 && > + test_path_is_missing 3 && > + test_path_is_file known > +' This checks that we exclude the union of the "-e" and "--exclude-from" parameters. What happens if one excludes a path and the other negates the exclusion? How is the precedence handled? Is it based on order on the command-line, or something else? I do not have much of a preference myself, but it probably makes sense to document and test it. > +test_expect_success 'git clean --exclude-from --exclude-from' ' > + rm -fr repo && > + mkdir repo && > + git init && > + touch known 1 2 3 && > + git add known && > + cat >.git/clean-exclude1 <<-\EOF && > + 1 > + EOF > + cat >.git/clean-exclude2 <<-\EOF && > + 2 > + EOF > + git clean -f --exclude-from=.git/clean-exclude1 --exclude-from=.git/clean-exclude2 && > + test_path_is_file 1 && > + test_path_is_file 2 && > + test_path_is_missing 3 && > + test_path_is_file known > +' Ditto here (as the same "type", the only precedence that would make any sense is command-line order here). > +test_expect_success 'git clean --exclude-from=BADFILE' ' > + rm -fr repo && > + mkdir repo && > + cd repo && > + git init && > + test_expect_code 128 git clean -f --exclude-from=.git/clean-exclude-not-there > +' Do you actually care about the 128 here, or is just "it should exit with failure"? If the latter, we usually use test_must_fail. -Peff ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 2/2] clean: new option --exclude-from 2015-12-06 14:58 ` [PATCH v2 2/2] clean: new option --exclude-from James 2015-12-07 20:56 ` Jeff King @ 2015-12-07 21:44 ` Junio C Hamano 2015-12-07 22:53 ` Eric Sunshine 2 siblings, 0 replies; 21+ messages in thread From: Junio C Hamano @ 2015-12-07 21:44 UTC (permalink / raw) To: James; +Cc: git, sunshine James <rouzier@gmail.com> writes: > +static int exclude_from_cb(const struct option *opt, > + const char *arg, int unset) > +{ > + struct dir_struct *dir = opt->value; > + add_excludes_from_file(dir, arg); I suspect this is wrong. add_excludes_from_file() creates a new excludes_list that is separate from the command line level and pushes that down to the exclude stack. You'd instead need to add each line of the input at the same EXC_CMDL level like -e <pattern> option does from the command line, I would think. ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 2/2] clean: new option --exclude-from 2015-12-06 14:58 ` [PATCH v2 2/2] clean: new option --exclude-from James 2015-12-07 20:56 ` Jeff King 2015-12-07 21:44 ` Junio C Hamano @ 2015-12-07 22:53 ` Eric Sunshine 2 siblings, 0 replies; 21+ messages in thread From: Eric Sunshine @ 2015-12-07 22:53 UTC (permalink / raw) To: James; +Cc: Git List In addition to Peff's and Junio's review comments... On Sun, Dec 6, 2015 at 9:58 AM, James <rouzier@gmail.com> wrote: > From: James Rouzier <rouzier@gmail.com> > > Specify a file to read for exclude patterns. Missing Signed-off-by:. > --- > diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh > @@ -628,6 +628,66 @@ test_expect_success 'git clean -e' ' > +test_expect_success 'git clean --exclude-from' ' > + rm -fr repo && > + mkdir repo && > + cd repo && See my review comments for patch 1/2 as to why you want to wrap 'cd' and remaining statements in a subshell. > + git init && > + touch known 1 2 3 && Likewise, use '>' rather than 'touch' to create empty files when the timestamp isn't significant. >1 && >2 && >3 && > + git add known && > + cat >.git/clean-exclude <<-\EOF && > + 1 > + 2 > + EOF > + git clean -f --exclude-from=.git/clean-exclude && > + test_path_is_file 1 && > + test_path_is_file 2 && > + test_path_is_missing 3 && > + test_path_is_file known > +' > + > +test_expect_success 'git clean -e --exclude-from' ' > + rm -fr repo && > + mkdir repo && > + cd repo && > + git init && > + touch known 1 2 3 && > + git add known && > + echo 1 >> .git/clean-exclude && > + git clean -f -e 2 --exclude-from=.git/clean-exclude && > + test_path_is_file 1 && > + test_path_is_file 2 && > + test_path_is_missing 3 && > + test_path_is_file known > +' > + > +test_expect_success 'git clean --exclude-from --exclude-from' ' > + rm -fr repo && > + mkdir repo && > + git init && > + touch known 1 2 3 && > + git add known && > + cat >.git/clean-exclude1 <<-\EOF && > + 1 > + EOF > + cat >.git/clean-exclude2 <<-\EOF && > + 2 > + EOF Creation of these single-line files probably would be more readable using 'echo', as you do in the test just above (for .git/clean-exclude): echo 1 >.git/clean-exclude1 && echo 2 >.git/clean-exclude2 && > + git clean -f --exclude-from=.git/clean-exclude1 --exclude-from=.git/clean-exclude2 && > + test_path_is_file 1 && > + test_path_is_file 2 && > + test_path_is_missing 3 && > + test_path_is_file known > +' > + > +test_expect_success 'git clean --exclude-from=BADFILE' ' > + rm -fr repo && > + mkdir repo && > + cd repo && > + git init && > + test_expect_code 128 git clean -f --exclude-from=.git/clean-exclude-not-there > +' > + > test_expect_success SANITY 'git clean -d with an unreadable empty directory' ' > mkdir foo && > chmod a= foo && > -- > 2.3.6 ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 1/2] modernize t7300 2015-12-06 14:58 ` [PATCH v2 1/2] modernize t7300 James 2015-12-06 14:58 ` [PATCH v2 2/2] clean: new option --exclude-from James @ 2015-12-07 21:40 ` Junio C Hamano 2015-12-07 22:46 ` Eric Sunshine 2015-12-07 22:43 ` Eric Sunshine 2 siblings, 1 reply; 21+ messages in thread From: Junio C Hamano @ 2015-12-07 21:40 UTC (permalink / raw) To: James; +Cc: git, sunshine James <rouzier@gmail.com> writes: > From: James Rouzier <rouzier@gmail.com> > > --- Missing sign-off. > t/t7300-clean.sh | 382 +++++++++++++++++++++++++++---------------------------- > 1 file changed, 190 insertions(+), 192 deletions(-) > > diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh > index 86ceb38..d555bb6 100755 > --- a/t/t7300-clean.sh > +++ b/t/t7300-clean.sh > @@ -28,15 +28,15 @@ test_expect_success 'git clean with skip-worktree .gitignore' ' > mkdir -p build docs && > touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && > git clean && > - test -f Makefile && > - test -f README && > - test -f src/part1.c && > - test -f src/part2.c && > - test ! -f a.out && > - test ! -f src/part3.c && > - test -f docs/manual.txt && > - test -f obj.o && > - test -f build/lib.so && > + test_path_is_file Makefile && > + test_path_is_file README && > + test_path_is_file src/part1.c && > + test_path_is_file src/part2.c && OK. > + test_path_is_missing a.out && > + test_path_is_missing src/part3.c && This is better than the original, which may have said "OK" upon seeing a directory called "a.out". > + test_path_is_file docs/manual.txt && > + test_path_is_file obj.o && > + test_path_is_file build/lib.so && OK. > git update-index --no-skip-worktree .gitignore && > git checkout .gitignore > ' > @@ -46,15 +46,15 @@ test_expect_success 'git clean' ' > mkdir -p build docs && > touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && > git clean && > - test -f Makefile && > - test -f README && > - test -f src/part1.c && > - test -f src/part2.c && > - test ! -f a.out && > - test ! -f src/part3.c && > - test -f docs/manual.txt && > - test -f obj.o && > - test -f build/lib.so > + test_path_is_file Makefile && > + test_path_is_file README && > + test_path_is_file src/part1.c && > + test_path_is_file src/part2.c && > + test_path_is_missing a.out && > + test_path_is_missing src/part3.c && > + test_path_is_file docs/manual.txt && > + test_path_is_file obj.o && > + test_path_is_file build/lib.so The verbosity of this conversion makes me wonder if we want to have "test_paths_are_files" and "test_paths_are_missing". For that matter, this test does not really care about the distinction between files and directories (e.g. some tests said "test ! -d docs" and would have passed if there were a 'docs' regular file, but what we really care about is the path 'docs' is _gone_), so what we want may be test_paths_exist and test_paths_are_missing. With that, the above hunk would become test_paths_exist Makefile README src/part1.c src/part2.c \ obj.o build/lib.so && test_paths_are_missing a.out src/part3.c I dunno. > test_expect_success 'git clean -e' ' > rm -fr repo && > mkdir repo && > - ( > - cd repo && > - git init && > - touch known 1 2 3 && > - git add known && > - git clean -f -e 1 -e 2 && > - test -e 1 && > - test -e 2 && > - ! (test -e 3) && > - test -e known > - ) > + cd repo && > + git init && > + touch known 1 2 3 && > + git add known && > + git clean -f -e 1 -e 2 && > + test_path_is_file 1 && > + test_path_is_file 2 && > + test_path_is_missing 3 && > + test_path_is_file known > ' I think this is wrong. The next test piece will be run inside "repo" directory with this patch applied. Don't lose the subshell here. ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 1/2] modernize t7300 2015-12-07 21:40 ` [PATCH v2 1/2] modernize t7300 Junio C Hamano @ 2015-12-07 22:46 ` Eric Sunshine 2015-12-07 22:50 ` Junio C Hamano 0 siblings, 1 reply; 21+ messages in thread From: Eric Sunshine @ 2015-12-07 22:46 UTC (permalink / raw) To: Junio C Hamano; +Cc: James, Git List On Mon, Dec 7, 2015 at 4:40 PM, Junio C Hamano <gitster@pobox.com> wrote: > James <rouzier@gmail.com> writes: >> @@ -46,15 +46,15 @@ test_expect_success 'git clean' ' >> mkdir -p build docs && >> touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && >> git clean && >> - test -f Makefile && >> - test -f README && >> - test -f src/part1.c && >> - test -f src/part2.c && >> - test ! -f a.out && >> - test ! -f src/part3.c && >> - test -f docs/manual.txt && >> - test -f obj.o && >> - test -f build/lib.so >> + test_path_is_file Makefile && >> + test_path_is_file README && >> + test_path_is_file src/part1.c && >> + test_path_is_file src/part2.c && >> + test_path_is_missing a.out && >> + test_path_is_missing src/part3.c && >> + test_path_is_file docs/manual.txt && >> + test_path_is_file obj.o && >> + test_path_is_file build/lib.so > > The verbosity of this conversion makes me wonder if we want to have > "test_paths_are_files" and "test_paths_are_missing". For that > matter, this test does not really care about the distinction between > files and directories (e.g. some tests said "test ! -d docs" and > would have passed if there were a 'docs' regular file, but what we > really care about is the path 'docs' is _gone_), so what we want may > be test_paths_exist and test_paths_are_missing. With that, the > above hunk would become > > test_paths_exist Makefile README src/part1.c src/part2.c \ > obj.o build/lib.so && > test_paths_are_missing a.out src/part3.c > > I dunno. Alternately, update test_path_foo() functions to accept multiple pathnames, or is that too ugly? ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 1/2] modernize t7300 2015-12-07 22:46 ` Eric Sunshine @ 2015-12-07 22:50 ` Junio C Hamano 0 siblings, 0 replies; 21+ messages in thread From: Junio C Hamano @ 2015-12-07 22:50 UTC (permalink / raw) To: Eric Sunshine; +Cc: James, Git List Eric Sunshine <sunshine@sunshineco.com> writes: > Alternately, update test_path_foo() functions to accept multiple > pathnames, or is that too ugly? That actually would have been my first choice, except (1) that path_is_missing has a cruft whose usefulness is dubious, and (2) that "path_exists A B C" and "path_is_missing D E F" would be gramatically incorrect. I think we should first see if we can remove that "customized message" that appears only in path_is_missing and remove it if we can. Extending "path_is_missing A B C" and friends to work would then become trivial. Thanks. ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 1/2] modernize t7300 2015-12-06 14:58 ` [PATCH v2 1/2] modernize t7300 James 2015-12-06 14:58 ` [PATCH v2 2/2] clean: new option --exclude-from James 2015-12-07 21:40 ` [PATCH v2 1/2] modernize t7300 Junio C Hamano @ 2015-12-07 22:43 ` Eric Sunshine 2 siblings, 0 replies; 21+ messages in thread From: Eric Sunshine @ 2015-12-07 22:43 UTC (permalink / raw) To: James; +Cc: Git List On Sun, Dec 6, 2015 at 9:58 AM, James <rouzier@gmail.com> wrote: > From: James Rouzier <rouzier@gmail.com> This would be a good place to explain how you are modernizing the test script. Right now, you're just updating to take advantage of test_path_is_foo(), but some other modernizations you could do include: * using '>' rather than 'touch' to create empty files when the timestamp doesn't matter (which is all cases in this script) * (optional) replace unnecessarily complex 'mkdir -p foo' with simpler 'mkdir foo' (but leave "mkdir -p foo/bar" as is) * drop blank lines before and after test body; for instance: test_expect_success 'foo' ' blah && bloo ' becomes: test_expect_success 'foo' ' blah && bloo ' > --- > diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh > @@ -609,32 +609,30 @@ test_expect_success 'force removal of nested git work tree' ' > test_expect_success 'git clean -e' ' > rm -fr repo && > mkdir repo && > - ( > - cd repo && > - git init && > - touch known 1 2 3 && > - git add known && > - git clean -f -e 1 -e 2 && > - test -e 1 && > - test -e 2 && > - ! (test -e 3) && > - test -e known > - ) > + cd repo && The previous working directory is not automatically restored at the end of the test, so this "cd" without corresponding "cd .." causes following tests to execute at the incorrect location. Unfortunately, you can't just place "cd .." at the end of a test since it will be skipped if something before the "cd .." fails. The way the existing code deals with this is by using a subshell: mkdir repo && ( cd repo && ... ) The "cd repo" is inside the subshell, so it doesn't affect the parent shell, and when the subshell exits, the parent shell remains at the correct working directory (regardless of whether the test succeeded or failed). Therefore, you don't want to drop the subshell. > + git init && > + touch known 1 2 3 && > + git add known && > + git clean -f -e 1 -e 2 && > + test_path_is_file 1 && > + test_path_is_file 2 && > + test_path_is_missing 3 && > + test_path_is_file known > ' ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] clean: new option --exclude-from 2015-11-26 14:44 [PATCH] clean: new option --exclude-from James 2015-11-30 2:24 ` Eric Sunshine @ 2015-12-02 0:53 ` Jeff King 2015-12-02 2:18 ` Junio C Hamano 1 sibling, 1 reply; 21+ messages in thread From: Jeff King @ 2015-12-02 0:53 UTC (permalink / raw) To: James; +Cc: git On Thu, Nov 26, 2015 at 09:44:25AM -0500, James wrote: > From: James Rouzier <rouzier@gmail.com> > > Specify a file to read for exclude patterns. > --- Lots of commands care about excludes (e.g., "add", "status"). Should this perhaps be an option to the main "git" to append to the set of excludes? You can kind-of do this already with: git -c core.excludesfile=/path/to/whatever clean ... but of course you might be using core.excludesfile already. I wonder if that config option should take multiple values and respect all of them, rather than last-one-wins. -Peff ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] clean: new option --exclude-from 2015-12-02 0:53 ` [PATCH] clean: new option --exclude-from Jeff King @ 2015-12-02 2:18 ` Junio C Hamano 2015-12-02 2:44 ` Jeff King 0 siblings, 1 reply; 21+ messages in thread From: Junio C Hamano @ 2015-12-02 2:18 UTC (permalink / raw) To: Jeff King; +Cc: James, git Jeff King <peff@peff.net> writes: > On Thu, Nov 26, 2015 at 09:44:25AM -0500, James wrote: > >> From: James Rouzier <rouzier@gmail.com> >> >> Specify a file to read for exclude patterns. >> --- > > Lots of commands care about excludes (e.g., "add", "status"). > > Should this perhaps be an option to the main "git" to append to the set > of excludes? > > You can kind-of do this already with: > > git -c core.excludesfile=/path/to/whatever clean ... > > but of course you might be using core.excludesfile already. I wonder if > that config option should take multiple values and respect all of them, > rather than last-one-wins. It is likely that existing users are already using $HOME/.gitconfig that sets core.excludesfile=$HOME/.gitconfig as the personal fallback, that is overriden, not tweaked, by project specific settings of the same variable in .git/config, so that would not fly very well, I suspect. ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] clean: new option --exclude-from 2015-12-02 2:18 ` Junio C Hamano @ 2015-12-02 2:44 ` Jeff King 2015-12-02 16:40 ` Junio C Hamano 0 siblings, 1 reply; 21+ messages in thread From: Jeff King @ 2015-12-02 2:44 UTC (permalink / raw) To: Junio C Hamano; +Cc: James, git On Tue, Dec 01, 2015 at 06:18:30PM -0800, Junio C Hamano wrote: > > Should this perhaps be an option to the main "git" to append to the set > > of excludes? > > > > You can kind-of do this already with: > > > > git -c core.excludesfile=/path/to/whatever clean ... > > > > but of course you might be using core.excludesfile already. I wonder if > > that config option should take multiple values and respect all of them, > > rather than last-one-wins. > > It is likely that existing users are already using $HOME/.gitconfig > that sets core.excludesfile=$HOME/.gitconfig as the personal > fallback, that is overriden, not tweaked, by project specific > settings of the same variable in .git/config, so that would not fly > very well, I suspect. Maybe. I would think the more common setup is: 1. Personal exclude files (e.g., your editor's backup files) come from ~/.gitconfig. 2. Per-project personal excludes go directly into .git/info/exclude. But you're right that it would be a backwards-incompatible change. -Peff ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] clean: new option --exclude-from 2015-12-02 2:44 ` Jeff King @ 2015-12-02 16:40 ` Junio C Hamano 2015-12-02 16:47 ` Jeff King 0 siblings, 1 reply; 21+ messages in thread From: Junio C Hamano @ 2015-12-02 16:40 UTC (permalink / raw) To: Jeff King; +Cc: James, git Jeff King <peff@peff.net> writes: > On Tue, Dec 01, 2015 at 06:18:30PM -0800, Junio C Hamano wrote: > >> It is likely that existing users are already using $HOME/.gitconfig >> that sets core.excludesfile=$HOME/.gitconfig as the personal >> fallback, that is overriden, not tweaked, by project specific >> settings of the same variable in .git/config, so that would not fly >> very well, I suspect. > > Maybe. I would think the more common setup is: > > 1. Personal exclude files (e.g., your editor's backup files) come from > ~/.gitconfig. > > 2. Per-project personal excludes go directly into .git/info/exclude. > > But you're right that it would be a backwards-incompatible change. No question about it, but at the same time I can sort of see how useful being able to read from more than one would be. But for this particular one, I viewed the topic as adding a new option as a shorter way for passing multiple -e <pattern> options on the command line. When viewed that way, even if core.excludesfile were multi-valued, I wouldn't have imagined that people would try to use that mechanism for such a purpose--for one thing, the precedence order is wrong for that purpose, isn't it? ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] clean: new option --exclude-from 2015-12-02 16:40 ` Junio C Hamano @ 2015-12-02 16:47 ` Jeff King 2015-12-02 17:25 ` Junio C Hamano 0 siblings, 1 reply; 21+ messages in thread From: Jeff King @ 2015-12-02 16:47 UTC (permalink / raw) To: Junio C Hamano; +Cc: James, git On Wed, Dec 02, 2015 at 08:40:05AM -0800, Junio C Hamano wrote: > But for this particular one, I viewed the topic as adding a new > option as a shorter way for passing multiple -e <pattern> options on > the command line. When viewed that way, even if core.excludesfile > were multi-valued, I wouldn't have imagined that people would try to > use that mechanism for such a purpose--for one thing, the precedence > order is wrong for that purpose, isn't it? Good point. I didn't think about precedence at all. I perhaps shouldn't have brought up core.excludesfile as all. I only meant it as "you maybe can hack your way through to this without adding any code". I think a real option to do git-wide excludes would probably be more like: git --exclude-from=/path/to/file clean ... and that in turn would probably set GIT_EXCLUDE_FROM to a colon-separated list of paths (or similar) so that sub-processes would respect it, too. On the other hand, one could make the same argument about the existing "-e". You cannot do: git add --exclude='*.o' . right now. So maybe "clean" is really the only place where people care about such ad-hoc exclusion. Or maybe this an opportunity to add: git --exclude='*.o' clean I dunno. I cannot think of a time when I would have used any of those options myself. -Peff ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] clean: new option --exclude-from 2015-12-02 16:47 ` Jeff King @ 2015-12-02 17:25 ` Junio C Hamano 2015-12-02 17:51 ` Jeff King 0 siblings, 1 reply; 21+ messages in thread From: Junio C Hamano @ 2015-12-02 17:25 UTC (permalink / raw) To: Jeff King; +Cc: James, git Jeff King <peff@peff.net> writes: > .... So maybe "clean" is really the only place where people care > about such ad-hoc exclusion. Or maybe this an opportunity to add: > > git --exclude='*.o' clean > > I dunno. I cannot think of a time when I would have used any of those > options myself. Me either and I do not think I ever wanted to use -e to "clean". I do not think we should liberally add options that apply to anything "git" in the first place [*1*]. Limit them to ones that are really special and fundamental that changes the way Git operates, i.e. "Where is our $GIT_DIR?" is a good thing for users to be able to tell "git" itself. Compared to that, the ignore patterns is a fringe that is used only by commands that care about the working tree (e.g. the global option in "git --exclude='*.o' ls-tree" would be meaningless). [Footnote] *1* It would add unnecessary confusion to the end users; they have to decide if they need to pass an option before or after the subcommand name. If the motivation behind the "git --option cmd" is to share code and semantics for common "--option", we should instead further refactor command line option handling, just like the code for config handling allows us to share config_default. ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] clean: new option --exclude-from 2015-12-02 17:25 ` Junio C Hamano @ 2015-12-02 17:51 ` Jeff King 2015-12-06 3:51 ` Junio C Hamano 0 siblings, 1 reply; 21+ messages in thread From: Jeff King @ 2015-12-02 17:51 UTC (permalink / raw) To: Junio C Hamano; +Cc: James, git On Wed, Dec 02, 2015 at 09:25:24AM -0800, Junio C Hamano wrote: > I do not think we should liberally add options that apply to > anything "git" in the first place [*1*]. Limit them to ones that > are really special and fundamental that changes the way Git > operates, i.e. "Where is our $GIT_DIR?" is a good thing for users to > be able to tell "git" itself. Compared to that, the ignore patterns > is a fringe that is used only by commands that care about the > working tree (e.g. the global option in "git --exclude='*.o' > ls-tree" would be meaningless). > > > [Footnote] > > *1* It would add unnecessary confusion to the end users; they have > to decide if they need to pass an option before or after the > subcommand name. If the motivation behind the "git --option cmd" > is to share code and semantics for common "--option", we should > instead further refactor command line option handling, just like > the code for config handling allows us to share config_default. My motivation isn't exactly code sharing. It is that you sometimes want to affect sub-commands of a program, and cannot pass command line options to them yourself. For instance, "git-stash --include-untracked" will call "git clean" under the hood. There is no way to say "...and treat foo.* as ignored for this invocation". It could grow its own "-e" option, but that does not help any other third-party scripts which call "git clean". So IMHO this is not really about command-line options, but about the environment in which a command is executed. Environment variables are the obvious way to do that; "git --foo" options are just syntactic sugar to set the variables. We could just add variables without matching options. I agree that we could end up proliferating such options (or environment variables). Using the logic above, you could argue that I should be able to affect any option of any sub-command in a script, which just gets silly. My rule of thumb would be that if there is some implicit state in the on-disk repo (e.g., what is in your .git/config) that you might want to override for a one-shot invocation, then it may be a reasonable candidate. The "git -c" config override is such an example. In this case, it is basically adding to ".git/info/exclude", which follows the same rule. But like I said, I do not feel all that strongly about this particular option. I would not use it myself. Just trying to make my reasoning clear. :) -Peff ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] clean: new option --exclude-from 2015-12-02 17:51 ` Jeff King @ 2015-12-06 3:51 ` Junio C Hamano 2015-12-07 19:39 ` Jeff King 0 siblings, 1 reply; 21+ messages in thread From: Junio C Hamano @ 2015-12-06 3:51 UTC (permalink / raw) To: Jeff King; +Cc: James, git Jeff King <peff@peff.net> writes: > My motivation isn't exactly code sharing. It is that you sometimes want > to affect sub-commands of a program, and cannot pass command line > options to them yourself. > > For instance, "git-stash --include-untracked" will call "git clean" > under the hood. There is no way to say "...and treat foo.* as ignored > for this invocation". It could grow its own "-e" option, but that does > not help any other third-party scripts which call "git clean". > > So IMHO this is not really about command-line options, but about the > environment in which a command is executed. Environment variables are > the obvious way to do that; "git --foo" options are just syntactic sugar > to set the variables. We could just add variables without matching > options. I'd be even more wary of that, as different commands use ignore patterns for different purposes. A script may invoke "clean" and "add" and would want to use different sets of ignore patterns to emulate "precious" class (which we do not have), for example, by giving a wider ignore pattern for "add" to prevent a file that must be kept untracked outside the index while telling "clean -X" that that file is not expendable with a narrower ignore pattern. That is just one example that comes to me without thinking about the issues too hard, so I am reasonably sure that it would hurt the ecosystem to promote that the ignore pattern can be used for specifying important per-invocation input to a script. In any case, what we've been discussing may be an interesting and potentially important tangent, but it still is a tangent while evaluating the patch in question. I do not think I'd be using the new "--exclude-from=<file>" option to "clean" (simply because I do not think I've ever used the existing "-e" option to it unless I am merely testing the command to make sure it works as advertised) myself, but I do not immediately see how it would hurt us in the future to add it now. So... ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] clean: new option --exclude-from 2015-12-06 3:51 ` Junio C Hamano @ 2015-12-07 19:39 ` Jeff King 0 siblings, 0 replies; 21+ messages in thread From: Jeff King @ 2015-12-07 19:39 UTC (permalink / raw) To: Junio C Hamano; +Cc: James, git On Sat, Dec 05, 2015 at 07:51:03PM -0800, Junio C Hamano wrote: > In any case, what we've been discussing may be an interesting and > potentially important tangent, but it still is a tangent while > evaluating the patch in question. I do not think I'd be using the > new "--exclude-from=<file>" option to "clean" (simply because I do > not think I've ever used the existing "-e" option to it unless I am > merely testing the command to make sure it works as advertised) > myself, but I do not immediately see how it would hurt us in the > future to add it now. So... I think that is OK. The reason I brought it up was "let's stop and make sure we don't want to go this other route before we add more potentially redundant options that we cannot get rid of later". But based on this discussion it is not at all clear that "clean --exclude-from" would become redundant, so let's cross that off as an objection. -Peff ^ permalink raw reply [flat|nested] 21+ messages in thread
end of thread, other threads:[~2015-12-07 22:53 UTC | newest] Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2015-11-26 14:44 [PATCH] clean: new option --exclude-from James 2015-11-30 2:24 ` Eric Sunshine [not found] ` <CAGjXF72PgdjBw03ERVYxj+atvsBXK0LeJ6O3zTZgi3-kv9BWsw@mail.gmail.com> 2015-12-01 22:25 ` Eric Sunshine 2015-12-06 14:58 ` [PATCH v2 1/2] modernize t7300 James 2015-12-06 14:58 ` [PATCH v2 2/2] clean: new option --exclude-from James 2015-12-07 20:56 ` Jeff King 2015-12-07 21:44 ` Junio C Hamano 2015-12-07 22:53 ` Eric Sunshine 2015-12-07 21:40 ` [PATCH v2 1/2] modernize t7300 Junio C Hamano 2015-12-07 22:46 ` Eric Sunshine 2015-12-07 22:50 ` Junio C Hamano 2015-12-07 22:43 ` Eric Sunshine 2015-12-02 0:53 ` [PATCH] clean: new option --exclude-from Jeff King 2015-12-02 2:18 ` Junio C Hamano 2015-12-02 2:44 ` Jeff King 2015-12-02 16:40 ` Junio C Hamano 2015-12-02 16:47 ` Jeff King 2015-12-02 17:25 ` Junio C Hamano 2015-12-02 17:51 ` Jeff King 2015-12-06 3:51 ` Junio C Hamano 2015-12-07 19:39 ` Jeff King
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).