我希望能够在Mercurial中管理我的应用程序依赖项,以便在我的应用程序中我有一个依赖存储库的fork / clone。我想在应用程序内部创建并提交对依赖项存储库的更改,但仍然从依赖项的主存储库中提取和合并更改。推送我的应用程序应该使用它推送依赖存储库,但不应该由应用程序存储库“跟踪”依赖项文件。这可能吗?
目录结构:
-- app
-- .hg
-- dependency
-- .hg
当我提交到应用程序存储库时,可以在依赖存储库中提交任何更改,但不是更好。
当我推送我的app存储库时,尝试推送依赖存储库是不行的。
下面的会话探讨了尝试使用subrepos的isssue。该场景模拟app和lib位于托管存储库(如Google Code)上的场景。我也尝试过告诉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。如果有人可以修改格式,我将不胜感激。
答案 0 :(得分:1)
这是我到目前为止找到的最佳解决方案:http://rklophaus.com/articles/20100124-SubmodulesAndSubreposDoneRight.html
Rusty Klophaus编写了这个小脚本,将.hg目录重命名为.subhg,有效地诱使Mercurial认为没有嵌套的存储库。该脚本还将hg命令代理到真正的hg,将目录设置为.subhg,所以只要你有他的subhg脚本,几乎所有东西都可以工作。您可以选择将.subhg目录添加到.hgignore中,这样就不会拉/推所有子存储库的历史记录。
这样做的缺点是贡献者必须有subhg才能提交到嵌套的存储库。我会爱在Mercurial中看到这种功能。
答案 1 :(得分:0)
您是否可以首先将其克隆到托管的libOnGCode
仓库并将其添加为子仓库,而不是在本地克隆appOnGCode
仓库?然后,当您克隆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
回购或直接进入您的本地回购;无论哪种方式,一切都应该同步。