1

I need to set up Mercurial HG in order to always take local version of a file that matches in a specific folder.

EG: when conflict on /**/dist/ always take local

This because I need to commit some built files. Thanks in advance

EDIT:

I need to commit some files generated by some processors (libsass, webpack), it depends on a temporary unavailability of my build-system. So, I removed these files from the hgignore. Now, the problem that I'm having is on Mercurial conflicts on these generated files. I want automate the merge-resolving using the local version of these files. similar to: How to keep the local file or the remote file during merge using Git and the command line? but for Mercurial HG

Community
  • 1
  • 1
Hitmands
  • 13,491
  • 4
  • 34
  • 69
  • Brief and concise is good, but this is too brief for me. You don't say *at all* what you try to do and what exactly your problem is at what step in the process. You want to select some files? Why? In what process? For what end, what do you want to do with the selection? Please be more verbose. – planetmaker Mar 22 '16 at 12:24
  • Note that merge tools will come into play when there is a _conflict_; non-conflicting changes will be incorporated in both directions, even with your solution. Are you sure you want this to happen to your built files? – alexis Mar 25 '16 at 22:42
  • Not really, I don't wanna multiple incorporations. I just want to always take the local version of a (for example) webpack output. Because Webpack is always running, it rebuilds everything after each hg pull. There's a solution? – Hitmands Mar 26 '16 at 09:15

1 Answers1

3

You can put a merge-pattern in your ~/.hgrc or .hg/hgrc to specify the default tool for a merge for a given file:

[merge-patterns]
**/dist/* = :local

The :local merge tool will prioritize the local version. See hg help merge-tools for a full list of internal merge tools. Note that using the --tool option during a merge will override this choice; however, setting the ui.merge option to define your default merge tool will not.

The **/dist/* pattern may or may not be what you need. Please adjust it to your needs (and note that regular expression patterns are also available for additional flexibility if required).

Alternatively, you can also automatically resolve these files after the merge, e.g. with:

hg resolve --tool :local $(hg files -I '**/dist/*')

Or, if the list of files is too large to fit on the command line:

hg files -0 -I '**/dist/*' | xargs -0 hg resolve --tool :local
Reimer Behrends
  • 8,600
  • 15
  • 19