git push currently doesn't consider pushInsteadOf when
using pushurl; this test tests that.

If you use pushurl with an alias that has a pushInsteadOf configuration
value, Git does not take advantage of it.  For example:

[url "git://github.com/"]
    insteadOf = github:
[url "git://github.com/myuser/"]
    insteadOf = mygithub:
[url "g...@github.com:myuser/"]
    pushInsteadOf = mygithub:
[remote "origin"]
    url     = github:organization/project
    pushurl = mygithub:project

With the above configuration, the following occurs:

$ git push origin master
fatal: remote error:
  You can't push to git://github.com/myuser/project.git
  Use g...@github.com:myuser/project.git

So you can see that pushurl is being followed (it's not attempting to
push to git://github.com/organization/project), but insteadOf values are
being used as opposed to pushInsteadOf values for expanding the pushurl
alias.

This commit fixes that.

Signed-off-by: Rob Hoelz <r...@hoelz.ro>
---
 Documentation/config.txt |  3 +-
 remote.c                 |  6 +++-
 t/t5516-fetch-push.sh    | 77 +++++++++++++++++++++++++++++++++++++++++++-----
 3 files changed, 75 insertions(+), 11 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index b3023b8..5610962 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2142,8 +2142,7 @@ url.<base>.pushInsteadOf::
        automatically use an appropriate URL to push, even for a
        never-before-seen repository on the site.  When more than one
        pushInsteadOf strings match a given URL, the longest match is
-       used.  If a remote has an explicit pushurl, Git will ignore this
-       setting for that remote.
+       used.
 
 user.email::
        Your email address to be recorded in any newly created commits.
diff --git a/remote.c b/remote.c
index e53a6eb..1ea240a 100644
--- a/remote.c
+++ b/remote.c
@@ -465,7 +465,11 @@ static void alias_all_urls(void)
                if (!remotes[i])
                        continue;
                for (j = 0; j < remotes[i]->pushurl_nr; j++) {
-                       remotes[i]->pushurl[j] = 
alias_url(remotes[i]->pushurl[j], &rewrites);
+                       char *copy = xstrdup(remotes[i]->pushurl[j]);
+                       remotes[i]->pushurl[j] = 
alias_url(remotes[i]->pushurl[j], &rewrites_push);
+                       if (!strcmp(copy, remotes[i]->pushurl[j]))
+                               remotes[i]->pushurl[j] = 
alias_url(remotes[i]->pushurl[j], &rewrites);
+                       free(copy);
                }
                add_pushurl_aliases = remotes[i]->pushurl_nr == 0;
                for (j = 0; j < remotes[i]->url_nr; j++) {
diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh
index c31e5c1..fbe0f29 100755
--- a/t/t5516-fetch-push.sh
+++ b/t/t5516-fetch-push.sh
@@ -228,19 +228,80 @@ test_expect_success 'push with pushInsteadOf' '
        )
 '
 
-test_expect_success 'push with pushInsteadOf and explicit pushurl 
(pushInsteadOf should not rewrite)' '
+test_expect_success 'push with pushInsteadOf and explicit pushurl (pushurl + 
pushInsteadOf does rewrite in this case)' '
        mk_empty &&
+       rm -rf ro rw &&
        TRASH="$(pwd)/" &&
-       git config "url.trash2/.pushInsteadOf" trash/ &&
-       git config remote.r.url trash/wrong &&
-       git config remote.r.pushurl "$TRASH/testrepo" &&
+       mkdir ro &&
+       mkdir rw &&
+       git init --bare rw/testrepo &&
+       test_config "url.file://$TRASH/ro/.insteadOf" ro: &&
+       test_config "url.file://$TRASH/rw/.pushInsteadOf" rw: &&
+       test_config remote.r.url ro:wrong &&
+       test_config remote.r.pushurl rw:testrepo &&
        git push r refs/heads/master:refs/remotes/origin/master &&
        (
-               cd testrepo &&
-               r=$(git show-ref -s --verify refs/remotes/origin/master) &&
-               test "z$r" = "z$the_commit" &&
+               cd rw/testrepo &&
+               echo "$the_commit commit        refs/remotes/origin/master" > 
expected &&
+               git for-each-ref refs/remotes/origin > actual &&
+               test_cmp expected actual
+       )
+'
 
-               test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
+test_expect_success 'push without pushInsteadOf and explicit pushurl (pushurl 
+ insteadOf is used for rewrite)' '
+       mk_empty &&
+       rm -rf ro rw &&
+       TRASH="$(pwd)/" &&
+       mkdir ro &&
+       mkdir rw &&
+       git init --bare rw/testrepo &&
+       test_config "url.file://$TRASH/ro/.insteadOf" ro: &&
+       test_config "url.file://$TRASH/rw/.insteadOf" rw: &&
+       test_config remote.r.url ro:wrong &&
+       test_config remote.r.pushurl rw:testrepo &&
+       git push r refs/heads/master:refs/remotes/origin/master &&
+       (
+               cd rw/testrepo &&
+               echo "$the_commit commit        refs/remotes/origin/master" > 
expected &&
+               git for-each-ref refs/remotes/origin > actual &&
+               test_cmp expected actual
+       )
+'
+
+test_expect_success 'push with pushInsteadOf but without explicit pushurl (url 
+ pushInsteadOf is used for rewrite)' '
+       mk_empty &&
+       rm -rf ro rw &&
+       TRASH="$(pwd)/" &&
+       mkdir ro &&
+       mkdir rw &&
+       git init --bare rw/testrepo &&
+       test_config "url.file://$TRASH/ro/.insteadOf" rw: &&
+       test_config "url.file://$TRASH/rw/.pushInsteadOf" rw: &&
+       test_config remote.r.url rw:testrepo &&
+       git push r refs/heads/master:refs/remotes/origin/master &&
+       (
+               cd rw/testrepo &&
+               echo "$the_commit commit        refs/remotes/origin/master" > 
expected &&
+               git for-each-ref refs/remotes/origin > actual &&
+               test_cmp expected actual
+       )
+'
+
+test_expect_success 'push without pushInsteadOf and without explicit pushurl 
(url + insteadOf is used for rewrite)' '
+       mk_empty &&
+       rm -rf ro rw &&
+       TRASH="$(pwd)/" &&
+       mkdir ro &&
+       mkdir rw &&
+       git init --bare rw/testrepo &&
+       test_config "url.file://$TRASH/rw/.insteadOf" rw: &&
+       test_config remote.r.url rw:testrepo &&
+       git push r refs/heads/master:refs/remotes/origin/master &&
+       (
+               cd rw/testrepo &&
+               echo "$the_commit commit        refs/remotes/origin/master" > 
expected &&
+               git for-each-ref refs/remotes/origin > actual &&
+               test_cmp expected actual
        )
 '
 
-- 
1.8.2
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to