Mercurial workflow for personal projects (with a .net bias)
secretGeek .:dot Nuts about dot Net:.
home .: about .: sign up .: sitemap .: secretGeek RSS

Mercurial workflow for personal projects (with a .net bias)

I'm using mercurial for personal projects and thought I'd share the approach I use with you so you can teach me to improve it.

(If you don't have mercurial, download it and install it now, so you can follow along)

(This isn't a "joke" post by the way. Sometimes my sarcasm runs so deep that I need to stop and reassure people when I'm not being sarcastic. In particular, I need to reassure myself ;-) )

Say I'm creating an open source project, such as fuv. I create the project online, then clone it locally:

c:\projects>md fuv
c:\projects>cd fuv
c:\projects\fuv>hg clone https://hg01.codeplex.com/fuv

(If I'm just creating it locally, like if it's closed-source, then I begin instead with 'hg init.')

The very first thing I add is a .hgignore file. This is the file where you tell mercurial *not* to check in all of those pesky user-specific files that a visual studio project generates, and to avoid versioning the bin and obj folders etc.

I've stolen the .hgignore file from the Funnel Web project because 1) the guys working on that project are much more thorough and intelligent than me, and 2) it was the first .hgignore file I found lying around on my hard drive.

The .hgignore goes in the same folder as the .hg folder. It doesn't go *in* the .hg folder (you don't normally have to go in there at all). It goes in the parent of the .hg folder.

Now it's time to write the code. You could either copy code in from elsewhere (if you had already started it) or if starting from scratch, create a new solution in the folder you've just created.

post build action in visual studio 2010

Here's the bit that I think is clever/stupid. I put a 'post-build' action on the project, so that everytime I build succesfully I check in the work in progress.

It's as simple as adding this to the post build step:

hg addremove
hg commit

This is clever because it means that every tiny change you make is tracked. And it's stupid for the same reason. The main reason reason it's stupid is that it means everytime something has changed you are asked to enter a commit note in a notepad.

It's quite annoying at first. But soon you get into the spirit of it. You realise that it is making you act in a more mindful manner. You are concentrating on every build, more aware of what you are doing, and better focused on your tasks.

Still, that bit could be improved, and it definitely wouldn't be to everyone's taste.

When you've completed a feature you push your work to the server using hg push, like this:

hg push

You have to enter a username and password at that point. Or, if you're pushing often you can store the username/password in mercurial's configuration.

There's a lot of different places and ways you can store this info. I'm going to describe one in particular, but I'm not saying it's the best one. Opinions or improvements welcome.

Remember I said earlier that you don't need to go into .hg folder.... well... go in there. There's a file called 'hgrc.' Editing it using something better than notepad (as it seems to have unix-style line-endings rather than windows-style line-endings (aka '\n' not '\r\n', aka 'Lf' not 'CrLf' aka 'char 10' not 'char13 char10').

Add three lines to it, to tell it the user name and passowrd, and which site they refer to:

[auth]
codeplex.prefix = https://hg01.codeplex.com/fuv
codeplex.username = secretGeek
codeplex.password = joshua

(Joshua is not my real password by the way. And the word before the "." can be whatever word you want as long as it's consistent across all three lines. It's just for grouping purposes.)

Here's the stackoverflow question on mercurial passwords that I got this from.

Automate your pushes!

Once you've got your username/password in place, you can make the push a post build action too!

To make it so that a push only occurs on a 'release' build, try this:

if /I "$(ConfigurationName)" == "Release" hg push

After that you've got an automated, integrated approach to version control even for the most insignificant of little projects.

Getting it setup and in place takes just a minute or two for a new project.

Some of the tweaks I'd like to make to this system are:

1. use some kind of a custom script to generate a proposed commit message. Perhaps it could look in your todo list (such as nextaction) to grab the item you are currently working on.

2. somehow 'flattening' the local commits when pushing, so that all of the in-between personal revisions are squished out of the way.

Also, I've been thinking about using mercurial (with 'auto commit' as described above) for managing a todo.txt file. Every time you save it commits, and a script looks at the diffs to see what tasks were deleted, marked as done, edited, added, etc. While it's an intriguing idea, I think it would need you to be very disciplined and somewhat restricted in the way you use the todo list.

(nexaction, by the way, lets you run custom shell commands when you complete a task. So you could use this to commit the file every time you complete a task. It's a feature I've never discussed with humans, out loud.)





'Wags' on Mon, 14 Feb 2011 13:53:05 GMT, sez:

Regarding #2, check out the hgcollapse extension. It squashed a range of local commits into one commit. Make sure to do this BEFORE pushing those changes to another repo since it does change/destroy history.



'Doeke' on Mon, 14 Feb 2011 15:08:15 GMT, sez:

Why not create the project like this:


c:\projects>hg clone https://hg01.codeplex.com/fuv/ fuv
c:\projects>cd fuv

That saves one line ;-)



