Skip to content

Commit 500b97e

Browse files
Fredrik KuivinenJunio C Hamano
authored andcommitted
[PATCH] Teach git-ls-files about '--' to denote end of options.
Useful if you have a file whose name starts with a dash. Signed-off-by: Fredrik Kuivinen <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent af21511 commit 500b97e

File tree

3 files changed

+82
-2
lines changed

3 files changed

+82
-2
lines changed

Documentation/git-ls-files.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ SYNOPSIS
1313
(-[c|d|o|i|s|u|k|m])\*
1414
[-x <pattern>|--exclude=<pattern>]
1515
[-X <file>|--exclude-from=<file>]
16-
[--exclude-per-directory=<file>]
16+
[--exclude-per-directory=<file>] [--] [<file>]\*
1717

1818
DESCRIPTION
1919
-----------
@@ -77,6 +77,13 @@ OPTIONS
7777
K to be killed
7878
? other
7979

80+
--::
81+
Do not interpret any more arguments as options.
82+
83+
<file>::
84+
Files to show. If no files are given all files which match the other
85+
specified criteria are shown.
86+
8087
Output
8188
------
8289
show files just outputs the filename unless '--stage' is specified in

ls-files.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ static void verify_pathspec(void)
530530
static const char ls_files_usage[] =
531531
"git-ls-files [-z] [-t] (--[cached|deleted|others|stage|unmerged|killed|modified])* "
532532
"[ --ignored ] [--exclude=<pattern>] [--exclude-from=<file>] "
533-
"[ --exclude-per-directory=<filename> ]";
533+
"[ --exclude-per-directory=<filename> ] [--] [<file>]*";
534534

535535
int main(int argc, const char **argv)
536536
{
@@ -544,6 +544,10 @@ int main(int argc, const char **argv)
544544
for (i = 1; i < argc; i++) {
545545
const char *arg = argv[i];
546546

547+
if (!strcmp(arg, "--")) {
548+
i++;
549+
break;
550+
}
547551
if (!strcmp(arg, "-z")) {
548552
line_terminator = 0;
549553
continue;

t/t3002-ls-files-dashpath.sh

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2005 Junio C Hamano
4+
#
5+
6+
test_description='git-ls-files test (-- to terminate the path list).
7+
8+
This test runs git-ls-files --others with the following on the
9+
filesystem.
10+
11+
path0 - a file
12+
-foo - a file with a funny name.
13+
-- - another file with a funny name.
14+
'
15+
. ./test-lib.sh
16+
17+
test_expect_success \
18+
setup \
19+
'echo frotz >path0 &&
20+
echo frotz >./-foo &&
21+
echo frotz >./--'
22+
23+
test_expect_success \
24+
'git-ls-files without path restriction.' \
25+
'git-ls-files --others >output &&
26+
diff -u output - <<EOF
27+
--
28+
-foo
29+
output
30+
path0
31+
EOF
32+
'
33+
34+
test_expect_success \
35+
'git-ls-files with path restriction.' \
36+
'git-ls-files --others path0 >output &&
37+
diff -u output - <<EOF
38+
path0
39+
EOF
40+
'
41+
42+
test_expect_success \
43+
'git-ls-files with path restriction with --.' \
44+
'git-ls-files --others -- path0 >output &&
45+
diff -u output - <<EOF
46+
path0
47+
EOF
48+
'
49+
50+
test_expect_success \
51+
'git-ls-files with path restriction with -- --.' \
52+
'git-ls-files --others -- -- >output &&
53+
diff -u output - <<EOF
54+
--
55+
EOF
56+
'
57+
58+
test_expect_success \
59+
'git-ls-files with no path restriction.' \
60+
'git-ls-files --others -- >output &&
61+
diff -u output - <<EOF
62+
--
63+
-foo
64+
output
65+
path0
66+
EOF
67+
'
68+
69+
test_done

0 commit comments

Comments
 (0)