2012-04-29 75 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}'