'Haacked' on Mon, 14 Feb 2011 15:12:05 GMT, sez:

Ah ha ha ha ha! Another Secret Geek classic! Once again you tickle my funny bone Leon. But in this case, this might actually be useful. I'm having trouble finding the meta joke here.



'Goran' on Mon, 14 Feb 2011 15:32:27 GMT, sez:

I went from SS->SVN->HG. Will probably navigate to ->GIT->DARCS next. Then finally settle on just using Dropbox :)



'Chris Sutton' on Mon, 14 Feb 2011 18:45:48 GMT, sez:

When you commit on every build, what is your commit message? How would you make a meaningful commit message?



'OJ' on Mon, 14 Feb 2011 21:16:23 GMT, sez:

Classic :)

Don't forget that you can combine those two steps into one:

hg commit -a



'Aaron Powell' on Tue, 15 Feb 2011 01:04:47 GMT, sez:

You stole our .hgignore! Oh noes! :P

Another tip Mercurial supports abbreviations in your commands, basically it does a best match on the command, so if you type:

hg addr

The only match for 'addr' is 'addremove'. But if you type:

hg a

You'll get an error as it doesn't know if you wanted the 'add' command, the 'addremove' command (or any of the other ones starting with 'a').

It's a good to know if you do a lot of command-line Mercurial work



'chai' on Tue, 15 Feb 2011 02:23:30 GMT, sez:

Can't you do a hg commit -m "Visual studio local build" to save you the notepad pop up?



'Aaron Powell' on Wed, 16 Feb 2011 02:39:51 GMT, sez:

@chai - you can, but then every commit will be exactly the same message. Not overly useful ;)



'Robert Wagner' on Wed, 16 Feb 2011 04:01:15 GMT, sez:

Not sure if I like reducing the frequency of commits like that. Sure it saves some time, but what if you need to rollback between compiles!?!

No thanks, I'll stick to my file monitoring implementation that checks into hg whenever a file is saved to disk.

It would be nice to have it integrated into VS though. The ability to revert the last few changes (like each character typed) would be great to do right within the IDE. I hate it when I make a typo and have to retype the whole line.



'Paul Stovell' on Wed, 16 Feb 2011 08:18:00 GMT, sez:

I love the "commit on compile" idea, I'm going to give it a try



'lb' on Wed, 16 Feb 2011 09:53:44 GMT, sez:

@Wags
Excellent, that's the extension I was thinking of. I'd heard about using it for squishing commits before pushing to subversion (since subversion is slower at dealing with history)

@Doeke
Nice work, that's 1 line saved.

@OJ
Note it's a capital 'A' on 'hg commit -A'
With hg commit -A we save another line. That's 2 saved.

@Aaron
So we can cut "hg commit -A" down to "hg com -A" -- that's a further 3 bytes!!

So 2 lines and 3 bytes saved, my work is gonna be done in no time!

@Rob
Stick to vss man. You'll be okay.



'OJ' on Wed, 16 Feb 2011 10:43:52 GMT, sez:

Crap, that's what I meant :) I blame the non-Das keyboard I am forced to use at the office.



'Chris Sutton' on Wed, 16 Feb 2011 14:32:11 GMT, sez:

save one more character "hg com -A" -> "hg ci -A" :)



'Robert Wagner' on Wed, 16 Feb 2011 23:15:24 GMT, sez:

@lb

Hope your happy, you started a Vim vs Emacs vs Resharper debate



'lb' on Thu, 17 Feb 2011 22:59:25 GMT, sez:

Other places to view examples of .hgignore files:

dotfiles.org/.hgignore

codepaste.net/search (search for hgignore)

stackoverflow.com/questions/34784/mercurial-hgignore-for-visual-studio-2008-projects/2555413






name


website (optional)


enter the word:
 

comment (HTML not allowed)


