Dear list,
While I can say something like
git add foo bar foo
(note the doubled foo)
when using git-add from a script, the following fails:
$ git commit -m. foo foo
error: pathspec 'foo' did not match any file(s) known to git.
Did you forget to 'git add'?
I am bringing this up in the context of
http://bugs.debian.org/439992, where debcommit.pl would duplicate
a file argument under certain conditions. It's since been fixed, but
I wonder whether git-commit could be made more robust in the
presence of duplicate arguments? Or is this behaviour by choice?
PS: please keep 439992-quiet@bugs.debian.org on Cc.
--
martin; (greetings from the heart of the sun.)
\____ echo mailto: !#^."<*>"|tr "<*> mailto:" net@madduck
an egg has the shortest sex-life of all: if gets laid once; it gets
eaten once. it also has to come in a box with 11 others, and the
only person who will sit on its face is its mother.
spamtraps: madduck.bogus@madduck.net
The first entry wins, all the subsequent entries will be discarded.
Signed-off-by: Alex Riesen <redacted>
---
martin f krafft, Wed, Aug 29, 2007 10:11:22 +0200:
when using git-add from a script, the following fails:
$ git commit -m. foo foo
error: pathspec 'foo' did not match any file(s) known to git.
Did you forget to 'git add'?
I am bringing this up in the context of
http://bugs.debian.org/439992, where debcommit.pl would duplicate
a file argument under certain conditions. It's since been fixed, but
I wonder whether git-commit could be made more robust in the
presence of duplicate arguments? Or is this behaviour by choice?
Don't think so. Looks like accident. The patch below fixes it,
by introducing a costly argument duplication check. Shouldn't
be a problem for a normal use (git-ls-files expects globs, not
pathnames).
setup.c | 21 +++++++++++++++++----
1 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/setup.c b/setup.c
index 06004f1..b13b628 100644
--- a/setup.c
+++ b/setup.c
@@ -111,10 +111,19 @@ void verify_non_filename(const char *prefix, const char *arg)
die("'%s': %s", arg, strerror(errno));
}
+static const char **has_pathspec(const char **start, const char **end, const char *spec)
+{
+ const char **p;
+ for (p = start; p != end; ++p)
+ if (!strcmp(*p, spec))
+ return p;
+ return NULL;
+}
+
const char **get_pathspec(const char *prefix, const char **pathspec)
{
const char *entry = *pathspec;
- const char **p;
+ const char **in, **out;
int prefixlen;
if (!prefix && !entry)@@ -128,11 +137,15 @@ const char **get_pathspec(const char *prefix, const char **pathspec)
}
/* Otherwise we have to re-write the entries.. */
- p = pathspec;
+ in = out = pathspec;
prefixlen = prefix ? strlen(prefix) : 0;
do {
- *p = prefix_path(prefix, prefixlen, entry);
- } while ((entry = *++p) != NULL);
+ const char *spec = prefix_path(prefix, prefixlen, entry);
+ if (!has_pathspec(pathspec, out, spec))
+ *out++ = spec;
+ } while ((entry = *++in) != NULL);
+ if (in != out)
+ *out = NULL;
return (const char **) pathspec;
}
--
1.5.3.rc7.24.g0e57
also sprach Alex Riesen [off-list ref] [2007.08.29.2144 +0200]:
Signed-off-by: Alex Riesen <redacted>
Signed-off-by: martin f krafft <redacted>
I confirm that Alex' patch does what it should:
$ git init
Initialized empty Git repository in .git/
$ date > a; git add a; git commit -m.
Created initial commit afb6bca: .
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 a
$ date >> a
$ git commit -m. a a
Created commit f41d10a: .
1 files changed, 1 insertions(+), 0 deletions(-)
--
.''`. martin f. krafft [off-list ref]
: :' : proud Debian developer, author, administrator, and user
`. `'` http://people.debian.org/~madduck - http://debiansystem.info
`- Debian - when you have better things to do than fixing systems
"although occasionally there is something to be said for solitude."
-- special agent dale cooper