]> Pileus Git - ~andy/git/commitdiff
git-svn: allow 'init' to act as multi-init
authorEric Wong <normalperson@yhbt.net>
Wed, 14 Feb 2007 20:27:41 +0000 (12:27 -0800)
committerEric Wong <normalperson@yhbt.net>
Fri, 23 Feb 2007 08:57:12 +0000 (00:57 -0800)
multi-init is now just an alias that requires -T/-t/-b;
all options that 'init' can now accept.

This will hopefully simplify usage and reduce typing.

Also, allow the --shared option in 'init' to take an optional
argument now that 'git-init --shared' supports an optional
argument.

Signed-off-by: Eric Wong <normalperson@yhbt.net>
git-svn.perl
t/t9107-git-svn-migrate.sh
t/t9109-git-svn-svk-mirrorpaths.sh

index 3eed62fc0bcacd74827b1e7c901d352f6b843986..b2931cd5aa99b6a0cf08fe5ba8485ad76b39847c 100755 (executable)
@@ -71,10 +71,10 @@ my %fc_opts = ( 'follow-parent|follow!' => \$Git::SVN::_follow_parent,
                %remote_opts );
 
 my ($_trunk, $_tags, $_branches);
-my %multi_opts = ( 'trunk|T=s' => \$_trunk,
-               'tags|t=s' => \$_tags,
-               'branches|b=s' => \$_branches );
-my %init_opts = ( 'template=s' => \$_template, 'shared' => \$_shared );
+my %init_opts = ( 'template=s' => \$_template, 'shared:s' => \$_shared,
+                  'trunk|T=s' => \$_trunk, 'tags|t=s' => \$_tags,
+                  'branches|b=s' => \$_branches, 'prefix=s' => \$_prefix,
+                  %remote_opts );
 my %cmt_opts = ( 'edit|e' => \$_edit,
                'rmdir' => \$SVN::Git::Editor::_rmdir,
                'find-copies-harder' => \$SVN::Git::Editor::_find_copies_harder,
@@ -90,6 +90,10 @@ my %cmd = (
        init => [ \&cmd_init, "Initialize a repo for tracking" .
                          " (requires URL argument)",
                          \%init_opts ],
+       'multi-init' => [ \&cmd_multi_init,
+                         "Deprecated alias for ".
+                         "'$0 init -T<trunk> -b<branches> -t<tags>'",
+                         \%init_opts ],
        dcommit => [ \&cmd_dcommit,
                     'Commit several diffs to merge with upstream',
                        { 'merge|m|M' => \$_merge,
@@ -101,12 +105,6 @@ my %cmd = (
                        { 'stdin|' => \$_stdin, %cmt_opts, %fc_opts, } ],
        'show-ignore' => [ \&cmd_show_ignore, "Show svn:ignore listings",
                        { 'revision|r=i' => \$_revision } ],
-       'multi-init' => [ \&cmd_multi_init,
-                       'Initialize multiple trees (like git-svnimport)',
-                       { %multi_opts, %init_opts, %remote_opts,
-                        'revision|r=i' => \$_revision,
-                        'prefix=s' => \$_prefix,
-                       } ],
        'multi-fetch' => [ \&cmd_multi_fetch,
                           "Deprecated alias for $0 fetch --all",
                           { 'revision|r=s' => \$_revision, %fc_opts } ],
@@ -182,6 +180,7 @@ Usage: $0 <command> [options] [arguments]\n
                next if $cmd && $cmd ne $_;
                print $fd '  ',pack('A17',$_),$cmd{$_}->[1],"\n";
                foreach (keys %{$cmd{$_}->[2]}) {
+                       next if /^multi-/; # don't show deprecated commands
                        # prints out arguments as they should be passed:
                        my $x = s#[:=]s$## ? '<arg>' : s#[:=]i$## ? '<num>' : '';
                        print $fd ' ' x 21, join(', ', map { length $_ > 1 ?
@@ -207,21 +206,31 @@ sub do_git_init_db {
        unless (-d $ENV{GIT_DIR}) {
                my @init_db = ('init');
                push @init_db, "--template=$_template" if defined $_template;
-               push @init_db, "--shared" if defined $_shared;
+               if (defined $_shared) {
+                       if ($_shared =~ /[a-z]/) {
+                               push @init_db, "--shared=$_shared";
+                       } else {
+                               push @init_db, "--shared";
+                       }
+               }
                command_noisy(@init_db);
        }
 }
 
+sub init_subdir {
+       my $repo_path = shift or return;
+       mkpath([$repo_path]) unless -d $repo_path;
+       chdir $repo_path or die "Couldn't chdir to $repo_path: $!\n";
+       $ENV{GIT_DIR} = $repo_path . "/.git";
+}
+
 sub cmd_init {
-       my $url = shift or die "SVN repository location required " .
-                               "as a command-line argument\n";
-       if (my $repo_path = shift) {
-               unless (-d $repo_path) {
-                       mkpath([$repo_path]);
-               }
-               chdir $repo_path or croak $!;
-               $ENV{GIT_DIR} = $repo_path . "/.git";
+       if (defined $_trunk || defined $_branches || defined $_tags) {
+               return cmd_multi_init(@_);
        }
+       my $url = shift or die "SVN repository location required ",
+                              "as a command-line argument\n";
+       init_subdir(@_);
        do_git_init_db();
 
        Git::SVN->init($url);
@@ -367,7 +376,10 @@ sub cmd_multi_init {
        }
        do_git_init_db();
        $_prefix = '' unless defined $_prefix;
-       $url =~ s#/+$## if defined $url;
+       if (defined $url) {
+               $url =~ s#/+$##;
+               init_subdir(@_);
+       }
        if (defined $_trunk) {
                my $trunk_ref = $_prefix . 'trunk';
                # try both old-style and new-style lookups:
index d26c355f059009ee0a57be07af1636ab47c11b12..a20038b6705a380e93983a23d4a6671b2d5944bf 100755 (executable)
@@ -40,7 +40,7 @@ test_expect_success 'initialize old-style (v0) git-svn layout' "
        "
 
 test_expect_success 'initialize a multi-repository repo' "
-       git-svn multi-init $svnrepo -T trunk -t tags -b branches &&
+       git-svn init $svnrepo -T trunk -t tags -b branches &&
        git-config --get-all svn-remote.svn.fetch > fetch.out &&
        grep '^trunk:refs/remotes/trunk$' fetch.out &&
        test -n \"\`git-config --get svn-remote.svn.branches \
@@ -72,7 +72,7 @@ test_expect_success 'multi-fetch works on partial urls + paths' "
                                 refs/remotes/\$j\`\" ||exit 1; done; done
        "
 
-test_expect_success 'migrate --minimize on old multi-inited layout' "
+test_expect_success 'migrate --minimize on old inited layout' "
        git config --unset-all svn-remote.svn.fetch &&
        git config --unset-all svn-remote.svn.url &&
        rm -rf $GIT_DIR/svn &&
index 7e4215185157572e79ee6bbef5270f1f08717b60..1e1b97b5fc971abdfb897e46d9def401a796bc94 100755 (executable)
@@ -73,8 +73,8 @@ test_expect_success 'initialize repo' "
        cd ..
        "
 
-test_expect_success 'multi-init an SVK mirror path' "
-       git-svn multi-init -T trunk -t tags -b branches $svnrepo/mirror/foobar
+test_expect_success 'init an SVK mirror path' "
+       git-svn init -T trunk -t tags -b branches $svnrepo/mirror/foobar
        "
 
 test_expect_success 'multi-fetch an SVK mirror path' "git-svn multi-fetch"