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. But the right to delete any post for any reason is reserved. Don't make me do it. Aim for constructiveness. Comments may be republished, emailed to your loved ones or printed and used as toilet paper. Also, I get particularly nasty on comment spam. It's not worth even trying to post comment spam here -- your html is escaped, and your links are given a rel='nofollow'. By attempting to post a comment, you understand that if the comment is considered spam, at my absolute discretion, your IP address may be used as the target of a prolonged distributed denial of service attack. Your electricity might suddenly stop working. Your car tyres will go mysteriously flat. You will suffer permanent hairloss. Your dreams will be filled with terrifying monsters. And in any case I reserve the right to record and publish your IP address.

 

TimeSnapper is 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

Use it for:

  • extracting data from text
  • manipulating text
  • generating code

It makes you look awesome. Use it right now! Go on! Hurry! Don't walk, run!

 

Articles

Mind-boggling Demo of New Gaming Genre, aka Folder-Based Hangman, aka Fun with Recursion Mind-boggling Demo of New Gaming Genre, aka Folder-Based Hangman, aka Fun with Recursion
Got CSV in your javascript? Use agnes. Got CSV in your javascript? Use agnes.
I went to write down a book name and founded an internet empire instead. I went to write down a book name and founded an internet empire instead.
NimbleText: Origins NimbleText: Origins
The Windows 8 Mullet The Windows 8 Mullet
Cosby: spontaneous striped background generator Cosby: spontaneous striped background generator
Slides from WDCNZ: Live Coding Asp.net MVC3 Slides from WDCNZ: Live Coding Asp.net MVC3
MVC 3, MVC 3, "Third Times a Charm" references
Custom Errors in ASP.Net MVC: It couldn't be simpler, right? Custom Errors in ASP.Net MVC: It couldn't be simpler, right?
Anatomy of a Domain Hijacking, part 2: The Website Who Came In From The Cold Anatomy of a Domain Hijacking, part 2: The Website Who Came In From The Cold
Anatomy of a Domain Hijacking, part 1 Anatomy of a Domain Hijacking, part 1
secretGeek.net domain has been stolen. The site may go down. secretGeek.net domain has been stolen. The site may go down.
Boring article: 'untrusted domain' issue with SQL Server. Boring article: 'untrusted domain' issue with SQL Server.
Coding While You Commute Coding While You Commute
Test Driven Dentistry Is A Good Thing Test Driven Dentistry Is A Good Thing
The 'less crashy' release of NimbleText The 'less crashy' release of NimbleText
Rethinking Toolbars in Visual Studio (or any IDE) Rethinking Toolbars in Visual Studio (or any IDE)
Where shall we have lunch? Where shall we have lunch?
Setting up email for your microIsv Setting up email for your microIsv
The NO Visual Studio movement: Compiling .net projects in Notepad++ The NO Visual Studio movement: Compiling .net projects in Notepad++
ZeroOne: the editor for programmers who think in binary ZeroOne: the editor for programmers who think in binary
Mercurial workflow for personal projects (with a .net bias) Mercurial workflow for personal projects (with a .net bias)
I see you're using vim. Let me fix that for you. I see you're using vim. Let me fix that for you.
The worst recruitment spam I've ever read The worst recruitment spam I've ever read
A thank you I forgot to say A thank you I forgot to say
My new product, NimbleText, is live My new product, NimbleText, is live
Grabbing the free songs of Jonathan Coulton (with Powershell) Grabbing the free songs of Jonathan Coulton (with Powershell)
Using NimbleSet to compare lists Using NimbleSet to compare lists
Wanted: Wiki Lists (dot org) Wanted: Wiki Lists (dot org)
DOS on Dope: The last MVC web framework you'll ever need DOS on Dope: The last MVC web framework you'll ever need
JSON Query Languages: 5 special purpose editors JSON Query Languages: 5 special purpose editors
What then, is b? What then, is b?
SQLike: A simple editor SQLike: A simple editor
Yet Another BizPlan Generator. Yet Another BizPlan Generator.
HOT GUIDS: A hot or not site for guids HOT GUIDS: A hot or not site for guids
How does life get better? One tiny hack at a time. How does life get better? One tiny hack at a time.
24 things to do, and 100 things *not* to do (yet) for building a MicroISV 24 things to do, and 100 things *not* to do (yet) for building a MicroISV
Venture capital won't kill Jeff Atwood, it will only make him Jeffer. Venture capital won't kill Jeff Atwood, it will only make him Jeffer.
A handy workflow image for newbie mercurial users A handy workflow image for newbie mercurial users
Fractal Feedback, a diversion into recreational programming Fractal Feedback, a diversion into recreational programming
Hump-Jumping: How the Education of Computer Science can be Saved, err, maybe. Hump-Jumping: How the Education of Computer Science can be Saved, err, maybe.
Suggested User Experience Improvements for DiffMerge Suggested User Experience Improvements for DiffMerge
SQL Style Extensions for C# SQL Style Extensions for C#
The Movie Hollywood (And My Wife) Doesn't Want You To See: Weekend at Jacko's The Movie Hollywood (And My Wife) Doesn't Want You To See: Weekend at Jacko's
Sysi: the ultimate administrators toolkit Sysi: the ultimate administrators toolkit

Archives .: secretGeek :: Complete Archives
TimeSnapper -- Automated Screenshot Journal TimeSnapper.com    
Version 3.3: true productivity boost

Next Action NextAction
Managing the top of your mind

NimbleText -- World's Simplest Code GeneratorNimbleText -- World's Simplest Code Generator, Text Manipulator, Data Extractor

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
Thomas White
OJ Reeves
Eric Sink

Aggregated Links

proggit
dzone
hacker news
dot net kicks

Human Link Machines

interesting finds
a continuous learner's weblog
arjan's world
weekly link post

LinkedIn profile
LogEnvy - event logs made sexy
Computer, Unlocked. A rapid computer customization resource
PC Smart Buys - Computer Hardware in Australia
 
home .: about .: sign up .: sitemap .: secretGeek RSS .: © Leon Bambrick 2006 .: privacy

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