简体   繁体   English

如何判断你是否在git-svn repo命令行中?

[英]How to tell if you're in a git-svn repo command line?

I'm trying to modify my bash prompt to print out if I'm in a git-svn repo. 我正在尝试修改我的bash提示符,如果我在git-svn repo中打印出来。 I see that git svn repos have a .git/svn folder, so I could check with: 我看到git svn repos有一个.git / svn文件夹,所以我可以查看:

# Find the top level git folder
_git_dir=`git rev-parse --show-toplevel 2> /dev/null`
# Find svn folder
_gsvn_check=`cd $_git_dir; ls .git/svn 2> /dev/null`

But then I noticed that my normal git repo has a .git/svn folder. 但后来我注意到我的普通git repo有一个.git / svn文件夹。 Is there any way to know for sure that you're in git-svn? 有没有办法确定你是在git-svn?

The .git/svn directory can be created if you run any git svn command in any repository - eg just running git svn info , as Carl Norum suggests will create it. 如果你在任何存储库中运行任何git svn命令,都可以创建.git/svn目录 - 例如,只需运行git svn info ,正如Carl Norum建议的那样 However, a slightly better test might be that .git/svn exists and is non-empty, eg 但是,稍微好一点的测试可能是.git/svn存在且非空,例如

[ -d .git/svn  ] && [ x != x"$(ls -A .git/svn/)" ] && echo Looks like git-svn

If you want a stricter test, you could look through the history of HEAD for any commit messages that contain a git-svn-id - essentially that's what git svn info is doing before it gives up. 如果你想要一个更严格的测试,你可以查看HEAD的历史记录,看看包含git-svn-id任何提交消息 - 基本上这就是git svn info在放弃之前所做的事情。 For example: 例如:

[ x != x"$(git log -n 1 --grep='^\s*git-svn-id' --oneline)" ] && echo "git-svn!"

... but it sounds as if that might be too slow for your use case. ...但听起来好像对你的用例来说可能太慢了。

The source code in git-svn.perl describes the layout of a git-svn repository in its different versions: git-svn.perl中的源代码描述了git-svn存储库的不同版本的布局:

... so you could write tests for all of those if you want to be careful to catch all the different versions. ...所以如果你想小心捕捉所有不同的版本,你可以为所有这些编写测试。

You should be able to use git svn info . 你应该能够使用git svn info Example output for a git-svn repository: git-svn存储库的示例输出:

Path: .
URL: svn+ssh://url/path/to/something/trunk
Repository Root: svn+ssh://path/to/something
Repository UUID: c22683c8-8Bcb-47f9-aeb8-1c337d8f7a2d
Revision: 12345
Node Kind: directory
Schedule: normal
Last Changed Author: somebody
Last Changed Rev: 12345
Last Changed Date: 2012-01-24 16:38:36 -0800 (Tue, 24 Jan 2012)

And for a regular git repo: 而对于常规的git repo:

Unable to determine upstream SVN information from working tree history

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM