1

我正在开发一个我无法控制的 svn 存储库。它使用具有非常严格权限的标准布局。

我没有读取父文件夹的权限。

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

但我可以阅读svn://foo.bar/project/trunksvn://foo.bar/project/branches/x

如果我在 git-svn 中使用多个遥控器,我可以获取并提交这些分支。但是 git-svn 不会找到分支的父级。多个遥控器将被视为不同的存储库。

看来我可以修改 git-svn 以更正后续父源。但我不知道perl。是否可以编写脚本修复分支的父哈希。或者我可以使用一个简单的脚本来创建新的远程分支,然后让 git-svn 来获取它。

4

1 回答 1

1

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
于 2012-04-13T03:03:19.640 回答