【问题标题】:Using Mercurial to manage dependencies as nested repositories使用 Mercurial 将依赖项作为嵌套存储库进行管理
【发布时间】:2010-06-04 19:11:50
【问题描述】:

我希望能够在 Mercurial 中管理我的应用程序依赖项,以便在我的应用程序内部拥有依赖项存储库的 fork/clone。我想对应用程序内的依赖库进行更改并提交更改,但仍从依赖项的主存储库中提取和合并更改。推送我的应用程序应该与它一起推送依赖项存储库,但应用程序存储库不应“跟踪”依赖项文件。这可能吗?

目录结构:

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

当我提交到应用程序存储库时,可以但最好不要在依赖项存储库中提交任何更改。

当我推送我的应用存储库时,尝试推送依赖存储库是不行的。

下面的会话探讨了尝试使用子存储库的问题。该场景模拟了应用程序和库位于托管存储库(如 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。如果有人可以修复格式,我将不胜感激。

【问题讨论】:

    标签: version-control mercurial


    【解决方案1】:

    这是迄今为止我找到的最佳解决方案:http://rklophaus.com/articles/20100124-SubmodulesAndSubreposDoneRight.html

    Rusty Klophaus 编写了这个小脚本来将 .hg 目录重命名为 .subhg,从而有效地诱使 Mercurial 认为没有嵌套的存储库。该脚本还将 hg 命令代理到真正的 hg,将目录设置为 .subhg,因此只要您拥有他的 subhg 脚本,几乎所有内容都可以正常工作。您可以选择将 .subhg 目录添加到您的 .hgignore 中,这样您就不会拉/推所有子存储库的历史记录。

    这样做的缺点是贡献者必须有 subhg 才能提交到嵌套存储库。我希望喜欢在 Mercurial 中看到这种功能。

    【讨论】:

      【解决方案2】:

      您可以先将其克隆到托管的appOnGCode 存储库中,然后将其作为子存储库添加,而不是在本地克隆libOnGCode 存储库吗?然后,当您克隆 appOnGCode 存储库时,您拥有的 libOnGCode 的副本将具有指向 Google 代码上的 appOnGCode/lib 存储库的 default 路径。基本上,这个顺序:

      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 repo 中提取更改,您可以将它们拉入appOnGCode repo 或直接拉入您的本地 repo;无论哪种方式,一切都应该同步。

      【讨论】:

      • 我认为不可能将其克隆到 Google 代码中。
      猜你喜欢
      • 2017-07-01
      • 1970-01-01
      • 2013-10-11
      • 2012-03-29
      • 2011-06-14
      • 2020-09-28
      • 1970-01-01
      • 2017-12-11
      • 1970-01-01
      相关资源
      最近更新 更多