* [PATCH 1/9] grep: use get_pathspec() correctly
2011-05-10 5:51 ` [PATCH 0/9] magic pathspec updates Junio C Hamano
@ 2011-05-10 5:51 ` Junio C Hamano
2011-05-10 5:51 ` [PATCH 2/9] get_pathspec(): an empty ':' pathspec should stand alone Junio C Hamano
` (8 subsequent siblings)
9 siblings, 0 replies; 28+ messages in thread
From: Junio C Hamano @ 2011-05-10 5:51 UTC (permalink / raw)
To: git; +Cc: pclouds
When there is no remaining string in argv, get_pathspec(prefix, argv)
will return a two-element array that has prefix as the first element,
so there is no need to re-roll that logic in the code that uses
get_pathspec().
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
builtin/grep.c | 8 +-------
1 files changed, 1 insertions(+), 7 deletions(-)
diff --git a/builtin/grep.c b/builtin/grep.c
index 0bf8c01..222dd6d 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -956,13 +956,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
verify_filename(prefix, argv[j]);
}
- if (i < argc)
- paths = get_pathspec(prefix, argv + i);
- else if (prefix) {
- paths = xcalloc(2, sizeof(const char *));
- paths[0] = prefix;
- paths[1] = NULL;
- }
+ paths = get_pathspec(prefix, argv + i);
init_pathspec(&pathspec, paths);
pathspec.max_depth = opt.max_depth;
pathspec.recursive = 1;
--
1.7.5.1.290.g1b565
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 2/9] get_pathspec(): an empty ':' pathspec should stand alone
2011-05-10 5:51 ` [PATCH 0/9] magic pathspec updates Junio C Hamano
2011-05-10 5:51 ` [PATCH 1/9] grep: use get_pathspec() correctly Junio C Hamano
@ 2011-05-10 5:51 ` Junio C Hamano
2011-05-10 5:51 ` [PATCH 3/9] count_pathspec(): return number of elements in pathspec Junio C Hamano
` (7 subsequent siblings)
9 siblings, 0 replies; 28+ messages in thread
From: Junio C Hamano @ 2011-05-10 5:51 UTC (permalink / raw)
To: git; +Cc: pclouds
"git cmd foo :" is a user error; diagnose it as such.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
setup.c | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/setup.c b/setup.c
index 51e354c..c1be388 100644
--- a/setup.c
+++ b/setup.c
@@ -256,6 +256,7 @@ const char **get_pathspec(const char *prefix, const char **pathspec)
const char *entry = *pathspec;
const char **src, **dst;
int prefixlen;
+ int has_root_widen = 0;
if (!prefix && !entry)
return NULL;
@@ -272,10 +273,15 @@ const char **get_pathspec(const char *prefix, const char **pathspec)
dst = pathspec;
prefixlen = prefix ? strlen(prefix) : 0;
while (*src) {
- *(dst++) = prefix_pathspec(prefix, prefixlen, *src);
+ const char *elem = prefix_pathspec(prefix, prefixlen, *src);
+ *(dst++) = elem;
+ if (!elem)
+ has_root_widen = 1;
src++;
}
*dst = NULL;
+ if (has_root_widen && src != pathspec + 1)
+ die("an empty ':' pathspec with other pathspecs");
if (!*pathspec)
return NULL;
return pathspec;
--
1.7.5.1.290.g1b565
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 3/9] count_pathspec(): return number of elements in pathspec
2011-05-10 5:51 ` [PATCH 0/9] magic pathspec updates Junio C Hamano
2011-05-10 5:51 ` [PATCH 1/9] grep: use get_pathspec() correctly Junio C Hamano
2011-05-10 5:51 ` [PATCH 2/9] get_pathspec(): an empty ':' pathspec should stand alone Junio C Hamano
@ 2011-05-10 5:51 ` Junio C Hamano
2011-05-10 13:29 ` Nguyen Thai Ngoc Duy
2011-05-10 5:51 ` [PATCH 4/9] add ":" is a pathspec that is too wide Junio C Hamano
` (6 subsequent siblings)
9 siblings, 1 reply; 28+ messages in thread
From: Junio C Hamano @ 2011-05-10 5:51 UTC (permalink / raw)
To: git; +Cc: pclouds
When fed a non-empty argv[], get_pathspec(prefix, argv) used to always
return an array of string that has the same number of elements as argv[]
had, but with ":" (work at toplevel without any path limit) magic pathspec
it can return zero elements. Passing the result from get_pathspec() to
this function will always give the correct number of pathspec elements.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
cache.h | 3 ++-
setup.c | 10 ++++++++++
2 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/cache.h b/cache.h
index be6ce72..6170dce 100644
--- a/cache.h
+++ b/cache.h
@@ -425,7 +425,8 @@ extern void set_git_work_tree(const char *tree);
#define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
-extern const char **get_pathspec(const char *prefix, const char **pathspec);
+extern const char **get_pathspec(const char *prefix, const char **argv);
+extern int count_pathspec(const char **pathspec);
extern void setup_work_tree(void);
extern const char *setup_git_directory_gently(int *);
extern const char *setup_git_directory(void);
diff --git a/setup.c b/setup.c
index c1be388..cab9ddd 100644
--- a/setup.c
+++ b/setup.c
@@ -287,6 +287,16 @@ const char **get_pathspec(const char *prefix, const char **pathspec)
return pathspec;
}
+int count_pathspec(const char **pathspec)
+{
+ int i;
+ if (!pathspec)
+ return 0;
+ for (i = 0; pathspec[i]; i++)
+ ; /* just counting */
+ return i;
+}
+
/*
* Test if it looks like we're at a git directory.
* We want to see:
--
1.7.5.1.290.g1b565
^ permalink raw reply related [flat|nested] 28+ messages in thread
* Re: [PATCH 3/9] count_pathspec(): return number of elements in pathspec
2011-05-10 5:51 ` [PATCH 3/9] count_pathspec(): return number of elements in pathspec Junio C Hamano
@ 2011-05-10 13:29 ` Nguyen Thai Ngoc Duy
0 siblings, 0 replies; 28+ messages in thread
From: Nguyen Thai Ngoc Duy @ 2011-05-10 13:29 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
On Tue, May 10, 2011 at 12:51 PM, Junio C Hamano <gitster@pobox.com> wrote:
> When fed a non-empty argv[], get_pathspec(prefix, argv) used to always
> return an array of string that has the same number of elements as argv[]
> had, but with ":" (work at toplevel without any path limit) magic pathspec
> it can return zero elements. Passing the result from get_pathspec() to
> this function will always give the correct number of pathspec elements.
And use the new function in builtin/rm.c too? A good cleanup while
you're touching cmd_rm()..
--
Duy
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 4/9] add ":" is a pathspec that is too wide
2011-05-10 5:51 ` [PATCH 0/9] magic pathspec updates Junio C Hamano
` (2 preceding siblings ...)
2011-05-10 5:51 ` [PATCH 3/9] count_pathspec(): return number of elements in pathspec Junio C Hamano
@ 2011-05-10 5:51 ` Junio C Hamano
2011-05-10 5:51 ` [PATCH 5/9] git rm ":" is like specifying nothing Junio C Hamano
` (5 subsequent siblings)
9 siblings, 0 replies; 28+ messages in thread
From: Junio C Hamano @ 2011-05-10 5:51 UTC (permalink / raw)
To: git; +Cc: pclouds
"git cmd :" should be exactly the same as "git cmd" run from the root
level of the working tree. "git add" without any pathspec should not
add anything.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
builtin/add.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/builtin/add.c b/builtin/add.c
index e127d5a..43a8aad 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -406,12 +406,12 @@ int cmd_add(int argc, const char **argv, const char *prefix)
(!(addremove || take_worktree_changes)
? ADD_CACHE_IGNORE_REMOVAL : 0));
- if (require_pathspec && argc == 0) {
+ pathspec = validate_pathspec(argc, argv, prefix);
+ if (require_pathspec && (!argc || !pathspec)) {
fprintf(stderr, "Nothing specified, nothing added.\n");
fprintf(stderr, "Maybe you wanted to say 'git add .'?\n");
return 0;
}
- pathspec = validate_pathspec(argc, argv, prefix);
if (read_cache() < 0)
die("index file corrupt");
--
1.7.5.1.290.g1b565
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 5/9] git rm ":" is like specifying nothing
2011-05-10 5:51 ` [PATCH 0/9] magic pathspec updates Junio C Hamano
` (3 preceding siblings ...)
2011-05-10 5:51 ` [PATCH 4/9] add ":" is a pathspec that is too wide Junio C Hamano
@ 2011-05-10 5:51 ` Junio C Hamano
2011-05-10 5:51 ` [PATCH 6/9] clean " Junio C Hamano
` (4 subsequent siblings)
9 siblings, 0 replies; 28+ messages in thread
From: Junio C Hamano @ 2011-05-10 5:51 UTC (permalink / raw)
To: git; +Cc: pclouds
"git cmd :" should be exactly the same as running "git cmd" from the
root level of the working tree. Do not decide solely on the value of
argc (i.e. remaining parameters after options and revs are parsed) to
see if the user limited the operation with paths.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
builtin/rm.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/builtin/rm.c b/builtin/rm.c
index ff491d7..c31f915 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -162,11 +162,13 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
die("index file corrupt");
pathspec = get_pathspec(prefix, argv);
+ if (!pathspec)
+ die("removing nothing?");
refresh_index(&the_index, REFRESH_QUIET, pathspec, NULL, NULL);
seen = NULL;
for (i = 0; pathspec[i] ; i++)
- /* nothing */;
+ ; /* nothing */
seen = xcalloc(i, 1);
for (i = 0; i < active_nr; i++) {
--
1.7.5.1.290.g1b565
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 6/9] clean ":" is like specifying nothing
2011-05-10 5:51 ` [PATCH 0/9] magic pathspec updates Junio C Hamano
` (4 preceding siblings ...)
2011-05-10 5:51 ` [PATCH 5/9] git rm ":" is like specifying nothing Junio C Hamano
@ 2011-05-10 5:51 ` Junio C Hamano
2011-05-10 15:14 ` Thiago Farina
2011-05-10 5:51 ` [PATCH 7/9] mv ":" ":" is like moving nothing from nowhere to nowhere Junio C Hamano
` (3 subsequent siblings)
9 siblings, 1 reply; 28+ messages in thread
From: Junio C Hamano @ 2011-05-10 5:51 UTC (permalink / raw)
To: git; +Cc: pclouds
Adjust argc that is meant to correspond do the number of elements in
the pathspec array.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
builtin/clean.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/builtin/clean.c b/builtin/clean.c
index 4a312ab..686cd6b 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -96,6 +96,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
add_exclude(exclude_list.items[i].string, "", 0, dir.exclude_list);
pathspec = get_pathspec(prefix, argv);
+ argc = count_pathspec(pathspec);
fill_directory(&dir, pathspec);
--
1.7.5.1.290.g1b565
^ permalink raw reply related [flat|nested] 28+ messages in thread
* Re: [PATCH 6/9] clean ":" is like specifying nothing
2011-05-10 5:51 ` [PATCH 6/9] clean " Junio C Hamano
@ 2011-05-10 15:14 ` Thiago Farina
0 siblings, 0 replies; 28+ messages in thread
From: Thiago Farina @ 2011-05-10 15:14 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, pclouds
On Tue, May 10, 2011 at 2:51 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Adjust argc that is meant to correspond do the number of elements in
s/do/to ?
> the pathspec array.
>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
> builtin/clean.c | 1 +
> 1 files changed, 1 insertions(+), 0 deletions(-)
>
> diff --git a/builtin/clean.c b/builtin/clean.c
> index 4a312ab..686cd6b 100644
> --- a/builtin/clean.c
> +++ b/builtin/clean.c
> @@ -96,6 +96,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
> add_exclude(exclude_list.items[i].string, "", 0, dir.exclude_list);
>
> pathspec = get_pathspec(prefix, argv);
> + argc = count_pathspec(pathspec);
>
> fill_directory(&dir, pathspec);
>
> --
> 1.7.5.1.290.g1b565
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 7/9] mv ":" ":" is like moving nothing from nowhere to nowhere
2011-05-10 5:51 ` [PATCH 0/9] magic pathspec updates Junio C Hamano
` (5 preceding siblings ...)
2011-05-10 5:51 ` [PATCH 6/9] clean " Junio C Hamano
@ 2011-05-10 5:51 ` Junio C Hamano
2011-05-10 13:30 ` Nguyen Thai Ngoc Duy
2011-05-10 5:51 ` [PATCH 8/9] checkout ":" is not giving any pathspec Junio C Hamano
` (2 subsequent siblings)
9 siblings, 1 reply; 28+ messages in thread
From: Junio C Hamano @ 2011-05-10 5:51 UTC (permalink / raw)
To: git; +Cc: pclouds
Make sure the code can deal with get_pathspec() that returns nothing.
Strictly speaking it may be a user error, but that is not an excuse
to dump core.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
builtin/mv.c | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/builtin/mv.c b/builtin/mv.c
index 93e8995..38af9f0 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -77,8 +77,12 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
die("index file corrupt");
source = copy_pathspec(prefix, argv, argc, 0);
- modes = xcalloc(argc, sizeof(enum update_mode));
+ if (!source)
+ die("copying from nowhere?");
+ modes = xcalloc(count_pathspec(source), sizeof(enum update_mode));
dest_path = copy_pathspec(prefix, argv + argc, 1, 0);
+ if (!dest_path)
+ die("copying to nowhere?");
if (dest_path[0][0] == '\0')
/* special case: "." was normalized to "" */
--
1.7.5.1.290.g1b565
^ permalink raw reply related [flat|nested] 28+ messages in thread
* Re: [PATCH 7/9] mv ":" ":" is like moving nothing from nowhere to nowhere
2011-05-10 5:51 ` [PATCH 7/9] mv ":" ":" is like moving nothing from nowhere to nowhere Junio C Hamano
@ 2011-05-10 13:30 ` Nguyen Thai Ngoc Duy
0 siblings, 0 replies; 28+ messages in thread
From: Nguyen Thai Ngoc Duy @ 2011-05-10 13:30 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
On Tue, May 10, 2011 at 12:51 PM, Junio C Hamano <gitster@pobox.com> wrote:
> diff --git a/builtin/mv.c b/builtin/mv.c
> index 93e8995..38af9f0 100644
> --- a/builtin/mv.c
> +++ b/builtin/mv.c
> @@ -77,8 +77,12 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
> die("index file corrupt");
>
> source = copy_pathspec(prefix, argv, argc, 0);
> - modes = xcalloc(argc, sizeof(enum update_mode));
> + if (!source)
> + die("copying from nowhere?");
> + modes = xcalloc(count_pathspec(source), sizeof(enum update_mode));
> dest_path = copy_pathspec(prefix, argv + argc, 1, 0);
> + if (!dest_path)
> + die("copying to nowhere?");
>
This command is interesting. Note to self: adding support for "git mv
'*.c' to/there".
I think we could take get_pathspec() out of copy_pathspec() and call
it just once (in case get_pathspec() or its successor does fancy
things), something roughly like this
diff --git a/builtin/mv.c b/builtin/mv.c
index 40f33ca..a032789 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -32,7 +32,7 @@ static const char **copy_pathspec(const char
*prefix, const char **pathspec,
result[i] = base_name ? strdup(basename(it)) : it;
}
}
- return get_pathspec(prefix, result);
+ return result;
}
static const char *add_slash(const char *path)
@@ -60,7 +60,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
OPT_BOOLEAN('k', NULL, &ignore_errors, "skip move/rename errors"),
OPT_END(),
};
- const char **source, **destination, **dest_path;
+ const char **pathspec, **source, **destination, **dest_path;
enum update_mode { BOTH = 0, WORKING_DIRECTORY, INDEX } *modes;
struct stat st;
struct string_list src_for_dst = STRING_LIST_INIT_NODUP;
@@ -69,16 +69,20 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
argc = parse_options(argc, argv, prefix, builtin_mv_options,
builtin_mv_usage, 0);
- if (--argc < 1)
+
+ pathspec = get_pathspec(prefix, argv);
+ argc = count_pathspec(pathspec);
+
+ if (--argc < 1 || !pathspec)
usage_with_options(builtin_mv_usage, builtin_mv_options);
newfd = hold_locked_index(&lock_file, 1);
if (read_cache() < 0)
die(_("index file corrupt"));
- source = copy_pathspec(prefix, argv, argc, 0);
+ source = copy_pathspec(prefix, pathspec, argc, 0);
modes = xcalloc(argc, sizeof(enum update_mode));
- dest_path = copy_pathspec(prefix, argv + argc, 1, 0);
+ dest_path = copy_pathspec(prefix, pathspec + argc, 1, 0);
if (dest_path[0][0] == '\0')
/* special case: "." was normalized to "" */
--
Duy
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 8/9] checkout ":" is not giving any pathspec
2011-05-10 5:51 ` [PATCH 0/9] magic pathspec updates Junio C Hamano
` (6 preceding siblings ...)
2011-05-10 5:51 ` [PATCH 7/9] mv ":" ":" is like moving nothing from nowhere to nowhere Junio C Hamano
@ 2011-05-10 5:51 ` Junio C Hamano
2011-05-10 5:51 ` [PATCH 9/9] t3703, t4208: add test cases for magic pathspec Junio C Hamano
2011-05-10 13:47 ` [PATCH 0/9] magic pathspec updates Nguyen Thai Ngoc Duy
9 siblings, 0 replies; 28+ messages in thread
From: Junio C Hamano @ 2011-05-10 5:51 UTC (permalink / raw)
To: git; +Cc: pclouds
"git cmd :" should be exactly the same as running "git cmd" from the
root level of the working tree. Do not decide solely on the value of
argc (i.e. remaining parameters after options and revs are parsed),
but make sure we actually do have pathspec to switch operation modes.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
builtin/checkout.c | 9 +++------
1 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 2bf02f2..fe46725 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -890,6 +890,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
char *conflict_style = NULL;
int patch_mode = 0;
int dwim_new_local_branch = 1;
+ const char **pathspec;
struct option options[] = {
OPT__QUIET(&opts.quiet, "suppress progress reporting"),
OPT_STRING('b', NULL, &opts.new_branch, "branch",
@@ -1004,12 +1005,8 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
if (opts.track == BRANCH_TRACK_UNSPECIFIED)
opts.track = git_branch_track;
- if (argc) {
- const char **pathspec = get_pathspec(prefix, argv);
-
- if (!pathspec)
- die("invalid path specification");
-
+ pathspec = get_pathspec(prefix, argv);
+ if (argc && pathspec) {
if (patch_mode)
return interactive_checkout(new.name, pathspec, &opts);
--
1.7.5.1.290.g1b565
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 9/9] t3703, t4208: add test cases for magic pathspec
2011-05-10 5:51 ` [PATCH 0/9] magic pathspec updates Junio C Hamano
` (7 preceding siblings ...)
2011-05-10 5:51 ` [PATCH 8/9] checkout ":" is not giving any pathspec Junio C Hamano
@ 2011-05-10 5:51 ` Junio C Hamano
2011-05-12 8:21 ` [PATCH jc/magic-pathspec] t3703: Skip tests using directory name ":" on Windows Johannes Sixt
2011-05-29 18:29 ` [PATCH 9/9] t3703, t4208: add test cases for magic pathspec Ævar Arnfjörð Bjarmason
2011-05-10 13:47 ` [PATCH 0/9] magic pathspec updates Nguyen Thai Ngoc Duy
9 siblings, 2 replies; 28+ messages in thread
From: Junio C Hamano @ 2011-05-10 5:51 UTC (permalink / raw)
To: git; +Cc: pclouds
From: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
While at it, also document ":" syntax.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
Documentation/glossary-content.txt | 3 +
t/t3703-add-magic-pathspec.sh | 78 ++++++++++++++++++++++++++++++++++++
t/t4208-log-magic-pathspec.sh | 45 +++++++++++++++++++++
3 files changed, 126 insertions(+), 0 deletions(-)
create mode 100755 t/t3703-add-magic-pathspec.sh
create mode 100755 t/t4208-log-magic-pathspec.sh
diff --git a/Documentation/glossary-content.txt b/Documentation/glossary-content.txt
index 0ca029b..0318024 100644
--- a/Documentation/glossary-content.txt
+++ b/Documentation/glossary-content.txt
@@ -327,6 +327,9 @@ icase;;
+
It is envisioned that we will support more types of magic in later
versions of git.
++
+A pathspec with only a colon means "there is no pathspec". This form
+should not be combined with other pathspec.
[[def_parent]]parent::
A <<def_commit_object,commit object>> contains a (possibly empty) list
diff --git a/t/t3703-add-magic-pathspec.sh b/t/t3703-add-magic-pathspec.sh
new file mode 100755
index 0000000..9e6708a
--- /dev/null
+++ b/t/t3703-add-magic-pathspec.sh
@@ -0,0 +1,78 @@
+#!/bin/sh
+
+test_description='magic pathspec tests using git-add'
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+ mkdir sub anothersub &&
+ : >sub/foo &&
+ : >anothersub/foo
+'
+
+test_expect_success 'colon alone magic should only used alone' '
+ test_must_fail git add -n sub/foo : &&
+ test_must_fail git add -n : sub/foo
+'
+
+test_expect_success 'add :' '
+ : >expected &&
+ (cd sub && git add -n : >actual) &&
+ test_cmp expected sub/actual
+'
+
+test_expect_success 'add :/' "
+ cat >expected <<-EOF &&
+ add 'anothersub/foo'
+ add 'expected'
+ add 'sub/actual'
+ add 'sub/foo'
+ EOF
+ (cd sub && git add -n :/ >actual) &&
+ test_cmp expected sub/actual
+"
+
+cat >expected <<EOF
+add 'anothersub/foo'
+EOF
+
+test_expect_success 'add :/anothersub' '
+ (cd sub && git add -n :/anothersub >actual) &&
+ test_cmp expected sub/actual
+'
+
+test_expect_success 'add :/non-existent' '
+ (cd sub && test_must_fail git add -n :/non-existent)
+'
+
+cat >expected <<EOF
+add 'sub/foo'
+EOF
+
+test_expect_success 'add :(icase)foo' '
+ (cd sub && git add -n ":(icase)FoO" >actual) &&
+ test_cmp expected sub/actual
+'
+
+test_expect_success 'a file with the same (long) magic name exists' '
+ : >":(icase)ha" &&
+ test_must_fail git add -n ":(icase)ha" 2>error &&
+ git add -n "./:(icase)ha"
+'
+
+cat >expected <<EOF
+fatal: pathspec ':(icase)ha' did not match any files
+EOF
+
+test_expect_failure 'show pathspecs exactly what are typed in' '
+ test_cmp expected error
+'
+
+test_expect_success 'a file with the same (short) magic name exists' '
+ mkdir ":" &&
+ : >":/bar" &&
+ test_must_fail git add -n :/bar &&
+ git add -n "./:/bar"
+'
+
+test_done
diff --git a/t/t4208-log-magic-pathspec.sh b/t/t4208-log-magic-pathspec.sh
new file mode 100755
index 0000000..ff7f485
--- /dev/null
+++ b/t/t4208-log-magic-pathspec.sh
@@ -0,0 +1,45 @@
+#!/bin/sh
+
+test_description='magic pathspec tests using git-log'
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+ test_commit initial &&
+ test_tick &&
+ git commit --allow-empty -m empty &&
+ mkdir sub
+'
+
+test_expect_failure '"git log :/" should be ambiguous' '
+ test_must_fail git log :/ 2>error &&
+ grep ambiguous error
+'
+
+test_expect_failure '"git log :" should be ambiguous' '
+ test_must_fail git log : 2>error &&
+ grep ambiguous error
+'
+
+test_expect_success 'git log -- :' '
+ git log -- :
+'
+
+test_expect_success 'git log HEAD -- :/' '
+ cat >expected <<-EOF &&
+ 24b24cf initial
+ EOF
+ (cd sub && git log --oneline HEAD -- :/ >../actual) &&
+ test_cmp expected actual
+'
+
+test_expect_success 'git log HEAD -- :' '
+ cat >expected <<-EOF &&
+ 41d179c empty
+ 24b24cf initial
+ EOF
+ (cd sub && git log --oneline HEAD -- : >../actual) &&
+ test_cmp expected actual
+'
+
+test_done
--
1.7.5.1.290.g1b565
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH jc/magic-pathspec] t3703: Skip tests using directory name ":" on Windows
2011-05-10 5:51 ` [PATCH 9/9] t3703, t4208: add test cases for magic pathspec Junio C Hamano
@ 2011-05-12 8:21 ` Johannes Sixt
2011-05-29 18:29 ` [PATCH 9/9] t3703, t4208: add test cases for magic pathspec Ævar Arnfjörð Bjarmason
1 sibling, 0 replies; 28+ messages in thread
From: Johannes Sixt @ 2011-05-12 8:21 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, pclouds
From: Johannes Sixt <j6t@kdbg.org>
":" is not allowed in file names on Windows. Detect this case and skip a
test if necessary.
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
---
t/t3703-add-magic-pathspec.sh | 8 ++++++--
1 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/t/t3703-add-magic-pathspec.sh b/t/t3703-add-magic-pathspec.sh
index ce5585e..e508246 100755
--- a/t/t3703-add-magic-pathspec.sh
+++ b/t/t3703-add-magic-pathspec.sh
@@ -44,8 +44,12 @@ test_expect_success 'a file with the same (long) magic name exists' '
git add -n "./:(icase)ha"
'
-test_expect_success 'a file with the same (short) magic name exists' '
- mkdir ":" &&
+if mkdir ":" 2>/dev/null
+then
+ test_set_prereq COLON_DIR
+fi
+
+test_expect_success COLON_DIR 'a file with the same (short) magic name exists' '
: >":/bar" &&
test_must_fail git add -n :/bar &&
git add -n "./:/bar"
--
1.7.5.1.1644.g7f2ed
^ permalink raw reply related [flat|nested] 28+ messages in thread
* Re: [PATCH 9/9] t3703, t4208: add test cases for magic pathspec
2011-05-10 5:51 ` [PATCH 9/9] t3703, t4208: add test cases for magic pathspec Junio C Hamano
2011-05-12 8:21 ` [PATCH jc/magic-pathspec] t3703: Skip tests using directory name ":" on Windows Johannes Sixt
@ 2011-05-29 18:29 ` Ævar Arnfjörð Bjarmason
2011-05-29 20:31 ` Junio C Hamano
1 sibling, 1 reply; 28+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2011-05-29 18:29 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, pclouds
On Tue, May 10, 2011 at 07:51, Junio C Hamano <gitster@pobox.com> wrote:
> +test_expect_success 'add :/' "
> + cat >expected <<-EOF &&
> + add 'anothersub/foo'
> + add 'expected'
> + add 'sub/actual'
> + add 'sub/foo'
> + EOF
> + (cd sub && git add -n :/ >actual) &&
> + test_cmp expected sub/actual
> +"
This needs to use test_i18ncmp.
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 9/9] t3703, t4208: add test cases for magic pathspec
2011-05-29 18:29 ` [PATCH 9/9] t3703, t4208: add test cases for magic pathspec Ævar Arnfjörð Bjarmason
@ 2011-05-29 20:31 ` Junio C Hamano
2011-05-29 20:36 ` Ævar Arnfjörð Bjarmason
0 siblings, 1 reply; 28+ messages in thread
From: Junio C Hamano @ 2011-05-29 20:31 UTC (permalink / raw)
To: Ævar Arnfjörð Bjarmason; +Cc: Junio C Hamano, git, pclouds
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
> On Tue, May 10, 2011 at 07:51, Junio C Hamano <gitster@pobox.com> wrote:
>
>> +test_expect_success 'add :/' "
>> + cat >expected <<-EOF &&
>> + add 'anothersub/foo'
>> + add 'expected'
>> + add 'sub/actual'
>> + add 'sub/foo'
>> + EOF
>> + (cd sub && git add -n :/ >actual) &&
>> + test_cmp expected sub/actual
>> +"
>
> This needs to use test_i18ncmp.
I don't think so (at least not yet).
Doesn't it come from read-cache.c::add_to_index()?
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 9/9] t3703, t4208: add test cases for magic pathspec
2011-05-29 20:31 ` Junio C Hamano
@ 2011-05-29 20:36 ` Ævar Arnfjörð Bjarmason
0 siblings, 0 replies; 28+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2011-05-29 20:36 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, pclouds
On Sun, May 29, 2011 at 22:31, Junio C Hamano <gitster@pobox.com> wrote:
>> This needs to use test_i18ncmp.
>
> I don't think so (at least not yet).
>
> Doesn't it come from read-cache.c::add_to_index()?
Doh, this was because I had a local patch by Jonathan in my tree that
I forgot was there. Sorry about the noise.
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 0/9] magic pathspec updates
2011-05-10 5:51 ` [PATCH 0/9] magic pathspec updates Junio C Hamano
` (8 preceding siblings ...)
2011-05-10 5:51 ` [PATCH 9/9] t3703, t4208: add test cases for magic pathspec Junio C Hamano
@ 2011-05-10 13:47 ` Nguyen Thai Ngoc Duy
2011-05-10 17:07 ` Junio C Hamano
9 siblings, 1 reply; 28+ messages in thread
From: Nguyen Thai Ngoc Duy @ 2011-05-10 13:47 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
On Tue, May 10, 2011 at 12:51 PM, Junio C Hamano <gitster@pobox.com> wrote:
> This is a series to update the magic pathspec topic, primarily the area
> around the empty ':' pathspec.
I think you missed git-commit and git-reset. "git commit --include :"
may get past parse_and_validate_options() (ie. not dying) but later on
in prepare_index(), there's no pathspec. I did not check very careful
though.
> Other than that, I think the current code is probably more or less safe to
> dogfood with known rough edges.
Agreed.
--
Duy
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 0/9] magic pathspec updates
2011-05-10 13:47 ` [PATCH 0/9] magic pathspec updates Nguyen Thai Ngoc Duy
@ 2011-05-10 17:07 ` Junio C Hamano
2011-05-11 12:11 ` Nguyen Thai Ngoc Duy
0 siblings, 1 reply; 28+ messages in thread
From: Junio C Hamano @ 2011-05-10 17:07 UTC (permalink / raw)
To: Nguyen Thai Ngoc Duy; +Cc: git
Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:
> On Tue, May 10, 2011 at 12:51 PM, Junio C Hamano <gitster@pobox.com> wrote:
>> This is a series to update the magic pathspec topic, primarily the area
>> around the empty ':' pathspec.
>
> I think you missed git-commit and git-reset. "git commit --include :"
> may get past parse_and_validate_options() (ie. not dying) but later on
> in prepare_index(), there's no pathspec. I did not check very careful
> though.
>
>> Other than that, I think the current code is probably more or less safe to
>> dogfood with known rough edges.
>
> Agreed.
After re-reading the series one more time (including the ones that are
already in next), I think teaching get_pathspec() about a lone ":" was
probably a bad idea. The only reason we might want to say "there is no
pathspec whatsoever" is when a command wants to limit its operation to
the current subdirectory and it changes behaviour when run at the root
level with and without pathspec (e.g. history simplification).
Note that no such command exists in our vocabulary today, so you need
to imagine "git local-log" that acts like "git log" but by default
shows history simplified to explain only the subdirectory you are
currently in, or something.
Such an application can easily notice that argv[] has only a lone ":"
left and do the same thing it does when there is no pathspec, without
affecting other (existing) users of get_pathspec().
But the thing is, we do not have such an application like "local-log"
now, we know we can easily support such commands when needed without
teaching get_pathspec() about a lone ":", and we can be sure that
existing commands that know get_pathspec() will never give them an
empty pathspec if they feed a non-empty argv[] will not be broken by
not teaching get_pathspec() about a lone ":".
I am leaning toward ripping the lone ":" support from the code in
"next". I would also remove ":(icase)" from "next". It was only meant
to be a POC to show how far we could go only by futzing get_pathspec()
function, and was never meant to be a serious implementation of the
feature. It should be re-done after we do deeper conversion and use
the "struct pathspec" interface not "char **" interface.
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 0/9] magic pathspec updates
2011-05-10 17:07 ` Junio C Hamano
@ 2011-05-11 12:11 ` Nguyen Thai Ngoc Duy
0 siblings, 0 replies; 28+ messages in thread
From: Nguyen Thai Ngoc Duy @ 2011-05-11 12:11 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
On Wed, May 11, 2011 at 12:07 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Note that no such command exists in our vocabulary today, so you need
> to imagine "git local-log" that acts like "git log" but by default
> shows history simplified to explain only the subdirectory you are
> currently in, or something.
>
> Such an application can easily notice that argv[] has only a lone ":"
> left and do the same thing it does when there is no pathspec, without
> affecting other (existing) users of get_pathspec().
Hmm.. if ":" (the semantics) is only used in few commands, perhaps an
option would be better than the cryptic ":".
> I am leaning toward ripping the lone ":" support from the code in
> "next". I would also remove ":(icase)" from "next". It was only meant
> to be a POC to show how far we could go only by futzing get_pathspec()
> function, and was never meant to be a serious implementation of the
> feature. It should be re-done after we do deeper conversion and use
> the "struct pathspec" interface not "char **" interface.
OK. But reserve the lone ":" syntax. It's precious. We may have a use
case for it some day.
--
Duy
^ permalink raw reply [flat|nested] 28+ messages in thread