git svn info: Unable to determine upstream SVN information from working tree history

If you ever had to work with a clone of a git repo which was created with git-svn, you might have tried to run

git svn info .

to find out about the latest svn revision in the git tree. Instead, you will see the error message

Unable to determine upstream SVN information from working tree history

and you might scratch your head. Turns out that git svn info only works for local trees created with git-svn. Once you clone such a tree, all svn related metadata will be lost. This data loss is by design. Apparently git considers svn info to be “metadata” which will not be cloned, whereas git history is not “metadata” and will thus be cloned. Is is also apparently fairly well known among git developers and advanced users that git svn only works from the repository it is initialized from, but the documentation doesn’t mention this limitation anywhere AFAICS. Similar issues exist for git svn log.

Side note: Microsoft Word (and pretty much every other word processor out there) will warn you about possible metadata loss if you save a document in the format of an earlier Word version. A similar warning from git might help people to avoid pushing git repos created with git-svn to some public server.

I wish to thank wereHamster and cbreak on irc.freenode.net/#git for patiently explaining the whole situation and associated design decisions to me.

Since the current state of affairs is completely unacceptable to me, I decided to write a git-svn-info script which produces output in a style similar to svn info. The output should be identical in formatting to what you get from svn info, but it will only output a subset of information. I might have overlooked something and offer no guarantees that it will work for you. The URL will be incorrect if you’re running this outside the base directory. Besides that, it’s a bash script and probably won’t work if your bash location differs. If anyone wants to help making this a portable shell script, please post a comment.

#!/bin/bash
git log|
        grep git-svn-id|
        sed 's/.*git-svn-id:[[:blank:]]*\([^@]\+\)@[0-9]\+[[:blank:]]\+\([^[:blank:]]\+\)/\1 \2/'|
        sort|
        uniq|
        while read url uuid; do
                revision=$(git log --grep="git-svn-id.*$uuid"|grep git-svn-id|sed 's/.*@//;s/[[:blank:]].*//'|sort -n|tail -1)
                author=$(git log --grep="git-svn-id: $url@$revision $uuid" --pretty=format:"%an")
                #date=$(git log --grep="git-svn-id: $url@$revision $uuid" --pretty=format:"%ad" --date=local)
                #echo "Path: "
                echo "URL: $url"
                #echo "Repository Root: "
                echo "Repository UUID: $uuid"
                echo "Revision: $revision"
                #echo "Node Kind: "
                #echo "Schedule: "
                echo "Last Changed Author: $author"
                #echo "Last Changed Rev: "
                #echo "Last Changed Date: "
        done

Published by

Carl-Daniel Hailfinger

coreboot and flashrom developer