mercurialhgignore

Mercurial: warn when adding files which would otherwise be ignored?


How can ask Mercurial to warn me before I add files which would otherwise be ignored?

For example, something like:

$ hg add foo.o
warning: adding ignored file foo.o

There seems to have been a patch submitted to the mailing list: https://www.mercurial-scm.org/pipermail/mercurial-devel/2008-February/004993.html

But I can't find any further references to it.


Solution

  • It's sort of a hacky workaround and only half what you want, but you could replace

    $ hg add foo.o
    

    with

    $ hg add -I foo.o
    

    That says "add everything but only if it's not ignored and it matches the pattern after -I".

    An example:

    $ ls -A
    .hg  .hgignore  this
    $ cat .hgignore 
    this
    $ hg stat --all
    ? .hgignore
    I this
    $ hg add -I this
    $ hg stat --all
    ? .hgignore
    I this
    

    So you can see that "this" wasn't added and is still in ignored state. Of course, that's not a warning, it's a refusal.