Mercurial extension to automatically create a .hgignore file?

I thought it would be nice to have a command like "hg ignore" that would automatically add all the raw files to the .hgignore file.

Manually editing the .hgignore file is powerful, but when I often create new repositories, it would be nice to add only the files I want and then execute hg ignore so that Mercurial automatically ignores the others.

Does anyone know of any extensions that do this?

+6
source share
1 answer

Try this as soon as you add all the necessary files:

hg stat --unknown --no-status >> .hgignore

You can create a command to automatically create .hgignore with alias . On a Unix-like system, add the following lines to .hg/hgrc (or one of the Mercurial other configuration files ):

 [alias] ignore = !echo 'syntax: glob' >> $(hg root)/.hgignore && \ $HG status --unknown --no-status >> $(hg root)/.hgignore 

This will give you the hg ignore command, which will populate the .hgignore file with all currently unknown files, thereby turning them into ignored ones.

On Windows, the syntax for an alias is:

 [alias] ignore = !echo syntax: glob > .hgignore && "%HG%" status --unknown --no-status -X .hgignore >> .hgignore 

On Windows, you must run it in the root directory of the repository, otherwise the .hgignore file will be created in the current directory, which is probably not the way you want.

Syntax ! in aliases is new in Mercurial 1.7. In earlier versions you can add

 [alias] ignore = status --unknown --no-status 

and then redirect the output of this command to the .hgignore file yourself:

  hg ignore >> .hgignore 

Then you also need to take care of adding the syntax: glob line if necessary (the default syntax is regular expressions).

+12
source

Source: https://habr.com/ru/post/885818/


All Articles