@matheusbsbs / matheus-bagliano / commits / 0068f2116e
Fork 0

testsvn: respect `init.defaultBranch`

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>

Johannes Schindelin committed Jun 24, 2020 at 14:46 UTC 0068f2116e67fac511941442cbbf7b0109adf57a
2 files changed +13 -3
remote-testsvn.c
+7 -3
@@ -13,7 +13,7 @@
13 static const char *url;
14 static int dump_from_file;
15 static const char *private_ref;
16 -static const char *remote_ref = "refs/heads/master";
16 +static char *remote_ref;
17 static const char *marksfilename, *notes_ref;
18 struct rev_note { unsigned int rev_nr; };
19
@@ -286,7 +286,7 @@ int cmd_main(int argc, const char **argv)
286 private_ref_sb = STRBUF_INIT, marksfilename_sb = STRBUF_INIT,
287 notes_ref_sb = STRBUF_INIT;
288 static struct remote *remote;
289 - const char *url_in;
289 + const char *url_in, *remote_ref_short;
290
291 setup_git_directory();
292 if (argc < 2 || argc > 3) {
@@ -294,6 +294,9 @@ int cmd_main(int argc, const char **argv)
294 return 1;
295 }
296
297 + remote_ref_short = git_default_branch_name();
298 + remote_ref = xstrfmt("refs/heads/%s", remote_ref_short);
299 +
300 remote = remote_get(argv[1]);
301 url_in = (argc == 3) ? argv[2] : remote->url[0];
302
@@ -306,7 +309,8 @@ int cmd_main(int argc, const char **argv)
309 url = url_sb.buf;
310 }
311
309 - strbuf_addf(&private_ref_sb, "refs/svn/%s/master", remote->name);
312 + strbuf_addf(&private_ref_sb, "refs/svn/%s/%s",
313 + remote->name, remote_ref_short);
314 private_ref = private_ref_sb.buf;
315
316 strbuf_addf(&notes_ref_sb, "refs/notes/%s/revs", remote->name);
t/t9020-remote-svn.sh
+6
@@ -84,6 +84,12 @@ test_expect_success REMOTE_SVN 'incremental imports must lead to the same head'
84 test_cmp master.good .git/refs/remotes/svnsim/master
85 '
86
87 +test_expect_success REMOTE_SVN 'respects configured default initial branch' '
88 + git -c init.defaultBranch=trunk remote add -f trunk \
89 + "testsvn::file://$TEST_DIRECTORY/t9154/svn.dump" &&
90 + git rev-parse --verify refs/remotes/trunk/trunk
91 +'
92 +
93 test_debug 'git branch -a'
94
95 test_done