Skip to content

Commit 857f8c3

Browse files
Michael J Grubergitster
authored andcommitted
builtin-remote: Show push urls as well
Teach builtin remote to show push urls also when asked to "show" a specific remote. This improves upon the standard display mode: multiple specified "url"s mean that the first one is for fetching, all are used for pushing. We make this clearer now by displaying the first one prefixed with "Fetch URL", and all "url"s (or, if present, all "pushurl"s) prefixed with "Push URL". Example with "one" having one url, "two" two urls, "three" one url and one pushurl (URL part only): * remote one Fetch URL: hostone.com:/somepath/repoone.git Push URL: hostone.com:/somepath/repoone.git * remote two Fetch URL: hosttwo.com:/somepath/repotwo.git Push URL: hosttwo.com:/somepath/repotwo.git Push URL: hosttwobackup.com:/somewheresafe/repotwo.git * remote three Fetch URL: http://hostthree.com/otherpath/repothree.git Push URL: hostthree.com:/pathforpushes/repothree.git Also, adjust t5505 accordingly and make it test for the new output. Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 056724c commit 857f8c3

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

builtin-remote.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,15 +1002,25 @@ static int show(int argc, const char **argv)
10021002
info.list = &info_list;
10031003
for (; argc; argc--, argv++) {
10041004
int i;
1005+
const char **url;
1006+
int url_nr;
10051007

10061008
get_remote_ref_states(*argv, &states, query_flag);
10071009

10081010
printf("* remote %s\n", *argv);
1009-
if (states.remote->url_nr) {
1010-
for (i=0; i < states.remote->url_nr; i++)
1011-
printf(" URL: %s\n", states.remote->url[i]);
1012-
} else
1013-
printf(" URL: %s\n", "(no URL)");
1011+
printf(" Fetch URL: %s\n", states.remote->url_nr > 0 ?
1012+
states.remote->url[0] : "(no URL)");
1013+
if (states.remote->pushurl_nr) {
1014+
url = states.remote->pushurl;
1015+
url_nr = states.remote->pushurl_nr;
1016+
} else {
1017+
url = states.remote->url;
1018+
url_nr = states.remote->url_nr;
1019+
}
1020+
for (i=0; i < url_nr; i++)
1021+
printf(" Push URL: %s\n", url[i]);
1022+
if (!i)
1023+
printf(" Push URL: %s\n", "(no URL)");
10141024
if (no_query)
10151025
printf(" HEAD branch: (not queried)\n");
10161026
else if (!states.heads.nr)

t/t5505-remote.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ EOF
135135

136136
cat > test/expect << EOF
137137
* remote origin
138-
URL: $(pwd)/one
138+
Fetch URL: $(pwd)/one
139+
Push URL: $(pwd)/one
139140
HEAD branch: master
140141
Remote branches:
141142
master new (next fetch will store in remotes/origin)
@@ -151,7 +152,8 @@ cat > test/expect << EOF
151152
master pushes to master (local out of date)
152153
master pushes to upstream (create)
153154
* remote two
154-
URL: ../two
155+
Fetch URL: ../two
156+
Push URL: ../three
155157
HEAD branch (remote HEAD is ambiguous, may be one of the following):
156158
another
157159
master
@@ -173,6 +175,7 @@ test_expect_success 'show' '
173175
git branch --track rebase origin/master &&
174176
git branch -d -r origin/master &&
175177
git config --add remote.two.url ../two &&
178+
git config --add remote.two.pushurl ../three &&
176179
git config branch.rebase.rebase true &&
177180
git config branch.octopus.merge "topic-a topic-b topic-c" &&
178181
(cd ../one &&
@@ -191,7 +194,8 @@ test_expect_success 'show' '
191194

192195
cat > test/expect << EOF
193196
* remote origin
194-
URL: $(pwd)/one
197+
Fetch URL: $(pwd)/one
198+
Push URL: $(pwd)/one
195199
HEAD branch: (not queried)
196200
Remote branches: (status not queried)
197201
master

0 commit comments

Comments
 (0)