3

I am new to the Mercurial and would like to seek some experienced advices about where to set branch under situation of my team's project. The project will be shared by 4 other members.

I have a repository on my local machine at directory /home/Cassie/localRepository/src1. There is another directory on my machine /home/Cassie/localRepository/src2 which holds most of common files as src1 directory but also has some different files. For example, at /home/Cassie/localRepository/src1, there are

file1 file2 file3 file4 file5

at /home/Cassie/localRepository/src2, there are

file1 file2 file3 file4(version2) file5(version 2)

I would like to make them to be two different branches and work on them separately. However, I still keep working on file1, file2 and fil3 and hope that both of these branches get updated files1 files2 files3 along with time. Please notice that both file4 and file5 at src1 directory share the same name as ones at src2 directory. If I move every files in the same directory, there will be no way to distinguish which version from which. It's why I saved one version of file4 and file5 at src1 directory and another version of file4 and file5 at scr2 directory. I have an team account at bitbucket and have pushed src1 directory to the account. Thus, the bitbucket has all files at src1 as a central repository. Now, I have problems of where to set up branch for src2 and achieve my goal.

Btw, my local machine is Linux RedHat workstation 6.2 and has mercurial 1.7 and tortoisehg 1.5.

I have tried some experiments:

(1) I created another directory, src as my local repository. Copied file1,2,3 to it, added and committed them.

(2) Then, I copied file4 from src1 directory to src and make it a branch called src1-Branch, copied, added file4.txt to src1-branch and committed it.

(3) created another branch called src2-branch, switched to src2-branch by

hg update src2-branch

,copied file4(version2) from src2 directory to current directory by

 cp ../src2/file4.txt .

,added file4 and tried to commit file4.txt. However, I encountered a error message as

waiting for lock on working directory of /home/Cassie/src held by 'Cassie-PC:20994'

I then googled online and people suggested to remove the .hg/wlock. It worked !

Anyone knows Why the problem happened at the first place ? Did I do something wrong when I add the file4.txt from the src2 to src2-branch ? Thanks

Cassie
  • 1,179
  • 6
  • 18
  • 30

1 Answers1

1

I think you can accomplish what you want using Mercurial branches. You can keep changes to your files separate across branches, optionally merging those changes into other branches. In your src1 repository, create a src2 branch:

 > hg branch src2

Then, you can delete files 4 and 5 and add files 6 and 7:

> hg remove file4 file5
> cp ..\src2\file6 .
> cp ..\src2\file7 .
> hg add file6 file7
> hg commit -m "Removing file4 and file5; adding file6 and file7."

Then you use Mercurial's merge command to bring changes from one branch into the other. From your original question, it sounds like you want to bring changes from the default (src1) branch into the src2 branch. In that case you would:

> hg up src2
> hg merge default
> hg commit -m "Merging default -> src2"

Merging brings all unmerged changes from the source branch into the destination branch. If you only want to bring some changes across, use the graft command if you're on Mercurial 2.0 or later, or the transplant extension if on an earlier version.

Aaron Jensen
  • 25,861
  • 15
  • 82
  • 91
  • I am a little bit confused which files are located at which directory. Assume we make src1 as our default branch and make src2 a branch. When you remove files 4,5 and add files 6,7, does src1 directory end up having all files 1~7 at its directory ? Or does src1 has only file1,2,3,6,7 as those at src2 ? If src1 has all files 1~7, it then creates a problem. File4 is in fact the same as file 6 with the same name but different version. For example, they are all called weather.f90 so they can not be put at the same directory. They are fine if they are at different directories. – Cassie Jun 14 '12 at 18:10
  • @Cassie Src1 and src2 are the same directory, but in different branches. If files 4 and 5 are removed and files 6 and 7 added to the src2 branch, it doesn't effect the src1 branch until you merge src2 into src1. If file 4 and file 6 are the same file, with different content, the same concept applies: file 4/6 will be different in the src2 branch than the src1 branch. – Aaron Jensen Jun 15 '12 at 13:46
  • I understand that file 4 and file 6 would be viewed differently for two branches. Assume file 4 is called weather.F90 and file 6 is also called weather.F90. When you perform the command `cp ..\src2\file6 .`, doesn't that overwrite the file4 in current directory ? How can you keep two files with the same name but different contents in the same directory ? Unfortunately, they must share the same file name and it is why I keep them at different directories. Thanks, – Cassie Jun 15 '12 at 17:45
  • Src1 and src2 aren't different directories. That's not how Mercurial works: its branches are stored as metadata. This is different than tools like Subversion where branches are actually different directories. You wouldn't ever do a `cp ..\src2\file`. You would just modify file6, save it, and commit it. The file would then be different between src1 and src2 branches. – Aaron Jensen Jun 15 '12 at 18:57
  • I think what you explained would work well if I haven't created my files yet. The problem is I have already had two files with the same name at different directories.I just installed mercurial and would like to use it to manage the codes. However, I encountered a locking problem when I tried to copy the files with the same name from different directories. Any idea ? I have updated my question.Thanks – Cassie Jun 21 '12 at 18:09