git-svn: checkout files on new fetches
authorEric Wong <normalperson@yhbt.net>
Fri, 16 Feb 2007 09:45:13 +0000 (01:45 -0800)
committerEric Wong <normalperson@yhbt.net>
Fri, 23 Feb 2007 08:57:13 +0000 (00:57 -0800)
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>
git-svn.perl
index 2152bf3de8a5205029926996e7174466ebd499ed..7ffbf641392f398743337d602696c328cec80b79 100755 (executable)
@@ -56,7 +56,7 @@ BEGIN
        $_template, $_shared,
        $_version, $_fetch_all,
        $_merge, $_strategy, $_dry_run,
        $_template, $_shared,
        $_version, $_fetch_all,
        $_merge, $_strategy, $_dry_run,
-       $_prefix);
+       $_prefix, $_no_checkout);
 $Git::SVN::_follow_parent = 1;
 my %remote_opts = ( 'username=s' => \$Git::SVN::Prompt::_username,
                     'config-dir=s' => \$Git::SVN::Ra::config_dir,
 $Git::SVN::_follow_parent = 1;
 my %remote_opts = ( 'username=s' => \$Git::SVN::Prompt::_username,
                     'config-dir=s' => \$Git::SVN::Ra::config_dir,
@@ -67,6 +67,7 @@ BEGIN
                'noMetadata' => \$Git::SVN::_no_metadata,
                'useSvmProps' => \$Git::SVN::_use_svm_props,
                'log-window-size=i' => \$Git::SVN::Ra::_log_window_size,
                'noMetadata' => \$Git::SVN::_no_metadata,
                'useSvmProps' => \$Git::SVN::_use_svm_props,
                'log-window-size=i' => \$Git::SVN::Ra::_log_window_size,
+               'no-checkout' => \$_no_checkout,
                'quiet|q' => \$_q,
                'repack-flags|repack-args|repack-opts=s' =>
                   \$Git::SVN::_repack_flags,
                'quiet|q' => \$_q,
                'repack-flags|repack-args|repack-opts=s' =>
                   \$Git::SVN::_repack_flags,
@@ -167,6 +168,7 @@ BEGIN
        $cmd{$cmd}->[0]->(@ARGV);
 };
 fatal $@ if $@;
        $cmd{$cmd}->[0]->(@ARGV);
 };
 fatal $@ if $@;
+post_fetch_checkout();
 exit 0;
 
 ####################### primary functions ######################
 exit 0;
 
 ####################### primary functions ######################
@@ -466,6 +468,27 @@ sub cmd_commit_diff {
 
 ########################### utility functions #########################
 
 
 ########################### utility functions #########################
 
+sub post_fetch_checkout {
+       return if $_no_checkout;
+       my $gs = $Git::SVN::_head or return;
+       return if verify_ref('refs/heads/master^0');
+
+       my $valid_head = verify_ref('HEAD^0');
+       command_noisy(qw(update-ref refs/heads/master), $gs->refname);
+       return if ($valid_head || !verify_ref('HEAD^0'));
+
+       return if $ENV{GIT_DIR} !~ m#^(?:.*/)?\.git$#;
+       my $index = $ENV{GIT_INDEX_FILE} || "$ENV{GIT_DIR}/index";
+       return if -f $index;
+
+       chomp(my $bare = `git config --bool --get core.bare`);
+       return if $bare eq 'true';
+       return if command_oneline(qw/rev-parse --is-inside-git-dir/) eq 'true';
+       command_noisy(qw/read-tree -m -u -v HEAD HEAD/);
+       print STDERR "Checked out HEAD:\n  ",
+                    $gs->full_url, " r", $gs->last_rev, "\n";
+}
+
 sub complete_svn_url {
        my ($url, $path) = @_;
        $path =~ s#/+$##;
 sub complete_svn_url {
        my ($url, $path) = @_;
        $path =~ s#/+$##;
@@ -668,7 +691,7 @@ package Git::SVN;
 use strict;
 use warnings;
 use vars qw/$default_repo_id $default_ref_id $_no_metadata $_follow_parent
 use strict;
 use warnings;
 use vars qw/$default_repo_id $default_ref_id $_no_metadata $_follow_parent
-            $_repack $_repack_flags $_use_svm_props/;
+            $_repack $_repack_flags $_use_svm_props $_head/;
 use Carp qw/croak/;
 use File::Path qw/mkpath/;
 use File::Copy qw/copy/;
 use Carp qw/croak/;
 use File::Path qw/mkpath/;
 use File::Copy qw/copy/;
@@ -1781,6 +1804,7 @@ sub rev_db_set {
        }
        close $fh or croak $!;
        if ($update_ref) {
        }
        close $fh or croak $!;
        if ($update_ref) {
+               $_head = $self;
                command_noisy('update-ref', '-m', "r$rev",
                              $self->refname, $commit);
        }
                command_noisy('update-ref', '-m', "r$rev",
                              $self->refname, $commit);
        }