Reputation: 350
I have a change to a file which I explicitly never want to commit to the repo. (In this case, its a hack around a bug that needs to be resolved by fixing an unrelated codebase.)
Is there a way to mark the change so that Hg will error out if I try to commit it? Ideally, it would be something inline in a comment so that I could choose to not commit that section of code (with TortoiseHg) and still be able to commit other portions.
Currently, I just have the change labelled with a nasty comment block, but it would be a great security blanket if I could tell the repo that this is dangerous code.
Upvotes: 1
Views: 25
Reputation: 5605
An alternative to writing a hook is to commit the change, and move it to the secret
phase. This will prevent ever pushing it to another repository. It also allows you to easily apply the change on top of any changeset by rebasing the secret commit.
Use a bookmark or a named branch to make the changeset easy to select.
hg branch externalbugworkaround
hg commit -m "HACK - workaround external bug. DO NOT PUSH"
hg phase -s -f externalbugworkaround
then to move it around
hg rebase --keepbranches -d rev -r externalbugworkaround
Upvotes: 1
Reputation: 6044
As you suggest yourself: the solution is to write a client-side commit hook which parses the file with a regex and errors-out when the code you want to skip committing is part of the commit.
A simple hook which checks for bad file extensions and commit messages is found for instance here - it should be easy to extend to checking a certain file for a specific pattern.
Upvotes: 0