Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it safe to use the same ignores file for Git, Mercurial, and Bazaar?

Git, Mercurial, and Bazaar all seem to have similar formats for their ignore file (.gitignore, .hgignore, .bzrignore [see also bzr patterns]).

In order to improve synchronization of the global ignore files, would it be safe to use one as an actual file and simply symlink the other two to that file? In other words, is there any danger in making my $HOME/.gitignore the canonical ignores file and doing

ln -s $HOME/.gitignore $HOME/.hgignore
ln -s $HOME/.gitignore $HOME/.bazaar/ignore

or is there some subtle difference among them that would bite me at some point?

like image 607
gotgenes Avatar asked Mar 14 '12 03:03

gotgenes


1 Answers

The syntax used in the ignore files is different from system to system:

  • Mercurial: list of regular expressions — can be changed with a syntax: glob line.

  • Bazaar: list of shell glob patterns — prefixing with RE: to match as regular expression.

  • Git: list of shell glob patterns.

Furthermore, the exact rules for how the shell patterns and regular expressions are matched differ from tool to tool. All in all, this means that you can only hope to use this trick if your global ignore file is pretty simple. Otherwise the differences can come and bite you, as you say.

I tested it with this file:

syntax: glob
.bzr
.git
.hg
*.o
*~

and it seems to work as intended across all three tools. To test it, I created this directory tree:

$ tree
.
|-- foo.c
|-- foo.c.~1~
|-- foo.h
|-- foo.o
`-- src
    |-- bar.c
    |-- bar.c.~1~
    `-- bar.o

and ran the status command for each tool:

$ for tool in hg git bzr; do echo "== $tool status =="; $tool status; done
== hg status ==
? foo.c
? foo.h
? src/bar.c
== git status ==
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       foo.c
#       foo.h
#       src/
nothing added to commit but untracked files present (use "git add" to track)
== bzr status ==
unknown:
  foo.c
  foo.h
  src/

As you can see, this simple file works fine.

Technically, Git and Bazaar will now ignore a file called syntax: glob, but unless you plan to create a file with that weird name, this doesn't matter. Finally, note that Mercurial doesn't read a $HOME/.hgignore file by default. But you can make it read it by adding

[ui]
ignore.my-default = ~/.hgignore

to your $HOME/.hgrc file.

like image 68
Martin Geisler Avatar answered Oct 28 '22 03:10

Martin Geisler