MathematicalOrchid
MathematicalOrchid

Reputation: 62848

Mercurial: Prevent commiting certain changes

I'm sure we've all done that thing where you temporarily hot-wire part of your application while you test something. We really don't want to commit such changes though.

Usually I mark such lines with a comment reminding me not to commit this change. But is there some way I can program Mercurial itself to refuse to commit any line containing a certain text fragment? (Not the entire file, just the marked line.) Is there some extension or something that does that?

Upvotes: 1

Views: 52

Answers (2)

Lazy Badger
Lazy Badger

Reputation: 97355

Contrary to (good and correct in terms of sense) platetmaker's answer I'll suggest another way:

  • Enable, learn and use MQ Extension (see also Tutorial page) or, as lightweight alternative, Shelve Extension
  • Store your WIP (modifications in working directory) as MQ-patches or shelves locally until they aren't finished

Upvotes: 0

planetmaker
planetmaker

Reputation: 6044

The answer is a clear 'No, but...' (or 'Yes, but...' - depends on how you see it).

If you always indicate WIP lines in the same manner, I recommend to write and install a (local) commit hook which will fail, if any such WIP lines are detected in the changeset. See https://www.mercurial-scm.org/wiki/Hook and https://www.mercurial-scm.org/wiki/UsefulHooks

In order to commit only some hunks, you can make use of the record extension (it's a default extension, just needs enabling). It allows you to cherry-pick the hunks at commit time. But it will fail at cherry-picking if the WIP code and the 'actual' code are in the same hunk.

Upvotes: 4

Related Questions