Note that there are some explanatory texts on larger screens.

plurals
  1. POMercurial Subrepos - How do you create them and how do they work?
    primarykey
    data
    text
    <p><strong>Situation</strong></p> <p>I have two .NET solutions (<code>Foo</code> and <code>Bar</code>) and a common library that contains ProjectA, ProjectB, and ProjectC. <code>Foo</code> and <code>Bar</code> reference one or more library projects, but the library projects are not located within the <code>Foo</code> and <code>Bar</code> Solution folders.</p> <p><strong>Directory structure:</strong></p> <pre><code>-- My Documents* -- Development -- Libraries -- ProjectA -- ProjectB -- ProjectC -- Projects -- Foo -- Solution -- .hg -- .hgignore -- Foo { Project Folder } -- FooTests { Project Folder } -- Foo.sln { References ProjectA } -- Foo.suo -- Bar -- Solution -- .hg -- .hgignore -- Bar { Project Folder } -- BarTests { Project Folder } -- Bar.sln { References ProjectA and ProjectB } -- Bar.suo </code></pre> <p>*alas, I'm still using Windows XP...</p> <p><strong>Mercurial Subrepositories</strong></p> <p><strong>Goal</strong> - I want to set up subrepos so that I can store the source code for any referenced library projects in my <code>Foo</code> and <code>Bar</code> repositories.</p> <p>According to <a href="https://www.mercurial-scm.org/wiki/subrepos" rel="nofollow noreferrer">this page</a> (which is literally the only documentation I can find on subrepos), setting up a subrepo requires executing the following commands from a DOS console window: </p> <pre><code>1| $ hg init main 2| $ cd main 3| $ hg init nested 4| $ echo test &gt; nested/foo 5| $ hg -R nested add nested/foo 6| $ echo nested = nested &gt; .hgsub 7| $ hg add .hgsub 8| $ ci -m "initial commit" </code></pre> <p><strong>Questions</strong></p> <ol> <li>Can any or all of these steps be executed with TortoiseHG, as of version 0.9.2? If yes, how? I'm pretty sure lines 1-3 can, but I don't know about lines 4-7. None of this seems to be documented in TortoiseHG.</li> <li>What does the above code do (a line-by-line explanation would be much appreciated). Here are some specific questions that came to mind as I was trying to decipher it: <ul> <li>What does <code>&gt;</code> do? I tried searching through the Mercurial docs for <code>&gt;</code>, but didn't find anything.</li> <li>In line 5, I don't understand what <code>nested/foo</code> is. Where did <code>foo</code> come from? What is <code>foo</code>? A repository? A folder?</li> <li>Line 6 - this one completely baffles me.</li> <li>In line 7, I assume <code>.hgsub</code> is being added to <code>main</code>? Or is it being added to <code>nested</code>?</li> </ul></li> <li>Let's say I get my subrepos set up, and my <code>Bar</code> repository is now up to revision 10. If I attempt to update my working directory to revision 7, will this cause my library folders (<code>My Documents/Development/Libraries/ProjectA</code> and <code>.../Libraries/ProjectB</code>) to update to whatever is stored in revision 7 as well?</li> </ol> <p><strong>Update</strong></p> <p>I added an 8th line of code: <code>ci -m "initial commit"</code>. This does two things: (1) adds a .hgsubstate file to the main repo and (2) commits all changes, including the new subrepo into the main repository (with message "initial commit"). The purpose of the .hgsubstate file is to keep track of the state of all subrepos, so if you return to an earlier revision, it will grab the correct revision from all subrepos as well.</p> <hr> <p><strong>Update 2 - some instructions</strong></p> <p>After further experimentation, I <em>think</em> I can now provide the steps to solve my original problem (using mostly Windows Explorer and TortoiseHG):</p> <p><strong>Creating a subrepo</strong></p> <ol> <li><code>Libraries/ProjectA</code>, <code>Libraries/ProjectB</code>, and the main repositories (<code>Projects/Foo/Solution</code> and <code>Projects/Bar/Solution</code>) must be separate repositories.</li> <li>Open <code>Projects/Foo/Solution</code>.</li> <li>Clone from <code>Libraries/ProjectA</code> to <code>Projects/Foo/Solution</code>.</li> <li>Add <code>ProjectA</code> to the <code>Foo</code> repository.</li> <li><p>Use a text editor to create a file called <code>.hgsub</code>, containing the following:</p> <pre><code>ProjectA = ProjectA </code></pre></li> <li><p>Open a DOS console window and enter the following commands <strong>(see note below)</strong>:</p> <pre><code>cd c:\...\Projects\Foo\Solution hg ci -m "Committing subrepo "ProjectA" </code></pre></li> <li><p>For <code>Bar</code>, the steps are basically the same, except the .hgsub file should contain entries for both projects, like this:</p> <pre><code>ProjectA = ProjectA ProjectB = ProjectB </code></pre></li> </ol> <p><strong>Note:</strong> starting with TortoiseHG 0.10 (which is slated for March), you will be able to use the <code>HG Commit</code> shell command to do this, but for now, you have to use the command line.</p> <p>Once this is all set up, it gets a little easier.</p> <p><strong>Committing changes</strong> - to commit changes to <code>Foo</code> or <code>Bar</code>, you do a <code>Synchronize/Pull</code> operation for each subrepo to get the subrepos in sync with the latest revisions in the library project repositories. Then you again use the command line to commit the changes (until version 0.10, when you can just use TortoiseHG to commit).</p> <p><strong>Updating working directory to an earlier revision</strong> - This seems to work pretty normally with TortoiseHG and doesn't seem to require use of any DOS commands. To actually work with the earlier revision in Visual Studio, you will need to do a <code>Synchronize/Push</code> operation to put the older version of the library projects back into the <code>Libraries/ProjectX</code> folder.</p> <p>As much as I like TortoiseHG for simple tasks, it's probably better to write batch files for frequently used subrepo operations (especially updating).</p> <p>Hope this helps someone in the future. If you see any mistakes, please let me know (or feel free to edit yourself if you are able).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload