{"thread":{"id":"15381","subject":"[PATCH] Add git-svn branch to allow branch creation in SVN repositories","startedAt":"2008-09-05T11:34:07Z","lastAt":"2008-09-07T02:33:16Z","messageCount":2,"participants":["Florian Ragwitz","Eric Wong"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"89839","messageId":"1220614447-3751-1-git-send-email-rafl@debian.org","threadId":"15381","inReplyTo":null,"subject":"[PATCH] Add git-svn branch to allow branch creation in SVN repositories","fromName":"Florian Ragwitz","fromEmail":"rafl@debian.org","sentAt":"2008-09-05T11:34:07Z","receivedAt":"2008-09-05T11:34:07Z","isPatch":true,"sender":{"key":"rafl@debian.org","avatar":"https://gravatar.com/avatar/87c13cf03f1d0ddb4777379622dc2e0a5224bc0321ce9622cfb4daad92e268ee?d=mp&s=160"},"body":"Signed-off-by: Florian Ragwitz <rafl@debian.org>\n---\n Documentation/git-svn.txt |   14 ++++++++++++++\n git-svn.perl              |   30 +++++++++++++++++++++++++++++-\n 2 files changed, 43 insertions(+), 1 deletions(-)\n\ndiff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt\nindex 1e644ca..23cf7c3 100644\n--- a/Documentation/git-svn.txt\n+++ b/Documentation/git-svn.txt\n@@ -149,6 +149,18 @@ and have no uncommitted changes.\n \tis very strongly discouraged.\n --\n \n+'branch'::\n+    Create a branch in the SVN repository.\n+\n+-m;;\n+--message;;\n+    Allows to specify the commit message.\n+\n+-t;;\n+--tag;;\n+    Create a tag by using the tags_subdir instead of the branches_subdir\n+    specified during git svn init.\n+\n 'log'::\n \tThis should make it easy to look up svn log messages when svn\n \tusers refer to -r/--revision numbers.\n@@ -498,6 +510,8 @@ Tracking and contributing to an entire Subversion-managed project\n \tgit svn clone http://svn.foo.org/project -T trunk -b branches -t tags\n # View all branches and tags you have cloned:\n \tgit branch -r\n+# Create a new branch in SVN\n+    git svn branch waldo\n # Reset your master to trunk (or any other branch, replacing 'trunk'\n # with the appropriate name):\n \tgit reset --hard remotes/trunk\ndiff --git a/git-svn.perl b/git-svn.perl\nindex 7a1d26d..55a2052 100755\n--- a/git-svn.perl\n+++ b/git-svn.perl\n@@ -66,7 +66,7 @@ my ($_stdin, $_help, $_edit,\n \t$_version, $_fetch_all, $_no_rebase,\n \t$_merge, $_strategy, $_dry_run, $_local,\n \t$_prefix, $_no_checkout, $_url, $_verbose,\n-\t$_git_format, $_commit_url);\n+\t$_git_format, $_commit_url, $_tag);\n $Git::SVN::_follow_parent = 1;\n my %remote_opts = ( 'username=s' => \\$Git::SVN::Prompt::_username,\n                     'config-dir=s' => \\$Git::SVN::Ra::config_dir,\n@@ -131,6 +131,10 @@ my %cmd = (\n \t\t\t  'revision|r=i' => \\$_revision,\n \t\t\t  'no-rebase' => \\$_no_rebase,\n \t\t\t%cmt_opts, %fc_opts } ],\n+\tbranch => [ \\&cmd_branch,\n+\t            'Create a branch in the SVN repository',\n+\t            { 'tag|t'       => \\$_tag,\n+\t              'message|m=s' => \\$_message } ],\n \t'set-tree' => [ \\&cmd_set_tree,\n \t                \"Set an SVN repository to a git tree-ish\",\n \t\t\t{ 'stdin|' => \\$_stdin, %cmt_opts, %fc_opts, } ],\n@@ -537,6 +541,30 @@ sub cmd_dcommit {\n \tunlink $gs->{index};\n }\n \n+sub cmd_branch {\n+\tmy $branch_name = shift or die \"branch name required\\n\";\n+\tmy $head        = shift || 'HEAD';\n+\n+\tmy ($src, $rev, undef, $gs) = working_head_info($head);\n+\n+\tmy $remote      = Git::SVN::read_all_remotes()->{svn};\n+\tmy ($lft, $rgt) = @{ $remote->{ $_tag ? 'tags' : 'branches' }->{path} }{qw/left right/};\n+\tmy $dst         = join '/', $remote->{url}, $lft, $branch_name, ($rgt || ());\n+\n+\tmy $ctx = SVN::Client->new(\n+\t\tauth    => Git::SVN::Ra::_auth_providers(),\n+\t\tlog_msg => sub { ${ $_[0] } = $_message || 'Create branch ' . $branch_name },\n+\t);\n+\n+\teval {\n+\t\t$ctx->ls($dst, 'HEAD', 0);\n+\t} and die \"branch ${branch_name} already exists\\n\";\n+\n+\t$ctx->copy($src, $rev, $dst);\n+\n+\t$gs->fetch_all;\n+}\n+\n sub cmd_find_rev {\n \tmy $revision_or_hash = shift or die \"SVN or git revision required \",\n \t                                    \"as a command-line argument\\n\";\n-- \n1.5.6.5\n"},{"id":"89934","messageId":"20080907023316.GA12392@untitled","threadId":"15381","inReplyTo":"1220614447-3751-1-git-send-email-rafl@debian.org","subject":"Re: [PATCH] Add git-svn branch to allow branch creation in SVN repositories","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2008-09-07T02:33:16Z","receivedAt":"2008-09-07T02:33:16Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"Hi Florian,\n\nCool.  Some people have been asking for this feature.\n\nI never implemented it myself because I've been unsure if it's\nphilosophically proper.  Ut's functionally redundant as svn(1) does the\nsame thing w/o needing a working copy.  But I'll accept your patch with\nsome minor modifications (comments inline).\n\nFlorian Ragwitz <rafl@debian.org> wrote:\n> --- a/Documentation/git-svn.txt\n> +++ b/Documentation/git-svn.txt\n> @@ -149,6 +149,18 @@ and have no uncommitted changes.\n>  \tis very strongly discouraged.\n>  --\n>  \n> +'branch'::\n> +    Create a branch in the SVN repository.\n\nPerhaps a \"tag\" command that is short for \"branch -t\" would\nbe helpful, too.\n\n> +-t;;\n> +--tag;;\n> +    Create a tag by using the tags_subdir instead of the branches_subdir\n> +    specified during git svn init.\n> +\n> diff --git a/git-svn.perl b/git-svn.perl\n> index 7a1d26d..55a2052 100755\n> --- a/git-svn.perl\n> +++ b/git-svn.perl\n> @@ -537,6 +541,30 @@ sub cmd_dcommit {\n>  \tunlink $gs->{index};\n>  }\n\nCoding style things:\n\n1. Don't pad declarations with extra whitespace.\n2. No lines over 80 characters (assuming tabs are 8 chars wide)\n\n> +sub cmd_branch {\n> +\tmy $branch_name = shift or die \"branch name required\\n\";\n> +\tmy $head        = shift || 'HEAD';\n> +\n> +\tmy ($src, $rev, undef, $gs) = working_head_info($head);\n> +\n> +\tmy $remote      = Git::SVN::read_all_remotes()->{svn};\n\n> +\tmy ($lft, $rgt) = @{ $remote->{ $_tag ? 'tags' : 'branches' }->{path} }{qw/left right/};\n> +\tmy $dst         = join '/', $remote->{url}, $lft, $branch_name, ($rgt || ());\n\nThis doesn't appear to fail gracefully for SVN repositories\nthat don't follow the standard trunk, branches, tags layout.\n\nCan you please ensure that it does and print an error message?\n\n> +\n> +\tmy $ctx = SVN::Client->new(\n> +\t\tauth    => Git::SVN::Ra::_auth_providers(),\n> +\t\tlog_msg => sub { ${ $_[0] } = $_message || 'Create branch ' . $branch_name },\n> +\t);\n> +\n> +\teval {\n> +\t\t$ctx->ls($dst, 'HEAD', 0);\n> +\t} and die \"branch ${branch_name} already exists\\n\";\n\nCan you print the URLs being copied and add a --dry-run/-n\noption (like dcommit).\n\n> +\t$ctx->copy($src, $rev, $dst);\n> +\n> +\t$gs->fetch_all;\n> +}\n> +\n>  sub cmd_find_rev {\n>  \tmy $revision_or_hash = shift or die \"SVN or git revision required \",\n>  \t                                    \"as a command-line argument\\n\";\n\nCan you also add a simple test case so we don't break it in the future?\nThanks.\n\n-- \nEric Wong\n"}]}