使Mercurial子存储库的行为类似于颠覆外部 [英] Making mercurial subrepositories behave like subversion externals

查看:91
本文介绍了使Mercurial子存储库的行为类似于颠覆外部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

常见问题解答和hginit.com对于帮助我从svn过渡到hg确实非常有用.

The FAQ, and hginit.com have been really useful for helping me make the transition from svn to hg.

但是,当涉及以Subversion的外部方式使用Hg的子存储库功能时,我已经尝试了所有方法,并且无法复制svn外部的良好行为.

However, when it comes to using Hg's subrepository feature in the manner of subversion's externals, I've tried everythign and cannot replicate the nice behavior of svn externals.

这是我想做的最简单的例子:

Here's the simplest example of what I want to do:

  1. 初始化"lib"存储库 该存储库永远不能用作独立存储库;它总是包含在main中 存储库,作为子存储库.

  1. Init "lib" repository This repository is never to be used as a standalone; it's always included by main repositories, as a sub-repository.

初始化一个或多个(包括存储库) 为了使示例简单,我将初始化"一个名为"main"的存储库

Init one or more including repositories To keep the example simple, I'll "init" a repository called "main"

主"包含"lib"作为子存储库

Have "main" include "lib" as a subrepository

重要-这是我无法工作的地方: 当我在"main/lib"中修改文件并推送修改时, 然后将该更改推送到"lib"存储库-而不是副本 在主要"内部.

Importantly -- AND HERE'S WHAT I CAN'T GET TO WORK: When I modify a file inside of "main/lib", and I push the modification, then that change gets pushed to the "lib" repository -- NOT to a copy inside of "main".

命令行胜于雄辩.在这个主题上,我尝试了很多变化,但这是要点.如果有人可以在命令行中答复,我将永远感激不已!

Command lines speak louder than words. I've tried so many variations on this theme, but here's the gist. If someone can reply, in command lines, I'll be forever grateful!

$ cd/home/moi/hgrepos ##我将hg存储库存储在主服务器上的位置

$ cd /home/moi/hgrepos ## Where I'm storing my hg repositories, on my main server

$ hg初始化库

$ echo"foo"> lib/lib.txt

$ echo "foo" > lib/lib.txt

$ hg添加lib

$ hg add lib

$ hg ci -A -m"Init lib" lib

$ hg ci -A -m "Init lib" lib

$ cd/home/moi/hgrepos

$ cd /home/moi/hgrepos

$ hg初始化主程序

$ hg init main

$ echo"foo"> main/main.txt

$ echo "foo" > main/main.txt

$ hg添加主

$ cd main

$ cd main

$ hg clone ../lib lib

$ hg clone ../lib lib

$ echo"lib = lib"> .hgsub

$ echo "lib=lib" > .hgsub

$ hg ci -A -m初始化主程序".

$ hg ci -A -m "Init main" .

一切正常,但是当我克隆主"存储库并本地化时 修改"main/lib"中的文件,然后将其推送,更改将推送到"main/lib"中, 不要"lib".

This all works fine, but when I make a clone of the "main" repository, and make local modifications to files in "main/lib", and push them, the changes get pushed to "main/lib", NOT to "lib".

$/home/moi/hg-test

$ /home/moi/hg-test

$ hg clone ssh://moi@www.moi.com/hgrepos/lib lib

$ hg clone ssh://moi@www.moi.com/hgrepos/lib lib

$ hg clone ssh://moi@www.moi.com/hgrepos/main main

$ hg clone ssh://moi@www.moi.com/hgrepos/main main

$ cd main

$ cd main

$ echo foo >> lib/lib.txt

$ echo foo >> lib/lib.txt

$ hg st

M lib.txt

M lib.txt

$ hg com -m从主存储库内部修改了lib.txt" lib.txt

$ hg com -m "Modified lib.txt, from inside the main repos" lib.txt

$ hg push

$ hg push

它表明我已经修改了lib中文件的COPY,而不是lib存储库中的文件.如果这按我希望的那样工作,则推动将是hgrepos/lib,而不是hgrepos/main/lib.即,我会看到:

