30

I'm using git-svn to store a "staging" version of some SVN repo, where other users are allowed to pull from this staging repo and commit there changes back to it, then the commits on the staging repo are periodically committed the upstream SVN repo.

I want to know if there's a way to map between the git committers' names and SVN usernames, so that their information would be kept intact when committing back to the SVN repo?

Jim Puls
  • 79,175
  • 10
  • 73
  • 78

2 Answers2

28

Vincent Danen does mention the -A option when using git svn:

So using ~/git as a top-level directory for Git repositories [...] create an authors.txt file.
This file will map the names of Subversion committers to Git authors, resulting in a correct history of the imported Subversion repository.
For projects with a small number of committers, this is quite easy. For larger projects with a lot of committers, this may take some time. The syntax of the file would be:

user = Joe User <user@example.com>
vdanen = Vincent Danen <vdanen@somewhere.com>

The short name is the committer name for Subversion whereas the long form is the user’s full name and e-mail address, as used by Git.

The final step is to clone the Subversion repository, which creates a local Git repository based on it. Assuming your repository uses the standards of /trunk, /tags, and /branches, use:

# git svn clone --no-metadata -A authors.txt -t tags -b branches -T trunk https://svn.example.com/svn/repo

-A<filename>
--authors-file=<filename>

Syntax is compatible with the file used by git-cvsimport:

loginname = Joe User <user@example.com>

If this option is specified and git-svn encounters an SVN committer name that does not exist in the authors-file, git-svn will abort operation.
The user will then have to add the appropriate entry.
Re-running the previous git-svn command after the authors-file is modified should continue operation.

config key: svn.authorsfile

This should work for all git-svn commands, including git-svn dcommit (when you push to SVN) (Note: I have not tested it directly though).

Mohammed Gamal does report (in the comments) it is working, but without the --no-metadata option.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • @Christoph: by the way, you *do* have a SVN mirror of an Git repo ( http://stackoverflow.com/questions/570945/git-clone-of-git-svn-tree/571084#571084 ). Did you ever had to use the --authors-file option ? – VonC Mar 24 '09 at 16:20
  • 2
    It doesn't work for me - all commits are dcommitted as user *root* to the SVN. Although I am using the `file:` scheme, I noticed you are using `https:`. What authentication method do you use in Apache that allows setting svn:author? – AndreKR Jun 20 '13 at 01:56
  • Neither -A or --authors-file work with the GitHub for Windows version of these tools. trying either of them will return "Unknown option: A" or "Unknown option: authors-file" respectively. – Tom Lint Jun 28 '15 at 14:37
  • @TomLint GitHub for Windows? I wouldn't know. This is meant to be used with git for windows (https://github.com/git-for-windows/git/), like the latest Git 2.4.4 (https://github.com/git-for-windows/git/releases) – VonC Jun 28 '15 at 14:40
1

a second option is to provide a program / script which solves the mapping.

Very useful if there the number of committers is unknown but might be "generated" from the SVN committer name!

If … SVN committer name that does not exist in the authors-file, git svn will abort operation. The user will then have to add the appropriate entry. Re-running the previous git svn command after the authors-file is modified …

so, therefor we have:

--authors-prog=mapMyCompanyUsers.sh

To not have force every user to checkout / curl / wget'ting the map-Script first, you might provide something like this:

$(tmpMapFile="$TMPDIR/mapSvnUsersAutomatically.$$.sh" && echo -e '#!/bin/sh\necho $1" <"$1"@example.com>"' > $tmpMapFile && chmod +x $tmpMapFile && echo $tmpMapFile)

The clone will look like:

$ git svn clone -s --authors-prog=$(tmpMapFile="$TMPDIR/mapSvnUsersAutomatically.$$.sh" && echo -e '#!/bin/sh\necho $1" <"$1"@example.com>"' > $tmpMapFile && chmod +x $tmpMapFile && echo $tmpMapFile) https://svn.example.com/svn/repo/

This will force all mappings are exacly the same and SVN clones might be "shared" and merged via git!

childno͡.de
  • 4,679
  • 4
  • 31
  • 57