2012-04-29 88 views
4

考虑的SVN仓库具有非常重要的生产文件:防止意外文件提交

. 
├── Makefile 
├── README 
├── config 
│   └── system_configurations 
│    └── IMPORTANT.conf 
.... 

开发人员经常更改IMPORTANT.conf本地出于测试目的,但不希望意外提交。

有没有办法保护这个文件,以便提交它会显示某种警告或需要一些特殊的命令行参数?

我知道有一些架构解决方案(例如,在本地使用LOCAL_IMPORTANT.conf,符号链接等) - 我正在寻找来自SVN领域的解决方案。

回答

1

我会找到一种方法,您可以将IMPORTANT.conf完全从SVN中取出,并让CI服务器将其从另一个位置复制到另一个位置 - 例如IMPORTANT_Dev.conf,IMPORTANT_Prod.conf等。

从技术上讲,你可以做一个post-commit钩子或pre-commit钩子来解析IMPORTANT.conf的提交细节,并且对开发者进行拍击或者提交失败,但这看起来过度使用源代码控制工具进行配置管理。

1

也许这不是一个simpliest的解决方案,但绝对配置和一般:

SVN挂钩(在这种情况下,pre-commit钩子)
您可以自由使用不同的脚本语言,然后你就可以以防止与预定义的承诺,评论不期而遇的变化,如:
(伪代码)

if(affected(important_file) && !commmentContains("IMPORTANT_FILE_CHANGE")) { 
    return false; 
} 

你可以找到关于谷歌的文章很多,但这里有一个例子:
http://wordaligned.org/articles/a-subversion-pre-commit-hook

1

有很多可能的解决方案。我希望锁定(正如Khoi所提到的)。在关键文件上设置svn:needs-lock,然后让人们明确地锁定他们实际上需要更改的罕见情况。

http://svnbook.red-bean.com/en/1.7/svn.advanced.locking.html

另一种解决方案可能是虽然SVN的访问控制。 SVN存储库如何被访问?HTTP和svn访问都允许权限要在路径设置:

http://svnbook.red-bean.com/en/1.7/svn.serverconfig.pathbasedauthz.html

+0

也SVN:如果它的单个文件/目录也忽略http://svnbook.red-bean.com/en/1.1/ch07s02.html – ehime 2012-05-01 22:14:03

0

尝试只是忽略它

# --------------------------------------------------------------------- 
#  Ignore all the .txt files in the /trunk/Blah/ directory 
# --------------------------------------------------------------------- 

# Go to the directory 
cd trunk/Blah/    # The directory with the files 

# Start editing the properties for the current directory 
svn propedit svn:ignore . # Opens an editor (SVN_EDITOR, EDITOR) 

# Add the following value with a new line, save, and exit: 
*.txt 

# See that things worked 
svn propget svn:ignore . # So you can see the properties 
svn status --no-ignore  # You should see an 'I' next to the ignored files 

# Commit 
svn commit -m "New Ignores" # You must commit the new property change 


# --------------------------------------------------------------------- 
#  Ignore a single file secret.txt in the /trunk/ directory 
# --------------------------------------------------------------------- 

# Go to the directory 
cd trunk/ 

# Add just the single file to the current directories ignore list (like above) 
# Note the dot at the end of the command is important 
svn propset svn:ignore secret.txt . 

# See that things worked 
svn propget svn:ignore . # Notice the single file was added to the list 
svn status --no-ignore  # You should see an 'I' next to the ignored files 

# Commit 
svn commit -m "Its secret" # You must commit the new property change 

当你想提交它,使用

svn changelist ignore-on-commit {file-you-want-to-add} 

如果你想找到未版本化的文件

svn status | grep ^\? | awk '{print $2}'