3
3
#include "transport.h"
4
4
#include "remote.h"
5
5
6
- static const char ls_remote_usage [] =
7
- "git ls-remote [--heads] [--tags] [--upload-pack=<exec>]\n"
8
- " [-q | --quiet] [--exit-code] [--get-url] [<repository> [<refs>...]]" ;
6
+ static const char * const ls_remote_usage [] = {
7
+ N_ ("git ls-remote [--heads] [--tags] [--refs] [--upload-pack=<exec>]\n"
8
+ " [-q | --quiet] [--exit-code] [--get-url]\n"
9
+ " [--symref] [<repository> [<refs>...]]" ),
10
+ NULL
11
+ };
9
12
10
13
/*
11
14
* Is there one among the list of patterns that match the tail part
@@ -30,72 +33,49 @@ static int tail_match(const char **pattern, const char *path)
30
33
31
34
int cmd_ls_remote (int argc , const char * * argv , const char * prefix )
32
35
{
33
- int i ;
34
36
const char * dest = NULL ;
35
37
unsigned flags = 0 ;
36
38
int get_url = 0 ;
37
39
int quiet = 0 ;
38
40
int status = 0 ;
41
+ int show_symref_target = 0 ;
39
42
const char * uploadpack = NULL ;
40
43
const char * * pattern = NULL ;
41
44
42
45
struct remote * remote ;
43
46
struct transport * transport ;
44
47
const struct ref * ref ;
45
48
46
- if (argc == 2 && !strcmp ("-h" , argv [1 ]))
47
- usage (ls_remote_usage );
49
+ struct option options [] = {
50
+ OPT__QUIET (& quiet , N_ ("do not print remote URL" )),
51
+ OPT_STRING (0 , "upload-pack" , & uploadpack , N_ ("exec" ),
52
+ N_ ("path of git-upload-pack on the remote host" )),
53
+ { OPTION_STRING , 0 , "exec" , & uploadpack , N_ ("exec" ),
54
+ N_ ("path of git-upload-pack on the remote host" ),
55
+ PARSE_OPT_HIDDEN },
56
+ OPT_BIT ('t' , "tags" , & flags , N_ ("limit to tags" ), REF_TAGS ),
57
+ OPT_BIT ('h' , "heads" , & flags , N_ ("limit to heads" ), REF_HEADS ),
58
+ OPT_BIT (0 , "refs" , & flags , N_ ("do not show peeled tags" ), REF_NORMAL ),
59
+ OPT_BOOL (0 , "get-url" , & get_url ,
60
+ N_ ("take url.<base>.insteadOf into account" )),
61
+ OPT_SET_INT (0 , "exit-code" , & status ,
62
+ N_ ("exit with exit code 2 if no matching refs are found" ), 2 ),
63
+ OPT_BOOL (0 , "symref" , & show_symref_target ,
64
+ N_ ("show underlying ref in addition to the object pointed by it" )),
65
+ OPT_END ()
66
+ };
48
67
49
- for (i = 1 ; i < argc ; i ++ ) {
50
- const char * arg = argv [i ];
68
+ argc = parse_options (argc , argv , prefix , options , ls_remote_usage ,
69
+ PARSE_OPT_STOP_AT_NON_OPTION );
70
+ dest = argv [0 ];
51
71
52
- if (* arg == '-' ) {
53
- if (starts_with (arg , "--upload-pack=" )) {
54
- uploadpack = arg + 14 ;
55
- continue ;
56
- }
57
- if (starts_with (arg , "--exec=" )) {
58
- uploadpack = arg + 7 ;
59
- continue ;
60
- }
61
- if (!strcmp ("--tags" , arg ) || !strcmp ("-t" , arg )) {
62
- flags |= REF_TAGS ;
63
- continue ;
64
- }
65
- if (!strcmp ("--heads" , arg ) || !strcmp ("-h" , arg )) {
66
- flags |= REF_HEADS ;
67
- continue ;
68
- }
69
- if (!strcmp ("--refs" , arg )) {
70
- flags |= REF_NORMAL ;
71
- continue ;
72
- }
73
- if (!strcmp ("--quiet" , arg ) || !strcmp ("-q" , arg )) {
74
- quiet = 1 ;
75
- continue ;
76
- }
77
- if (!strcmp ("--get-url" , arg )) {
78
- get_url = 1 ;
79
- continue ;
80
- }
81
- if (!strcmp ("--exit-code" , arg )) {
82
- /* return this code if no refs are reported */
83
- status = 2 ;
84
- continue ;
85
- }
86
- usage (ls_remote_usage );
87
- }
88
- dest = arg ;
89
- i ++ ;
90
- break ;
72
+ if (argc > 1 ) {
73
+ int i ;
74
+ pattern = xcalloc (argc , sizeof (const char * ));
75
+ for (i = 1 ; i < argc ; i ++ )
76
+ pattern [i - 1 ] = xstrfmt ("*/%s" , argv [i ]);
91
77
}
92
78
93
- if (argv [i ]) {
94
- int j ;
95
- pattern = xcalloc (argc - i + 1 , sizeof (const char * ));
96
- for (j = i ; j < argc ; j ++ )
97
- pattern [j - i ] = xstrfmt ("*/%s" , argv [j ]);
98
- }
99
79
remote = remote_get (dest );
100
80
if (!remote ) {
101
81
if (dest )
@@ -125,7 +105,9 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
125
105
continue ;
126
106
if (!tail_match (pattern , ref -> name ))
127
107
continue ;
128
- printf ("%s %s\n" , oid_to_hex (& ref -> old_oid ), ref -> name );
108
+ if (show_symref_target && ref -> symref )
109
+ printf ("ref: %s\t%s\n" , ref -> symref , ref -> name );
110
+ printf ("%s\t%s\n" , oid_to_hex (& ref -> old_oid ), ref -> name );
129
111
status = 0 ; /* we found something */
130
112
}
131
113
return status ;
0 commit comments