Skip to content

Commit 1abf095

Browse files
committed
git-add: adjust to the get_pathspec() changes.
We would need to notice and fail if command line had a nonsense pathspec. Earlier get_pathspec() returned all the inputs including bad ones, but the new one issues warnings and removes offending ones from its return value, so the callers need to be adjusted to notice it. Additional test scripts were initially from Robin Rosenberg, further fixed. Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 097971f commit 1abf095

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

builtin-add.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,18 @@ int cmd_add(int argc, const char **argv, const char *prefix)
228228
goto finish;
229229
}
230230

231+
if (*argv) {
232+
/* Was there an invalid path? */
233+
if (pathspec) {
234+
int num;
235+
for (num = 0; pathspec[num]; num++)
236+
; /* just counting */
237+
if (argc != num)
238+
exit(1); /* error message already given */
239+
} else
240+
exit(1); /* error message already given */
241+
}
242+
231243
fill_directory(&dir, pathspec, ignored_too);
232244

233245
if (show_only) {

t/t7010-setup.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,51 @@ test_expect_success 'git ls-files (relative #3)' '
114114
115115
'
116116

117+
test_expect_success 'commit using absolute path names' '
118+
git commit -m "foo" &&
119+
echo aa >>a/b/c/d &&
120+
git commit -m "aa" "$(pwd)/a/b/c/d"
121+
'
122+
123+
test_expect_success 'log using absolute path names' '
124+
echo bb >>a/b/c/d &&
125+
git commit -m "bb" $(pwd)/a/b/c/d &&
126+
127+
git log a/b/c/d >f1.txt &&
128+
git log "$(pwd)/a/b/c/d" >f2.txt &&
129+
diff -u f1.txt f2.txt
130+
'
131+
132+
test_expect_success 'blame using absolute path names' '
133+
git blame a/b/c/d >f1.txt &&
134+
git blame "$(pwd)/a/b/c/d" >f2.txt &&
135+
diff -u f1.txt f2.txt
136+
'
137+
138+
test_expect_success 'setup deeper work tree' '
139+
test_create_repo tester
140+
'
141+
142+
test_expect_success 'add a directory outside the work tree' '(
143+
cd tester &&
144+
d1="$(cd .. ; pwd)" &&
145+
git add "$d1"
146+
)'
147+
148+
test_expect_success 'add a file outside the work tree, nasty case 1' '(
149+
cd tester &&
150+
f="$(pwd)x" &&
151+
echo "$f" &&
152+
touch "$f" &&
153+
git add "$f"
154+
)'
155+
156+
test_expect_success 'add a file outside the work tree, nasty case 2' '(
157+
cd tester &&
158+
f="$(pwd | sed "s/.$//")x" &&
159+
echo "$f" &&
160+
touch "$f" &&
161+
git add "$f"
162+
)'
163+
117164
test_done

0 commit comments

Comments
 (0)