Tuesday, March 6, 2012

I Hate Mercurial

Yes I do. But, I have to use it. So...here are some commands for simple daily work. Did not find this exactly in a single reference source.

This is what I need to do to change the folder structure
> mkdir NewSubFolder
> hg mv .\1.SomeFile.sql .\NewSubFolder
> hg commit -A  -m "Move files to new folder"

This is what I needed to review code when I was coming up to speed.
> hg init #make a place to share your code. This will store many branches
> hg clone #copy a full software repo to your machine
> hg branches #what branches do I have to choose from
>hg branch #what branch am I in?
>hg update #update the working dir (or switch revisions)
>hg pull --insecure https://host.com/PROJECT # pull from source to the current dir w/o checking the certificate.
> hg merge
this is what I need to share my changes
> hg branch WebDriverSpike-QP418 # creates a new branch. for some reason mercurial docs say to only do this for release level commit streams, but I do it for spikes and feature development
> hg commit -m WebDriverSpike-QP418 # commit changes to my branch use hg branch here to ensure you are in your Branch.

> hg push

OOPS. I hit the error:
   abort: crosses branches (merge branches or use --clean to discard changes)

When you want to switch between at two branches you use update. However this forces you to either merge or drop changes. I find that silly as branches are independent in TFS and I can easily run two instances of my IDE to compare them. In Mercurial you have to clone your whole repository manually then in one repo you would update and drop the changes.

> hg clone repoOld repoNew
> cd repoOld
> hg update -C default #drops changes prior to changing branches

The long form is
1.       Create the folder structure locally (below is a suggested folder layout) using Windows Explorer.
3.       Dump the existing software project folders under the correct functional test area (e.g. Selenium code goes under UI testing, T-SQL goes under ETL testing)
4.       Create a repository at the top level project folder (where it says <Your Top Level Software Project Folder - N levels deep>)
5.      Add the same files to the HG repository
6.       Commit exisitng code via HG.
7.       Share out your top level folder for source control via Windows Explorer (where it says Source below) with your team via a security group.
8.       Log onto the repository server.
9.       Go to C:\Source
10.   Create the same folder structure as above, up to top level software project folder
11.   Steps from cmd line in Powershell

PS C:\> cd C:\Source\Team1
PS C:\Source\Team1> cd .\ProjectA
PS C:\Source\Team1\ProjectA> hg init .
PS C:\Source\Team1\ProjectA> ls

    Directory: C:\Source\Team1\ProjectA


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----         6/15/2012   4:30 PM            .hg - this confirms the repository was created
d----         6/15/2012   3:20 PM            ProjectA

PS C:\Source\Team1\ProjectA> cd .\ImpactDataArchive
PS C:\Source\Team1\ProjectA\FeatureA.1> hg clone \ machine>\Source\Team1   --this is your local development machine\<your 
updating to branch default
34 files updated, 0 files merged, 0 files removed, 0 files unresolved

You should now be able to commit and push changes to the server as a backup. You have to issue a commit AND a push for the changes to show up on the server. There is a Powershell extension to combine those steps.
I can use the same steps as 8-12 to pull or push to anyone on the team (peer to peer).

No comments:

Post a Comment