希望将简单的SVN工具转换为Git

时间:2014-06-27 13:16:15

标签: git bash svn bitbucket

因此,该工具的目的是提取我们在每个版本中使用的静态文件来跟踪SOX信息。

以下是我以前使用的代码:

   
FirstOfYear=`date +%Y-01-01`
Today=`date +%Y-%m-%d`

StartDate=${FirstOfYear}
EndDate=${Today}

# Change these for the app (as it appears in SVN) and the Code for the file names
app=FooApp
code=FA

# Clean up last Run
rm ${code}_*.txt
rm TT${code}_*.txt
#Setup the Header
last="0.0"
echo "${code} Releases ${StartDate} - ${EndDate}" >> TT${code}_Release_List.txt

for Release in `svn log -v --revision {${StartDate}}:{${EndDate}}   http://svn.mynet.com/repos/${app}/tags |grep "A /tags" | sed 's/.*gs\/\([0-9|.]*\).*/\1/g'`
do
 if [ ${last} != ${Release} ]; then

        svn export http://svn.mynet.com/repos/${app}/tags/"$Release"/docs/release_notes.txt ${code}_"$Release"_release_notes.txt
        cat ${code}_"$Release"_release_notes.txt | ./../GenSummary.pl >> ${code}_Summary.txt
        cat ${code}_"$Release"_release_notes.txt | ./../GenReleaseList.pl >> TT${code}_Release_List.txt
        echo http://svn.mynet.com/repos/${app}/tags/"$Release"/docs/release_notes.txt >> ${code}_Summary.txt
        echo ================================================= >> ${code}_Summary.txt

 fi
 last=$Release

done

所以只是为了解释......这个脚本只是在指定的日期之间查看SVN存储库,然后拉出创建的标签。然后它从存储库中提取密钥文件。

我们已经/正在迁移到Git,我们正在使用git-workflow所以在循环结束时,我们在主分支上有一组标记。

现在我我唯一可以解决我为SVN做的事情就是克隆存储库,这样我就可以对其进行轮询以获取信息......

有人有任何其他建议吗?顺便说一下,我们正在使用Bitbucket作为我们的中央存储库。

1 个答案:

答案 0 :(得分:0)

好的,我认为我有一个有效的解决方案。当然,你必须首先在本地克隆repo,然后在repo中做这样的事情:

FirstOfYear=`date +%Y-01-01`
Today=`date +%Y-%m-%d`

StartDate=${FirstOfYear}
EndDate=${Today}

for commit in `git tag --list |xargs git show --since=$StartDate --before=$EndDate --format='COMMIT: %H'|grep 'COMMIT: '|cut -d' ' -f2`; do
    git show $commit:docs/release_notes.txt >> /tmp/output_file
done

这是for循环中那个丑陋混乱的细分:

1:列出所有标签:

git tag --list

2:将所有这些代码传递给git show,过滤掉您未查找的日期内的所有内容,然后使用前缀COMMIT:打印出提交

xargs git show --since=$StartDate --before=$EndDate --format='COMMIT: %H'

3:解析出该输出的提交哈希值

grep 'COMMIT: '|cut -d' ' -f2`

现在我们有一个在您想要的日期范围内标记的提交列表,我们可以使用git cat-file转储每个标记的release_notes.txt

您应该可以添加所需的任何其他特殊处理。

<强> --- --- EDIT

如果您需要输出文件名称中的标记名称,则可以执行以下操作:

FirstOfYear=`date +%Y-01-01`
Today=`date +%Y-%m-%d`

StartDate=${FirstOfYear}
EndDate=${Today}

for tag_and_commit in `git tag --list |xargs git show --since=$StartDate --before=$EndDate|perl -ne '$_=join("", <>); while(/^tag (\w+).*?^commit (\w+)/gsm) { print "$1-$2\n" }'`; do
    IFS='-' read -r -a ARR <<< "$tag_and_commit"
    tag=${ARR[0]}
    commit=${ARR[1]}
    git show $commit:docs/release_notes.txt >> /tmp/$tag-output_file
done

请注意,在bash脚本中执行所有这些操作变得非常难看(可能部分原因在于我的弱bash技能)。可能更好的长期将其转换为perl / ruby​​ /无论脚本。