This patch picks up on Adrian's work on issue2542. I simplified the test case, and in the process stumbled on another bug in the sanity checks the tag command does on the working dir: with .hgtags dirty, tag aborted even if --local was passed.