git-svn: checkout files on new fetches
On newly-created repositories, 'refs/heads/master' does not point to anything. This can be confusing to new users; so we update 'master' to point to the last imported ref after fetching is done. Once 'master' is valid; we assume HEAD points to it; and if the repository is not bare, then checkout the files if the working tree is clean and unused. Signed-off-by: Eric Wong <normalperson@yhbt.net>
Eric Wong committed
Feb 16, 2007 at 01:45 UTC
1e889ef36c45b5554f7e317493ed3f4f901f8d9f
1 file changed
+26
-2
git-svn.perl
+26
-2
@@ -56,7 +56,7 @@ my ($_stdin, $_help, $_edit,
56
$_template, $_shared,
57
$_version, $_fetch_all,
58
$_merge, $_strategy, $_dry_run,
59
- $_prefix);
59
+ $_prefix, $_no_checkout);
60
$Git::SVN::_follow_parent = 1;
61
my %remote_opts = ( 'username=s' => \$Git::SVN::Prompt::_username,
62
'config-dir=s' => \$Git::SVN::Ra::config_dir,
@@ -67,6 +67,7 @@ my %fc_opts = ( 'follow-parent|follow!' => \$Git::SVN::_follow_parent,
67
'noMetadata' => \$Git::SVN::_no_metadata,
68
'useSvmProps' => \$Git::SVN::_use_svm_props,
69
'log-window-size=i' => \$Git::SVN::Ra::_log_window_size,
70
+ 'no-checkout' => \$_no_checkout,
71
'quiet|q' => \$_q,
72
'repack-flags|repack-args|repack-opts=s' =>
73
\$Git::SVN::_repack_flags,
@@ -167,6 +168,7 @@ eval {
168
$cmd{$cmd}->[0]->(@ARGV);
169
};
170
fatal $@ if $@;
171
+post_fetch_checkout();
172
exit 0;
173
174
####################### primary functions ######################
@@ -466,6 +468,27 @@ sub cmd_commit_diff {
468
469
########################### utility functions #########################
470
471
+sub post_fetch_checkout {
472
+ return if $_no_checkout;
473
+ my $gs = $Git::SVN::_head or return;
474
+ return if verify_ref('refs/heads/master^0');
475
+
476
+ my $valid_head = verify_ref('HEAD^0');
477
+ command_noisy(qw(update-ref refs/heads/master), $gs->refname);
478
+ return if ($valid_head || !verify_ref('HEAD^0'));
479
+
480
+ return if $ENV{GIT_DIR} !~ m#^(?:.*/)?\.git$#;
481
+ my $index = $ENV{GIT_INDEX_FILE} || "$ENV{GIT_DIR}/index";
482
+ return if -f $index;
483
+
484
+ chomp(my $bare = `git config --bool --get core.bare`);
485
+ return if $bare eq 'true';
486
+ return if command_oneline(qw/rev-parse --is-inside-git-dir/) eq 'true';
487
+ command_noisy(qw/read-tree -m -u -v HEAD HEAD/);
488
+ print STDERR "Checked out HEAD:\n ",
489
+ $gs->full_url, " r", $gs->last_rev, "\n";
490
+}
491
+
492
sub complete_svn_url {
493
my ($url, $path) = @_;
494
$path =~ s#/+$##;
@@ -668,7 +691,7 @@ package Git::SVN;
691
use strict;
692
use warnings;
693
use vars qw/$default_repo_id $default_ref_id $_no_metadata $_follow_parent
671
- $_repack $_repack_flags $_use_svm_props/;
694
+ $_repack $_repack_flags $_use_svm_props $_head/;
695
use Carp qw/croak/;
696
use File::Path qw/mkpath/;
697
use File::Copy qw/copy/;
@@ -1781,6 +1804,7 @@ sub rev_db_set {
1804
}
1805
close $fh or croak $!;
1806
if ($update_ref) {
1807
+ $_head = $self;
1808
command_noisy('update-ref', '-m', "r$rev",
1809
$self->refname, $commit);
1810
}