Skip to content

Commit 1668b7d

Browse files
committed
Merge git://git.bogomips.org/git-svn
* git://git.bogomips.org/git-svn: git-svn: Warn about changing default for --prefix in Git v2.0 Documentation/git-svn: Promote the use of --prefix in docs + examples git-svn.txt: elaborate on rev_map files git-svn.txt: replace .git with $GIT_DIR git-svn.txt: reword description of gc command git-svn.txt: fix AsciiDoc formatting error git-svn: fix signed commit parsing
2 parents 9768648 + f849bb6 commit 1668b7d

File tree

3 files changed

+146
-25
lines changed

3 files changed

+146
-25
lines changed

Documentation/git-svn.txt

Lines changed: 67 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,21 @@ COMMANDS
7979
trailing slash, so be sure you include one in the
8080
argument if that is what you want. If --branches/-b is
8181
specified, the prefix must include a trailing slash.
82-
Setting a prefix is useful if you wish to track multiple
83-
projects that share a common repository.
82+
Setting a prefix (with a trailing slash) is strongly
83+
encouraged in any case, as your SVN-tracking refs will
84+
then be located at "refs/remotes/$prefix/*", which is
85+
compatible with Git's own remote-tracking ref layout
86+
(refs/remotes/$remote/*). Setting a prefix is also useful
87+
if you wish to track multiple projects that share a common
88+
repository.
89+
+
90+
NOTE: In Git v2.0, the default prefix will CHANGE from "" (no prefix)
91+
to "origin/". This is done to put SVN-tracking refs at
92+
"refs/remotes/origin/*" instead of "refs/remotes/*", and make them
93+
more compatible with how Git's own remote-tracking refs are organized
94+
(i.e. refs/remotes/$remote/*). You can enjoy the same benefits today,
95+
by using the --prefix option.
96+
8497
--ignore-paths=<regex>;;
8598
When passed to 'init' or 'clone' this regular expression will
8699
be preserved as a config key. See 'fetch' for a description
@@ -104,8 +117,11 @@ COMMANDS
104117
'fetch'::
105118
Fetch unfetched revisions from the Subversion remote we are
106119
tracking. The name of the [svn-remote "..."] section in the
107-
.git/config file may be specified as an optional command-line
108-
argument.
120+
$GIT_DIR/config file may be specified as an optional
121+
command-line argument.
122+
+
123+
This automatically updates the rev_map if needed (see
124+
'$GIT_DIR/svn/\*\*/.rev_map.*' in the FILES section below for details).
109125

110126
--localtime;;
111127
Store Git commit times in the local timezone instead of UTC. This
@@ -201,6 +217,9 @@ accept. However, '--fetch-all' only fetches from the current
201217
+
202218
Like 'git rebase'; this requires that the working tree be clean
203219
and have no uncommitted changes.
220+
+
221+
This automatically updates the rev_map if needed (see
222+
'$GIT_DIR/svn/\*\*/.rev_map.*' in the FILES section below for details).
204223

205224
-l;;
206225
--local;;
@@ -435,8 +454,8 @@ Any other arguments are passed directly to 'git log'
435454
specific revision.
436455

437456
'gc'::
438-
Compress $GIT_DIR/svn/<refname>/unhandled.log files in .git/svn
439-
and remove $GIT_DIR/svn/<refname>index files in .git/svn.
457+
Compress $GIT_DIR/svn/<refname>/unhandled.log files and remove
458+
$GIT_DIR/svn/<refname>/index files.
440459

441460
'reset'::
442461
Undoes the effects of 'fetch' back to the specified revision.
@@ -449,9 +468,10 @@ Any other arguments are passed directly to 'git log'
449468
file cannot be ignored forever (with --ignore-paths) the only
450469
way to repair the repo is to use 'reset'.
451470
+
452-
Only the rev_map and refs/remotes/git-svn are changed. Follow 'reset'
453-
with a 'fetch' and then 'git reset' or 'git rebase' to move local
454-
branches onto the new tree.
471+
Only the rev_map and refs/remotes/git-svn are changed (see
472+
'$GIT_DIR/svn/\*\*/.rev_map.*' in the FILES section below for details).
473+
Follow 'reset' with a 'fetch' and then 'git reset' or 'git rebase' to
474+
move local branches onto the new tree.
455475

456476
-r <n>;;
457477
--revision=<n>;;
@@ -684,7 +704,7 @@ svn-remote.<name>.noMetadata::
684704
+
685705
This option can only be used for one-shot imports as 'git svn'
686706
will not be able to fetch again without metadata. Additionally,
687-
if you lose your .git/svn/**/.rev_map.* files, 'git svn' will not
707+
if you lose your '$GIT_DIR/svn/\*\*/.rev_map.*' files, 'git svn' will not
688708
be able to rebuild them.
689709
+
690710
The 'git svn log' command will not work on repositories using
@@ -804,16 +824,16 @@ Tracking and contributing to an entire Subversion-managed project
804824

805825
------------------------------------------------------------------------
806826
# Clone a repo with standard SVN directory layout (like git clone):
807-
git svn clone http://svn.example.com/project --stdlayout
827+
git svn clone http://svn.example.com/project --stdlayout --prefix svn/
808828
# Or, if the repo uses a non-standard directory layout:
809-
git svn clone http://svn.example.com/project -T tr -b branch -t tag
829+
git svn clone http://svn.example.com/project -T tr -b branch -t tag --prefix svn/
810830
# View all branches and tags you have cloned:
811831
git branch -r
812832
# Create a new branch in SVN
813833
git svn branch waldo
814834
# Reset your master to trunk (or any other branch, replacing 'trunk'
815835
# with the appropriate name):
816-
git reset --hard remotes/trunk
836+
git reset --hard svn/trunk
817837
# You may only dcommit to one branch/tag/trunk at a time. The usage
818838
# of dcommit/rebase/show-ignore should be the same as above.
819839
------------------------------------------------------------------------
@@ -827,7 +847,7 @@ have each person clone that repository with 'git clone':
827847

828848
------------------------------------------------------------------------
829849
# Do the initial import on a server
830-
ssh server "cd /pub && git svn clone http://svn.example.com/project
850+
ssh server "cd /pub && git svn clone http://svn.example.com/project [options...]"
831851
# Clone locally - make sure the refs/remotes/ space matches the server
832852
mkdir project
833853
cd project
@@ -840,8 +860,9 @@ have each person clone that repository with 'git clone':
840860
git config --remove-section remote.origin
841861
# Create a local branch from one of the branches just fetched
842862
git checkout -b master FETCH_HEAD
843-
# Initialize 'git svn' locally (be sure to use the same URL and -T/-b/-t options as were used on server)
844-
git svn init http://svn.example.com/project
863+
# Initialize 'git svn' locally (be sure to use the same URL and
864+
# --stdlayout/-T/-b/-t/--prefix options as were used on server)
865+
git svn init http://svn.example.com/project [options...]
845866
# Pull the latest changes from Subversion
846867
git svn rebase
847868
------------------------------------------------------------------------
@@ -973,12 +994,22 @@ without giving any repository layout options. If the full history with
973994
branches and tags is required, the options '--trunk' / '--branches' /
974995
'--tags' must be used.
975996

997+
When using the options for describing the repository layout (--trunk,
998+
--tags, --branches, --stdlayout), please also specify the --prefix
999+
option (e.g. '--prefix=origin/') to cause your SVN-tracking refs to be
1000+
placed at refs/remotes/origin/* rather than the default refs/remotes/*.
1001+
The former is more compatible with the layout of Git's "regular"
1002+
remote-tracking refs (refs/remotes/$remote/*), and may potentially
1003+
prevent similarly named SVN branches and Git remotes from clobbering
1004+
each other. In Git v2.0 the default prefix used (i.e. when no --prefix
1005+
is given) will change from "" (no prefix) to "origin/".
1006+
9761007
When using multiple --branches or --tags, 'git svn' does not automatically
9771008
handle name collisions (for example, if two branches from different paths have
9781009
the same name, or if a branch and a tag have the same name). In these cases,
9791010
use 'init' to set up your Git repository then, before your first 'fetch', edit
980-
the .git/config file so that the branches and tags are associated with
981-
different name spaces. For example:
1011+
the $GIT_DIR/config file so that the branches and tags are associated
1012+
with different name spaces. For example:
9821013

9831014
branches = stable/*:refs/remotes/svn/stable/*
9841015
branches = debug/*:refs/remotes/svn/debug/*
@@ -1006,7 +1037,7 @@ CONFIGURATION
10061037
-------------
10071038

10081039
'git svn' stores [svn-remote] configuration information in the
1009-
repository .git/config file. It is similar the core Git
1040+
repository $GIT_DIR/config file. It is similar the core Git
10101041
[remote] sections except 'fetch' keys do not accept glob
10111042
arguments; but they are instead handled by the 'branches'
10121043
and 'tags' keys. Since some SVN repositories are oddly
@@ -1035,8 +1066,8 @@ comma-separated list of names within braces. For example:
10351066
[svn-remote "huge-project"]
10361067
url = http://server.org/svn
10371068
fetch = trunk/src:refs/remotes/trunk
1038-
branches = branches/{red,green}/src:refs/remotes/branches/*
1039-
tags = tags/{1.0,2.0}/src:refs/remotes/tags/*
1069+
branches = branches/{red,green}/src:refs/remotes/project-a/branches/*
1070+
tags = tags/{1.0,2.0}/src:refs/remotes/project-a/tags/*
10401071
------------------------------------------------------------------------
10411072

10421073
Multiple fetch, branches, and tags keys are supported:
@@ -1060,8 +1091,21 @@ $ git svn branch -d branches/server release-2-3-0
10601091

10611092
Note that git-svn keeps track of the highest revision in which a branch
10621093
or tag has appeared. If the subset of branches or tags is changed after
1063-
fetching, then .git/svn/.metadata must be manually edited to remove (or
1064-
reset) branches-maxRev and/or tags-maxRev as appropriate.
1094+
fetching, then $GIT_DIR/svn/.metadata must be manually edited to remove
1095+
(or reset) branches-maxRev and/or tags-maxRev as appropriate.
1096+
1097+
FILES
1098+
-----
1099+
$GIT_DIR/svn/\*\*/.rev_map.*::
1100+
Mapping between Subversion revision numbers and Git commit
1101+
names. In a repository where the noMetadata option is not set,
1102+
this can be rebuilt from the git-svn-id: lines that are at the
1103+
end of every commit (see the 'svn.noMetadata' section above for
1104+
details).
1105+
+
1106+
'git svn fetch' and 'git svn rebase' automatically update the rev_map
1107+
if it is missing or not up to date. 'git svn reset' automatically
1108+
rewinds it.
10651109

10661110
SEE ALSO
10671111
--------

git-svn.perl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,7 +1389,17 @@ sub cmd_multi_init {
13891389
usage(1);
13901390
}
13911391

1392-
$_prefix = '' unless defined $_prefix;
1392+
unless (defined $_prefix) {
1393+
$_prefix = '';
1394+
warn <<EOF
1395+
WARNING: --prefix is not given, defaulting to empty prefix.
1396+
This is probably not what you want! In order to stay compatible
1397+
with regular remote-tracking refs, provide a prefix like
1398+
--prefix=origin/ (remember the trailing slash), which will cause
1399+
the SVN-tracking refs to be placed at refs/remotes/origin/*.
1400+
NOTE: In Git v2.0, the default prefix will change from empty to 'origin/'.
1401+
EOF
1402+
}
13931403
if (defined $url) {
13941404
$url = canonicalize_url($url);
13951405
init_subdir(@_);
@@ -1759,7 +1769,7 @@ sub get_commit_entry {
17591769
my $msgbuf = "";
17601770
while (<$msg_fh>) {
17611771
if (!$in_msg) {
1762-
$in_msg = 1 if (/^\s*$/);
1772+
$in_msg = 1 if (/^$/);
17631773
$author = $1 if (/^author (.*>)/);
17641774
} elsif (/^git-svn-id: /) {
17651775
# skip this for now, we regenerate the

t/t9117-git-svn-init-clone.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,71 @@ test_expect_success 'clone to target directory with --stdlayout' '
5252
rm -rf target
5353
'
5454

55+
test_expect_success 'init without -s/-T/-b/-t does not warn' '
56+
test ! -d trunk &&
57+
git svn init "$svnrepo"/project/trunk trunk 2>warning &&
58+
test_must_fail grep -q prefix warning &&
59+
rm -rf trunk &&
60+
rm -f warning
61+
'
62+
63+
test_expect_success 'clone without -s/-T/-b/-t does not warn' '
64+
test ! -d trunk &&
65+
git svn clone "$svnrepo"/project/trunk 2>warning &&
66+
test_must_fail grep -q prefix warning &&
67+
rm -rf trunk &&
68+
rm -f warning
69+
'
70+
71+
test_svn_configured_prefix () {
72+
prefix=$1 &&
73+
cat >expect <<EOF &&
74+
project/trunk:refs/remotes/${prefix}trunk
75+
project/branches/*:refs/remotes/${prefix}*
76+
project/tags/*:refs/remotes/${prefix}tags/*
77+
EOF
78+
test ! -f actual &&
79+
git --git-dir=project/.git config svn-remote.svn.fetch >>actual &&
80+
git --git-dir=project/.git config svn-remote.svn.branches >>actual &&
81+
git --git-dir=project/.git config svn-remote.svn.tags >>actual &&
82+
test_cmp expect actual &&
83+
rm -f expect actual
84+
}
85+
86+
test_expect_success 'init with -s/-T/-b/-t without --prefix warns' '
87+
test ! -d project &&
88+
git svn init -s "$svnrepo"/project project 2>warning &&
89+
grep -q prefix warning &&
90+
test_svn_configured_prefix "" &&
91+
rm -rf project &&
92+
rm -f warning
93+
'
94+
95+
test_expect_success 'clone with -s/-T/-b/-t without --prefix warns' '
96+
test ! -d project &&
97+
git svn clone -s "$svnrepo"/project 2>warning &&
98+
grep -q prefix warning &&
99+
test_svn_configured_prefix "" &&
100+
rm -rf project &&
101+
rm -f warning
102+
'
103+
104+
test_expect_success 'init with -s/-T/-b/-t and --prefix does not warn' '
105+
test ! -d project &&
106+
git svn init -s "$svnrepo"/project project --prefix="" 2>warning &&
107+
test_must_fail grep -q prefix warning &&
108+
test_svn_configured_prefix "" &&
109+
rm -rf project &&
110+
rm -f warning
111+
'
112+
113+
test_expect_success 'clone with -s/-T/-b/-t and --prefix does not warn' '
114+
test ! -d project &&
115+
git svn clone -s "$svnrepo"/project --prefix="" 2>warning &&
116+
test_must_fail grep -q prefix warning &&
117+
test_svn_configured_prefix "" &&
118+
rm -rf project &&
119+
rm -f warning
120+
'
121+
55122
test_done

0 commit comments

Comments
 (0)