7

I've started using version control to better manage revisions to my PowerShell code. I decided to use Mercurial for 3 main reasons:

  1. As a DVCS, it doesn't require a server.
  2. If I want to, I can store a private repository online for free (bitbucket.org)
  3. It seemed simpler to use than Git.

Mercurial works well for versioning PowerShell Modules since each module is contained in its own directory. However, I have some scripts that don't belong in a module, but I would still like to version them. These scripts are in a ".\Scripts" directory that is added to $env:PATH so I can easily run them from the command line. Since these scripts aren't really related to each other, it doesn't make much sense to create a single repository for the Scripts directory.

How should I version single scripts?

I've thought of the following options:

  • Create subdirectory for each script/related scripts.
  • Use temporary repositories until the script is "stable" then add the script to the main "Scripts" directory and version the collection of scripts as one. This would reduce the number of changesets introduced to the "Scripts" repository.

Is there a tool that better handles versioning single files? Is there better way for versioning single files with Mercurial? Any other ideas?

2
  • This might be a handy tool to have, I've often wanted something like this myself, ability to version individual configuration and script files. Aug 16, 2011 at 7:47
  • Another added bonus to keeping scripts in a DVCS is that you can have the repository on a shared drive and pull the changes to all your servers when you need it and you will always have the up to date version of the scripts. Aug 16, 2011 at 13:11

3 Answers 3

11

Grouping of files based on their functionality should be based on

1) Name.

2) Folder they are in.

Just give a proper name for the scripts. If there are multiple related scripts group them into a folder. Having one script per folder makes no sense. You end up with almost same number of folders as scripts.

All this in a single repository. Generally, people have multiple projects in a single repo. Creating multiple repos, especially for a few files means lots of overhead. If the script is not "stable" use branches. That is what they are for and merge them back.

And don't worry how many "changesets" are there in the repo!

PS: Might seem a bit opinionated, but there is no real right or wrong answer for what you ask.

6
  • I appreciate your answer. I know that with SVN-like VCS multiple projects are usually grouped into 1 repo, but Mercurial commits are made at the repo level. Thus projects are usually kept separate (see: stackoverflow.com/questions/929508/… ). I agree that placing scripts into separate folders is not efficient, but it also doesn't seem like committing a bunch of unrelated scripts is very organised either. It feels like I'm trying to choose the lesser of 2 evils; just looking for opinions.
    – Rynant
    Aug 15, 2011 at 23:07
  • @Rynant - Here is my answer on a similar question for Git - stackoverflow.com/questions/7033601/…. I understand that, but you were talking at file level, that too script (text) files. It will hurt more to have different repos in this context.
    – manojlds
    Aug 15, 2011 at 23:15
  • I'm going to keep everything in the scripts folder as one repo. Each module has its own repo and all of my profile scripts in another repo.
    – Rynant
    Aug 17, 2011 at 17:33
  • I totally agree with @manojlds here. I actually have a "Projects\Modules" folder where I put module projects that I'm working on, and the reason is: I put my whole WindowsPowerShell folder into mercurial, and I can't be bothered with sub-repos for actual projects.
    – Jaykul
    Aug 17, 2011 at 21:07
  • @Jaykul - How do you handle pushing/pulling ShowUI to/from codeplex if it's part of a repo with other modules?
    – Rynant
    Sep 1, 2011 at 14:46
4

Step back, relax, and ask yourself if this is premature optimization. A primary benefit of using VCS is that you do not need to worry about starting with the "perfect" solution. DVCS tracks change history across renames & moves (use hg mv, or try auto-detection with hg addremove --similarity).

These scripts are in a ".\Scripts" directory that is added to $env:PATH so I can easily run them from the command line. Since these scripts aren't really related to each other, it doesn't make much sense to create a single repository for the Scripts directory

If the scripts are all in the same directory, it certainly makes sense to track them in the same repository.

  • Use temporary repositories until the script is "stable" ...

A "temporary" repo defeats the purpose of having a repo, which is to have a history of changes.

This would reduce the number of changesets introduced to the "Scripts" repository.

As @manojlds said, there is no reason to worry about the number of changesets. None.

My advice:

  • Put your experimental scripts in a directory like ./Scripts/incubating/
  • When a script matures, put it in ./Scripts/ or ./Scripts/Foo/ or whatever; use hg mv to help Mercurial track the move/rename
    • Or use hg addremove --similarity to auto-detect moves/renames
  • The script's change history is preserved and you can reorganize your script directories as your collection evolves
1
  • Thanks for the advice; I think I may have been hit by analysis paralysis :-/ It just feels strange to me to have one script that configures Peer-to-Peer SQL replication and another script that collects a domain's computer inventory, and track them in the same repository.
    – Rynant
    Aug 16, 2011 at 1:44
2

I think the chaps here have some good ideas and have pointed out you may be focusing a little too much on it. For completely carefree source control see Tome's guide http://powertoe.wordpress.com/2010/12/12/why-every-it-pro-should-use-mercurial-for-source-control-with-their-powershell-scripts/

I've followed this method and found it very useful. 2 reasons I've found source control useful:

  1. having a bad day and rewritten a script so that it doesn't do anything you want it to and you can't remember how to get it back!

  2. changes in needs, sometimes you need a script to monitor or do something for a short period and then need it to revert to the original set up. easily done with source control.

As such, having all the scripts in one repo isn't really an issue.

I did wonder if you can use it to synchronise computers as well (automatically instead of pushing\pulling when needed) but it's not something I've had time to look at.

3
  • I've seen Tome's post; it was one of the things that pointed me towards Mercurial for source control. For now, I'm not going to schedule automatic commits.
    – Rynant
    Aug 16, 2011 at 12:56
  • I've also thought about pushing/pulling from bitbucket to sync computers. Currently, I'm using Dropbox to store most of my PowerShell scripts. profile.ps1 simply dot-sources a My.profile.ps1 file in .\Dropbox\PSH\Profile. My.profile.ps1 then dot-sources additional scripts based on $Host.Name. In the QA domain at work I do the same thing except with the scripts on a fileshare.
    – Rynant
    Aug 16, 2011 at 12:57
  • both of those are good ideas. were I set up the mercurial sc there wasn't access to either of those services, I know nothing about running a mercurial server so figured I'd leave it until it became something more than cool :)
    – Matt
    Aug 16, 2011 at 13:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.