]> git.ipfire.org Git - thirdparty/git.git/commitdiff
testsvn: respect `init.defaultBranch`
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Wed, 24 Jun 2020 14:46:36 +0000 (14:46 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 24 Jun 2020 16:14:21 +0000 (09:14 -0700)
The default name of the initial branch in new repositories can now be
configured. The `testsvn` remote helper translates the remote Subversion
repository's branch name `trunk` to the hard-coded name `master`.
Clearly, the intention was to make the name align with Git's defaults.

So while we are not talking about a newly-created repository in the
`testsvn` context, it is a newly-created _Git_ repository, si it _still_
makes sense to use the overridden default name for the initial branch
whenever users configured it.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
remote-testsvn.c
t/t9020-remote-svn.sh

index 3af708c5b671920cff3d1888eb9c8ae724e0d648..cde39b94fb8439a9da3c57428a7f5e15056ae54a 100644 (file)
@@ -13,7 +13,7 @@
 static const char *url;
 static int dump_from_file;
 static const char *private_ref;
-static const char *remote_ref = "refs/heads/master";
+static char *remote_ref;
 static const char *marksfilename, *notes_ref;
 struct rev_note { unsigned int rev_nr; };
 
@@ -286,7 +286,7 @@ int cmd_main(int argc, const char **argv)
                        private_ref_sb = STRBUF_INIT, marksfilename_sb = STRBUF_INIT,
                        notes_ref_sb = STRBUF_INIT;
        static struct remote *remote;
-       const char *url_in;
+       const char *url_in, *remote_ref_short;
 
        setup_git_directory();
        if (argc < 2 || argc > 3) {
@@ -294,6 +294,9 @@ int cmd_main(int argc, const char **argv)
                return 1;
        }
 
+       remote_ref_short = git_default_branch_name();
+       remote_ref = xstrfmt("refs/heads/%s", remote_ref_short);
+
        remote = remote_get(argv[1]);
        url_in = (argc == 3) ? argv[2] : remote->url[0];
 
@@ -306,7 +309,8 @@ int cmd_main(int argc, const char **argv)
                url = url_sb.buf;
        }
 
-       strbuf_addf(&private_ref_sb, "refs/svn/%s/master", remote->name);
+       strbuf_addf(&private_ref_sb, "refs/svn/%s/%s",
+                   remote->name, remote_ref_short);
        private_ref = private_ref_sb.buf;
 
        strbuf_addf(&notes_ref_sb, "refs/notes/%s/revs", remote->name);
index 6fca08e5e35bd35cab5b97654b4a852ac28c9a34..0f97bafb00c293259054d57960c507b342fb194f 100755 (executable)
@@ -84,6 +84,12 @@ test_expect_success REMOTE_SVN 'incremental imports must lead to the same head'
        test_cmp master.good .git/refs/remotes/svnsim/master
 '
 
+test_expect_success REMOTE_SVN 'respects configured default initial branch' '
+       git -c init.defaultBranch=trunk remote add -f trunk \
+               "testsvn::file://$TEST_DIRECTORY/t9154/svn.dump" &&
+       git rev-parse --verify refs/remotes/trunk/trunk
+'
+
 test_debug 'git branch -a'
 
 test_done