Skip to content

Commit 1aa0e63

Browse files
committed
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>
1 parent 00a1b28 commit 1aa0e63

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

remote-testsvn.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
static const char *url;
1414
static int dump_from_file;
1515
static const char *private_ref;
16-
static const char *remote_ref = "refs/heads/master";
16+
static char *remote_ref;
1717
static const char *marksfilename, *notes_ref;
1818
struct rev_note { unsigned int rev_nr; };
1919

@@ -286,14 +286,17 @@ int cmd_main(int argc, const char **argv)
286286
private_ref_sb = STRBUF_INIT, marksfilename_sb = STRBUF_INIT,
287287
notes_ref_sb = STRBUF_INIT;
288288
static struct remote *remote;
289-
const char *url_in;
289+
const char *url_in, *remote_ref_short;
290290

291291
setup_git_directory();
292292
if (argc < 2 || argc > 3) {
293293
usage("git-remote-svn <remote-name> [<url>]");
294294
return 1;
295295
}
296296

297+
remote_ref_short = git_default_branch_name();
298+
remote_ref = xstrfmt("refs/heads/%s", remote_ref_short);
299+
297300
remote = remote_get(argv[1]);
298301
url_in = (argc == 3) ? argv[2] : remote->url[0];
299302

@@ -306,7 +309,8 @@ int cmd_main(int argc, const char **argv)
306309
url = url_sb.buf;
307310
}
308311

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);
310314
private_ref = private_ref_sb.buf;
311315

312316
strbuf_addf(&notes_ref_sb, "refs/notes/%s/revs", remote->name);

t/t9020-remote-svn.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ test_expect_success REMOTE_SVN 'incremental imports must lead to the same head'
8484
test_cmp master.good .git/refs/remotes/svnsim/master
8585
'
8686

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+
8793
test_debug 'git branch -a'
8894

8995
test_done

0 commit comments

Comments
 (0)