Skip to content

Commit 45781ad

Browse files
Uwe Kleine-Königgitster
authored andcommitted
get_remote_url(): use the same data source as ls-remote to get remote urls
The formerly implemented algorithm behaved differently to remote.c:remote_get() at least for remotes that contain a slash. While the former just assumes a/b is a path the latter checks the config for remote."a/b" first which is more reasonable. This removes the last user of git-parse-remote.sh:get_data_source(), so this function is removed. Signed-off-by: Uwe Kleine-König <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7ed863a commit 45781ad

File tree

2 files changed

+12
-47
lines changed

2 files changed

+12
-47
lines changed

builtin/ls-remote.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
3333
int i;
3434
const char *dest = NULL;
3535
unsigned flags = 0;
36+
int get_url = 0;
3637
int quiet = 0;
3738
const char *uploadpack = NULL;
3839
const char **pattern = NULL;
@@ -69,6 +70,10 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
6970
quiet = 1;
7071
continue;
7172
}
73+
if (!strcmp("--get-url", arg)) {
74+
get_url = 1;
75+
continue;
76+
}
7277
usage(ls_remote_usage);
7378
}
7479
dest = arg;
@@ -94,6 +99,12 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
9499
}
95100
if (!remote->url_nr)
96101
die("remote %s has no configured URL", dest);
102+
103+
if (get_url) {
104+
printf("%s\n", *remote->url);
105+
return 0;
106+
}
107+
97108
transport = transport_get(remote, NULL);
98109
if (uploadpack != NULL)
99110
transport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack);

git-parse-remote.sh

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,8 @@
44
# this would fail in that case and would issue an error message.
55
GIT_DIR=$(git rev-parse -q --git-dir) || :;
66

7-
get_data_source () {
8-
case "$1" in
9-
*/*)
10-
echo ''
11-
;;
12-
.)
13-
echo self
14-
;;
15-
*)
16-
if test "$(git config --get "remote.$1.url")"
17-
then
18-
echo config
19-
elif test -f "$GIT_DIR/remotes/$1"
20-
then
21-
echo remotes
22-
elif test -f "$GIT_DIR/branches/$1"
23-
then
24-
echo branches
25-
else
26-
echo ''
27-
fi ;;
28-
esac
29-
}
30-
317
get_remote_url () {
32-
data_source=$(get_data_source "$1")
33-
case "$data_source" in
34-
'')
35-
echo "$1"
36-
;;
37-
self)
38-
echo "$1"
39-
;;
40-
config)
41-
git config --get "remote.$1.url"
42-
;;
43-
remotes)
44-
sed -ne '/^URL: */{
45-
s///p
46-
q
47-
}' "$GIT_DIR/remotes/$1"
48-
;;
49-
branches)
50-
sed -e 's/#.*//' "$GIT_DIR/branches/$1"
51-
;;
52-
*)
53-
die "internal error: get-remote-url $1" ;;
54-
esac
8+
git ls-remote --get-url "$1"
559
}
5610

5711
get_default_remote () {

0 commit comments

Comments
 (0)