All viewpoints welcome. Incivility is not tolerated, such comments are deleted.

 

I'm the co-author of TimeSnapper, a life analysis system that stores and plays-back your computer use. It makes timesheet recording a breeze, helps you recover lost work and shows you how to sharpen your act.

 

NimbleText - FREE text manipulation and data extraction

NimbleText is a Powerful FREE Tool

I wrote this, and use it every day for:

  • extracting data from text
  • manipulating text
  • generating code

It makes you look awesome. You should use NimbleText, you handsome devil!

 

Articles

The Canine Pyramid The Canine Pyramid
Humans: A Tragedy. Humans: A Tragedy.
ACK! ACK!
OfficeQuest... Gamification for the Office Suite OfficeQuest... Gamification for the Office Suite
New product launch: NimbleSET New product launch: NimbleSET
Programming The Robot from Diary of a Wimpy Kid Programming The Robot from Diary of a Wimpy Kid
Happy new year 2014 Happy new year 2014
Downtime as a service Downtime as a service
The Shape of Your Irrationality The Shape of Your Irrationality
This is why I don't go to nice restaurants any more. This is why I don't go to nice restaurants any more.
A flowchart of what programmers do at work all day A flowchart of what programmers do at work all day
The Telepresent Man. The Telepresent Man.
Interview with an Ex-Microsoftie. Interview with an Ex-Microsoftie.
CRUMBS! Commandline navigation tool for Powershell CRUMBS! Commandline navigation tool for Powershell
Little tool for making Amazon affiliate links Little tool for making Amazon affiliate links
Extracting a Trello board as markdown Extracting a Trello board as markdown
hgs: Manage Lots of Mercurial Projects Simultaneously hgs: Manage Lots of Mercurial Projects Simultaneously
You Must Get It! You Must Get It!
AddDays: A Very Simple Date Calculator AddDays: A Very Simple Date Calculator
Google caught in a lie. Google caught in a lie.
NimbleText 2.0: More Than Twice The Price! NimbleText 2.0: More Than Twice The Price!
A Computer Simulation of Creative Work, or 'How To Get Nothing Done' A Computer Simulation of Creative Work, or 'How To Get Nothing Done'
NimbleText 1.9 -- BoomTown! NimbleText 1.9 -- BoomTown!
Line Endings. Line Endings.
**This** is how you pivot **This** is how you pivot
Art of the command-line helper Art of the command-line helper
Go and read a book. Go and read a book.
Slurp up mega-traffic by writing scalable, timeless search-bait Slurp up mega-traffic by writing scalable, timeless search-bait
Do *NOT* try this Hacking Script at home Do *NOT* try this Hacking Script at home
The 'Should I automate it?' Calculator The 'Should I automate it?' Calculator

Archives Complete secretGeek Archives

TimeSnapper -- Automated Screenshot Journal TimeSnapper: automatic screenshot journal

25 steps for building a Micro-ISV 25 steps for building a Micro-ISV
3 minute guides -- babysteps in new technologies: powershell, JSON, watir, F# 3 Minute Guide Series
Universal Troubleshooting checklist Universal Troubleshooting Checklist
Top 10 SecretGeek articles Top 10 SecretGeek articles
ShinyPower (help with Powershell) ShinyPower
Now at CodePlex

Realtime CSS Editor, in a browser RealTime Online CSS Editor
Gradient Maker -- a tool for making background images that blend from one colour to another. Forget photoshop, this is the bomb. Gradient Maker



[powered by Google] 

How to be depressed How to be depressed
You are not inadequate.



Recommended Reading


the little schemer


The Best Software Writing I
The Business Of Software (Eric Sink)

Recommended blogs

Jeff Atwood
Joseph Cooney
Phil Haack
Scott Hanselman
Julia Lerman
Rhys Parry
Joel Pobar
OJ Reeves
Eric Sink

InfoText - amazing search for SharePoint
LogEnvy - event logs made sexy
Computer, Unlocked. A rapid computer customization resource
Aussie Bushwalking
BrisParks :: best parks for kids in brisbane
PhysioTec, Brisbane Specialist Physiotherapy & Pilates
 
home .: about .: sign up .: sitemap .: secretGeek RSS .: © Leon Bambrick 2006 .: privacy

home .: about .: sign up .: sitemap .: RSS .: © Leon Bambrick 2006 .: privacy