From eff714bddafd3d49cde0eac6ae670970da024fb4 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Mon, 19 Dec 2011 19:23:50 -0600 Subject: [PATCH 1/3] git-svn: multiple fetch/branches/tags keys are supported "git svn" can be configured to use multiple fetch, branches, and tags refspecs by passing multiple --branches or --tags options at init time or editing the configuration file later, which can be handy when working with messy Subversion repositories. Add a note to the configuration section documenting how this works. Signed-off-by: Jonathan Nieder Signed-off-by: Eric Wong --- Documentation/git-svn.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt index 58b6d540ca..6c0988e895 100644 --- a/Documentation/git-svn.txt +++ b/Documentation/git-svn.txt @@ -1032,6 +1032,18 @@ comma-separated list of names within braces. For example: tags = tags/{1.0,2.0}/src:refs/remotes/tags/* ------------------------------------------------------------------------ +Multiple fetch, branches, and tags keys are supported: + +------------------------------------------------------------------------ +[svn-remote "messy-repo"] + url = http://server.org/svn + fetch = trunk/project-a:refs/remotes/project-a/trunk + fetch = branches/demos/june-project-a-demo:refs/remotes/project-a/demos/june-demo + branches = branches/server/*:refs/remotes/project-a/branches/* + branches = branches/demos/2011/*:refs/remotes/project-a/2011-demos/* + tags = tags/server/*:refs/remotes/project-a/tags/* +------------------------------------------------------------------------ + Note that git-svn keeps track of the highest revision in which a branch or tag has appeared. If the subset of branches or tags is changed after fetching, then .git/svn/.metadata must be manually edited to remove (or From 7d82b4af1cefe55b825f524f250cd0002dbba4ab Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Mon, 19 Dec 2011 19:24:30 -0600 Subject: [PATCH 2/3] git-svn: clarify explanation of --destination argument The existing documentation for "-d" does not make it obvious whether its argument is supposed to be a full svn path, a partial svn path, the glob from the config file, or what. Clarify the text and add an example to get the reader started. Reported-by: Nathan Gray Signed-off-by: Jonathan Nieder Signed-off-by: Eric Wong --- Documentation/git-svn.txt | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt index 6c0988e895..68c706d807 100644 --- a/Documentation/git-svn.txt +++ b/Documentation/git-svn.txt @@ -271,13 +271,15 @@ first have already been pushed into SVN. Create a tag by using the tags_subdir instead of the branches_subdir specified during git svn init. --d;; ---destination;; +-d;; +--destination=;; + If more than one --branches (or --tags) option was given to the 'init' or 'clone' command, you must provide the location of the branch (or - tag) you wish to create in the SVN repository. The value of this - option must match one of the paths specified by a --branches (or - --tags) option. You can see these paths with the commands + tag) you wish to create in the SVN repository. specifies which + path to use to create the branch or tag and should match the pattern + on the left-hand side of one of the configured branches or tags + refspecs. You can see these refspecs with the commands + git config --get-all svn-remote..branches git config --get-all svn-remote..tags @@ -1044,6 +1046,13 @@ Multiple fetch, branches, and tags keys are supported: tags = tags/server/*:refs/remotes/project-a/tags/* ------------------------------------------------------------------------ +Creating a branch in such a configuration requires disambiguating which +location to use using the -d or --destination flag: + +------------------------------------------------------------------------ +$ git svn branch -d branches/server release-2-3-0 +------------------------------------------------------------------------ + Note that git-svn keeps track of the highest revision in which a branch or tag has appeared. If the subset of branches or tags is changed after fetching, then .git/svn/.metadata must be manually edited to remove (or From f4f4c7fc00e8acf91150c717cf005fc36c1dd120 Mon Sep 17 00:00:00 2001 From: Tobias Schulte Date: Wed, 15 May 2013 22:14:43 +0200 Subject: [PATCH 3/3] git-svn: introduce --parents parameter for commands branch and tag This parameter is equivalent to the parameter --parents on svn cp commands and is useful for non-standard repository layouts. Signed-off-by: Tobias Schulte Signed-off-by: Eric Wong --- Documentation/git-svn.txt | 5 +++ git-svn.perl | 19 +++++++++- t/t9167-git-svn-cmd-branch-subproject.sh | 48 ++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100755 t/t9167-git-svn-cmd-branch-subproject.sh diff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt index 68c706d807..aad452f169 100644 --- a/Documentation/git-svn.txt +++ b/Documentation/git-svn.txt @@ -300,6 +300,11 @@ where is the name of the SVN repository as specified by the -R option to git config --get-all svn-remote..commiturl + +--parents;; + Create parent folders. This parameter is equivalent to the parameter + --parents on svn cp commands and is useful for non-standard repository + layouts. + 'tag':: Create a tag in the SVN repository. This is a shorthand for 'branch -t'. diff --git a/git-svn.perl b/git-svn.perl index ccabe065f3..d070de012c 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -113,7 +113,7 @@ sub _req_svn { $_template, $_shared, $_version, $_fetch_all, $_no_rebase, $_fetch_parent, $_before, $_after, - $_merge, $_strategy, $_preserve_merges, $_dry_run, $_local, + $_merge, $_strategy, $_preserve_merges, $_dry_run, $_parents, $_local, $_prefix, $_no_checkout, $_url, $_verbose, $_commit_url, $_tag, $_merge_info, $_interactive); @@ -203,6 +203,7 @@ sub _req_svn { { 'message|m=s' => \$_message, 'destination|d=s' => \$_branch_dest, 'dry-run|n' => \$_dry_run, + 'parents' => \$_parents, 'tag|t' => \$_tag, 'username=s' => \$Git::SVN::Prompt::_username, 'commit-url=s' => \$_commit_url } ], @@ -211,6 +212,7 @@ sub _req_svn { { 'message|m=s' => \$_message, 'destination|d=s' => \$_branch_dest, 'dry-run|n' => \$_dry_run, + 'parents' => \$_parents, 'username=s' => \$Git::SVN::Prompt::_username, 'commit-url=s' => \$_commit_url } ], 'set-tree' => [ \&cmd_set_tree, @@ -1172,6 +1174,10 @@ sub cmd_branch { $ctx->ls($dst, 'HEAD', 0); } and die "branch ${branch_name} already exists\n"; + if ($_parents) { + mk_parent_dirs($ctx, $dst); + } + print "Copying ${src} at r${rev} to ${dst}...\n"; $ctx->copy($src, $rev, $dst) unless $_dry_run; @@ -1179,6 +1185,17 @@ sub cmd_branch { $gs->fetch_all; } +sub mk_parent_dirs { + my ($ctx, $parent) = @_; + $parent =~ s{/[^/]*$}{}; + + if (!eval{$ctx->ls($parent, 'HEAD', 0)}) { + mk_parent_dirs($ctx, $parent); + print "Creating parent folder ${parent} ...\n"; + $ctx->mkdir($parent) unless $_dry_run; + } +} + sub cmd_find_rev { my $revision_or_hash = shift or die "SVN or git revision required ", "as a command-line argument\n"; diff --git a/t/t9167-git-svn-cmd-branch-subproject.sh b/t/t9167-git-svn-cmd-branch-subproject.sh new file mode 100755 index 0000000000..53def876ed --- /dev/null +++ b/t/t9167-git-svn-cmd-branch-subproject.sh @@ -0,0 +1,48 @@ +#!/bin/sh +# +# Copyright (c) 2013 Tobias Schulte +# + +test_description='git svn branch for subproject clones' +. ./lib-git-svn.sh + +test_expect_success 'initialize svnrepo' ' + mkdir import && + ( + cd import && + mkdir -p trunk/project branches tags && + ( + cd trunk/project && + echo foo > foo + ) && + svn_cmd import -m "import for git-svn" . "$svnrepo" >/dev/null + ) && + rm -rf import && + svn_cmd co "$svnrepo"/trunk/project trunk/project && + ( + cd trunk/project && + echo bar >> foo && + svn_cmd ci -m "updated trunk" + ) && + rm -rf trunk +' + +test_expect_success 'import into git' ' + git svn init --trunk=trunk/project --branches=branches/*/project \ + --tags=tags/*/project "$svnrepo" && + git svn fetch && + git checkout remotes/trunk +' + +test_expect_success 'git svn branch tests' ' + test_must_fail git svn branch a && + git svn branch --parents a && + test_must_fail git svn branch -t tag1 && + git svn branch --parents -t tag1 && + test_must_fail git svn branch --tag tag2 && + git svn branch --parents --tag tag2 && + test_must_fail git svn tag tag3 && + git svn tag --parents tag3 +' + +test_done