git-svn: don't create master if another head exists

git-svn insists on creating the "master" head (unless it exists) on every "fetch". It is useful that it gets created initially, when no head exists - users expect this git convention of having a "master" branch on initial clone. However creating it when there already is another head does not provide any value - the ref is never updated, so it just gets stale after a while. Also, some users find it annoying that it gets recreated, especially when they would like the git branch names to follow SVN repository branch names. More background in http://thread.gmane.org/gmane.comp.version-control.git/115030 Make git-svn skip the "master" creation if HEAD already points at a valid head. This means "master" does get created on initial "clone" but does not get recreated once a user deletes it. Also, make post_fetch_checkout work with any head that is pointed to by HEAD, not just "master". Also, use fatal error handling consistent with the rest of the program for post_fetch_checkout. Signed-off-by: Marcin Owsiany <marcin@owsiany.pl> Signed-off-by: Eric Wong <normalperson@yhbt.net>

Marcin Owsiany committed Jun 24, 2012 at 22:40 UTC e3bd4ddaa9a60fa4e70efdb143b434b440d6cec4
1 file changed +4 -5
git-svn.perl
+4 -5
@@ -367,9 +367,9 @@ Git::SVN::init_vars();
367 eval {
368 Git::SVN::verify_remotes_sanity();
369 $cmd{$cmd}->[0]->(@ARGV);
370 + post_fetch_checkout();
371 };
372 fatal $@ if $@;
372 -post_fetch_checkout();
373 exit 0;
374
375 ####################### primary functions ######################
@@ -1598,8 +1598,8 @@ sub rebase_cmd {
1598
1599 sub post_fetch_checkout {
1600 return if $_no_checkout;
1601 + return if verify_ref('HEAD^0');
1602 my $gs = $Git::SVN::_head or return;
1602 - return if verify_ref('refs/heads/master^0');
1603
1604 # look for "trunk" ref if it exists
1605 my $remote = Git::SVN::read_all_remotes()->{$gs->{repo_id}};
@@ -1612,9 +1612,8 @@ sub post_fetch_checkout {
1612 }
1613 }
1614
1615 - my $valid_head = verify_ref('HEAD^0');
1616 - command_noisy(qw(update-ref refs/heads/master), $gs->refname);
1617 - return if ($valid_head || !verify_ref('HEAD^0'));
1615 + command_noisy(qw(update-ref HEAD), $gs->refname);
1616 + return unless verify_ref('HEAD^0');
1617
1618 return if $ENV{GIT_DIR} !~ m#^(?:.*/)?\.git$#;
1619 my $index = $ENV{GIT_INDEX_FILE} || "$ENV{GIT_DIR}/index";