2010-06-04 68 views
0

我希望能夠管理我的應用程序依賴關係在Mercurial中,這樣在我的應用程序中我有一個依賴庫的叉/克隆。我希望對應用程序內的依賴關係庫進行更改並提交,但仍會從依賴關係的主庫中提取和合並更改。推送我的應用程序應該推它的依賴庫,但依賴文件不應該由應用程序庫「跟蹤」。這可能嗎?使用Mercurial管理作爲嵌套存儲庫的依賴關係

的目錄結構:

-- app 
    -- .hg 
    -- dependency 
     -- .hg 

當我提交到應用程序庫中,這是確定的,但不是最好犯依賴庫的任何變化。

當我推送我的應用程序存儲庫時,嘗試推送依賴存儲庫是不行的。

下面的會議探討了試圖使用subrepos的isssue。該場景模擬了應用程序和lib位於託管資源庫(如Google代碼)上的場景。我也曾嘗試告訴Mercurial忽略子庫。

# Make library on Google Code 
mkdir libOnGCode 
cd libOnGCode/ 
hg init 
echo "this library is really complex" > libfile 
hg add 
hg ci -m "I'm so awesome..." 
cd .. 

# Make app on Google Code 
mkdir appOnGCode 
cd appOnGCode/ 
hg init 
echo "my base app" > appfile 
hg add 
hg ci -m "Initial app commit" 
cd .. 

# Bring down local copy of app 
hg clone appOnGCode appLocal 
cd appLocal 
hg clone ../libOnGCode/ lib 
# abort: path 'lib/libfile' is inside repo 'lib' 
echo "I'm gonna use a library" >> appfile 
hg add lib 
hg add lib/* 
hg ci -m "Added a library" 
hg push # It's not tracking lib 

echo "Trying subrepos round 1..." 
echo lib = lib > .hgsub 
hg add .hgsub 
hg ci -m "Adding subrepo" 
# committing subrepository lib 
hg push 
# pushing to /workingdir/appOnGCode 
# pushing subrepo lib 
# abort: repository /workingdir/appOnGCode/lib not found! 

echo "Trying subrepos round 2..." 
echo lib = ../libOnGCode > .hgsub 
hg ci -m "Adding subrepo" 
hg push 
# Cool, the subrepo worked, pulling app pulls lib 
cd lib 
echo "My addition to the lib" >> libfile 
hg ci -m "Adding extra functionality" 
cd .. 
hg push 
cd ../libOnGCode 
hg update 
echo "Argh, it updated the lib on google code" 
echo "If I didn't have permission to push on the lib repo, pushing the app would fail" 
cat libfile 
echo "Removing those changes" 
hg backout -m "Removing those changes" tip 
cd ../appLocal/lib/ 
hg pull -u 
echo "Trying to add extra functionality again" >> libfile 
hg ci -m "Trying again" 
cd .hg/ 
echo "Removing hgrc, which only has path info" 
rm hgrc 
cd ../../ 
hg push 
cd ../appOnGCode 
hg update 
cat lib/libfile 
# Tears hair out 

PS。如果任何人都可以修復格式,我會很感激。

回答

1

這是到目前爲止,我已經找到了最好的解決辦法:http://rklophaus.com/articles/20100124-SubmodulesAndSubreposDoneRight.html

生鏽Klophaus寫了這個小腳本重命名.hg目錄.subhg,有效地欺騙水銀以爲沒有一個嵌套的存儲庫。該腳本還將hg命令委託給真正的hg,並將該目錄設置爲.subhg,所以只要你有他的subhg腳本,幾乎所有東西都可以工作。您可以選擇將.subhg目錄添加到.hgignore中,以便不拉/推動所有子庫的歷史記錄。

這樣做的缺點是貢獻者必須擁有subhg才能提交到嵌套存儲庫。我會在Mercurial中看到這種功能。

0

而不是在本地克隆libOnGCode回購,您可以首先將其克隆到託管appOnGCode回購,並添加它作爲subrepo那裏嗎?然後,當您克隆appOnGCode回購時,libOnGCode的副本將具有其default路徑指向Google代碼上的appOnGCode/lib回購。基本上,這個順序:

hg init libOnGCode 
# Do stuff in libOnGCode 
hg commit -m "Library is all set up" 

hg init appOnGCode 
# Do some stuff in appOnGCode 
hg clone libOnGCode lib 
echo lib = lib > .hgsub 
hg add 
hg commit -m "App is all set up" 

# on your local system... 
hg clone /path/to/appOnGCode app 
cat app/lib/.hg/hgrC# Shows default is in appOnGCode/lib 
# Do some stuff to app and/or lib 
hg commit -m "Local stuff" 
hg push # Only goes to /appOnGCode. 

如果您還需要從原來的libOnGCode回購拉的變化,你可以拉他們到appOnGCode回購或直接到當地的回購;無論哪種方式,一切都應該同步。

+0

我不認爲有可能將其克隆到Google Code中。 – 2010-06-05 21:02:31