[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 <freku045@student.liu.se> Signed-off-by: Junio C Hamano <junkio@cox.net>
Fredrik Kuivinen committed
Oct 2, 2005 at 17:33 UTC
500b97e4bb184c954a52550843e6314ecf97a208
3 files changed
+82
-2
Documentation/git-ls-files.txt
+8
-1
@@ -13,7 +13,7 @@ SYNOPSIS
13
(-[c|d|o|i|s|u|k|m])\*
14
[-x <pattern>|--exclude=<pattern>]
15
[-X <file>|--exclude-from=<file>]
16
- [--exclude-per-directory=<file>]
16
+ [--exclude-per-directory=<file>] [--] [<file>]\*
17
18
DESCRIPTION
19
-----------
@@ -77,6 +77,13 @@ OPTIONS
77
K to be killed
78
? other
79
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
+
87
Output
88
------
89
show files just outputs the filename unless '--stage' is specified in
ls-files.c
+5
-1
@@ -530,7 +530,7 @@ static void verify_pathspec(void)
530
static const char ls_files_usage[] =
531
"git-ls-files [-z] [-t] (--[cached|deleted|others|stage|unmerged|killed|modified])* "
532
"[ --ignored ] [--exclude=<pattern>] [--exclude-from=<file>] "
533
- "[ --exclude-per-directory=<filename> ]";
533
+ "[ --exclude-per-directory=<filename> ] [--] [<file>]*";
534
535
int main(int argc, const char **argv)
536
{
@@ -544,6 +544,10 @@ int main(int argc, const char **argv)
544
for (i = 1; i < argc; i++) {
545
const char *arg = argv[i];
546
547
+ if (!strcmp(arg, "--")) {
548
+ i++;
549
+ break;
550
+ }
551
if (!strcmp(arg, "-z")) {
552
line_terminator = 0;
553
continue;
t/t3002-ls-files-dashpath.sh
new
+69
@@ -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