It shows that I've made a modification to a COPY of a file in lib, NOT to a file in the lib repository. If this were working as I'd like it to work, the push would be to hgrepos/lib, NOT to hgrepos/main/lib. I.e., I would see:

$ hg push

$ hg push

推送到ssh://moi@www.moi.com/hgrepos/lib

pushing to ssh://moi@www.moi.com/hgrepos/lib

提前谢谢!

艾米莉在波特兰

推荐答案

问题出在您的.hgsub文件上.它指向lib库的位置,因此,如果lib是main的同级文件,则应该为:

The problem is with your .hgsub file. It points to where the lib repo is, so if lib is a sibling to main it should be:

lib=../lib

您的hg add libhg add main行也没有意义.将那些添加到main和lib之外的回购中?您正在/home/moi/hgrepos中运行它们.

Also your hg add lib and hg add main lines don't make sense. To what repo outside of main and lib are those being added? You're running them while in in /home/moi/hgrepos.

这是您的脚本,有一些调整:

Here's your script with some tweaks:

+ cd /home/ry4an/hgtest
+ hg init lib
+ echo foo
+ cd lib
+ hg commit -A -m Init lib
adding lib.txt
+ cd /home/ry4an/hgtest
+ hg init main
+ echo foo
+ cd main
+ echo lib=../lib
+ hg clone ../lib
destination directory: lib
updating to branch default
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ hg add .hgsub main.txt
+ hg commit -m Init main: initial file and a .hgsub
committing subrepository lib
+ cd /home/ry4an/hgtest
+ hg clone main main-clone
updating to branch default
pulling subrepo lib
requesting all changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files
3 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ cd main-clone
+ echo foo
+ hg commit -m Modified lib.txt, from inside the main repos
committing subrepository lib
+ hg push
pushing to /home/ry4an/hgtest/main
pushing subrepo lib
searching for changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files
searching for changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files

要通过ssh://进行此操作,您只需要进行一次更改.克隆主仓库时,将hg clone main main-clone更改为hg clone ssh://host/hgtest/main main-clone -克隆主仓库会自动克隆lib –这就是子仓库的好处.

To do that over ssh:// you need only make a single change. When cloning the main repo change hg clone main main-clone to hg clone ssh://host/hgtest/main main-clone -- cloning the main automatically clones the lib -- that's the subrepo benefit.

这是该工作的日志:

+ cd /home/ry4an/hgtest
+ hg init lib
+ echo foo
+ cd lib
+ hg commit -A -m Init lib
adding lib.txt
+ cd /home/ry4an/hgtest
+ hg init main
+ echo foo
+ cd main
+ echo lib=../lib
+ hg clone ../lib
destination directory: lib
updating to branch default
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ hg add .hgsub main.txt
+ hg commit -m Init main: initial file and a .hgsub
committing subrepository lib
+ cd /home/ry4an/hgtest
+ hg clone ssh://localhost/hgtest/main main-clone
The authenticity of host 'localhost (::1)' can't be established.
RSA key fingerprint is 0c:58:d6:d3:d3:16:14:ee:3b:be:01:bc:c7:3c:92:0b.
Are you sure you want to continue connecting (yes/no)? yes
ry4an@localhost's password: 
requesting all changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 3 changes to 3 files
updating to branch default
pulling subrepo lib
ry4an@localhost's password: 
requesting all changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files
3 files updated, 0 files merged, 0 files removed, 0 files unresolved
remote: Warning: Permanently added 'localhost' (RSA) to the list of known hosts.
+ cd main-clone
+ echo foo
+ hg commit -m Modified lib.txt, from inside the main repos
committing subrepository lib
+ hg push
ry4an@localhost's password: 
pushing to ssh://localhost/hgtest/main
pushing subrepo lib
ry4an@localhost's password: 
searching for changes
remote: adding changesets
remote: adding manifests
remote: adding file changes
remote: added 1 changesets with 1 changes to 1 files
searching for changes
remote: adding changesets
remote: adding manifests
remote: adding file changes
remote: added 1 changesets with 1 changes to 1 files

这篇关于使Mercurial子存储库的行为类似于颠覆外部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