Yaocl
Yaocl

Reputation: 194

git-svn with strict permission

I am working on a svn repository out of my control. It uses a standard layout with very strict permissions.

I have't read permission to the parent folder.

svn://foo.bar/project/
svn://foo.bar/project/branches

But I can read svn://foo.bar/project/trunk and svn://foo.bar/project/branches/x.

If I use multiple remotes with git-svn, I can fetch and commit these branches. But the git-svn will not find the branch's parent. Multiple remotes will be treated as different repositories.

It seems I can modify the git-svn to correct the follow parent source. But I don't known perl. Is it possible to write a script fix the branch's parent hash. Or can I use a simple script to create new remote branch then let git-svn to fetch it.

Upvotes: 1

Views: 211

Answers (1)

Yaocl
Yaocl

Reputation: 194

I wrote a simple dirty shell script to init the new branch.It will create the first commit for the svn branch. After that the git-svn fetch --all will work.

#!/bin/bash

branch=$1
prefix=svn-remote.svn-$branch
rooturl=svn://example.com
branchurl=$rooturl/foo/branches
git config $prefix.ignore-paths "^exclude"
git config $prefix.url $branchurl/$branch
git config $prefix.fetch :refs/remotes/$branch

logentry=$(svn log -v -r0:HEAD --stop-on-copy -l 1 --xml $branchurl/$branch)
torev=$(echo "$logentry" |grep revision |grep -o [0-9]*)
fromrev=$(echo "$logentry" |grep copyfrom-rev |grep -o [0-9]*)
frompath=$(echo "$logentry" |grep copyfrom-path | sed -E 's/\s*copyfrom-path="(.*)"/\1/')
author=$(echo "$logentry" |grep "<author>" |sed -E 's#</?author>##g')
author_date=$(echo "$logentry" |grep "<date>" |sed -E 's#</?date>##g')

if [ -z $torev ];then
    exit 1;
fi

if [ -z $fromrev ];then
    exit 2;
fi

if [ -z $frompath ];then
    exit 3;
fi

fromurl=$rooturl$frompath@$fromrev
tourl=$branchurl/$branch@$torev
frombranch=$(basename $frompath )
echo $fromurl
echo $tourl
echo $fromrev
parent=$(git svn log -r $fromrev $frombranch --oneline --show-commit |grep $fromrev |awk '{print $3}')
if [ -z $parent ];then
    exit 4;
fi
uuid=$(git log -1 |grep git-svn-id: | awk '{print $NF}')
tree=$(git cat-file commit $parent |head -1 |cut  -d ' ' -f 2)
echo tree $tree
echo parent $parent
echo uuid $uuid

head=$(GIT_AUTHOR_NAME=$author GIT_AUTHOR_EMAIL=$author@$uuid GIT_AUTHOR_DATE=$author_date git commit-tree $tree -p $parent <<EOF
$logentry

git-svn-id: $tourl $uuid 
EOF
)
echo $head
git update-ref refs/remotes/$branch $head

Upvotes: 1

Related Questions