使用 Mercurial 将依赖项作为嵌套存储库进行管理

发布于 2024-09-04 10:59:00 字数 2092 浏览 3 评论 0原文

我希望能够在 Mercurial 中管理我的应用程序依赖项,以便在我的应用程序中我有一个依赖项存储库的分支/克隆。我想对应用程序内的依赖项存储库进行更改并提交更改,但仍从依赖项的主存储库中提取并合并更改。推送我的应用程序应该同时推送依赖项存储库,但依赖项文件不应由应用程序存储库“跟踪”。这可能吗?

目录结构:

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

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

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

下面的会议探讨了尝试使用子存储库的问题。该场景模拟应用程序和库位于 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

附言。如果有人可以修复格式,我将不胜感激。

I'd like to be able to manage my app dependencies in Mercurial such that inside my app I have a fork/clone of the dependency repository. I'd like to make and commit changes to the dependency repository inside the app, but still pull and merge changes from the dependency's primary repository. Pushing my app should push the dependency repository with it, but the dependency files shouldn't be "tracked" by the app repository. Is this possible?

The directory structure:

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

When I commit to the app repository, it's OK but not preferable to commit any changes in the dependency repository.

When I push my app repository, it's NOT OK to try to push the dependency repository.

The session below explores the isssue trying to use subrepos. The scenario emulates one where the app and lib are on a hosted repository like Google Code. I have also tried unsuccessfully to tell Mercurial to ignore the subrepository.

# 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. If anyone can fix the formatting on that I'd be grateful.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ぃ弥猫深巷。 2024-09-11 10:59:00

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

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

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

This is the best solution I have found so far: http://rklophaus.com/articles/20100124-SubmodulesAndSubreposDoneRight.html

Rusty Klophaus wrote this small script to rename the .hg directory to .subhg, effectively tricking Mercurial into thinking there isn't a nested repository. The script also proxies hg commands to the real hg, setting the directory to work on as the .subhg, so pretty much everything just works as long as you have his subhg script. You can optionally add the .subhg directory to your .hgignore so you don't pull/push all the subrepository's history.

The downsides of this are that contributors must have subhg to commit to the nested repository. I would love to see this kind of functionality in Mercurial.

女中豪杰 2024-09-11 10:59:00

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

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 存储库或直接提取到本地存储库中;无论哪种方式,一切都应该同步。

Instead of cloning the libOnGCode repo locally, can you first clone it into the hosted appOnGCode repo and add it as a subrepo there? Then when you clone the appOnGCode repo, the copy of libOnGCode that you have will have its default path pointing at the appOnGCode/lib repo on Google Code. Basically, this sequence:

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.

If you also need to pull changes from the original libOnGCode repo, you can either pull them into the appOnGCode repo or directly into your local repo; either way, everything should sync up.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文