diff options
author | Joey Hess <joey@gnu.kitenet.net> | 2009-02-13 23:40:30 -0500 |
---|---|---|
committer | Joey Hess <joey@gnu.kitenet.net> | 2009-02-13 23:40:30 -0500 |
commit | ec0218e86b32dd80d8cb4e5a69ea7d7c9b5f4ad6 (patch) | |
tree | 0d62e0ba272f656b8f36e6c5ad4e789a08c8ade1 | |
parent | 62bd8959418ca26c8b8e45561f4dba71758b0ec3 (diff) |
ignore file update support
* etckeeper update-ignore will automatically update the VCS ignore
file, only touching the part inside a "managed by etckeeper"
comment block.
* Run etckeeper update-ignore on upgrade.
-rw-r--r-- | README | 3 | ||||
-rw-r--r-- | debian/changelog | 4 | ||||
-rw-r--r-- | debian/postinst | 3 | ||||
-rw-r--r-- | etckeeper.8 | 5 | ||||
-rwxr-xr-x | init.d/50vcs-ignore | 102 | ||||
-rwxr-xr-x | update-ignore.d/01update-ignore | 152 | ||||
-rw-r--r-- | update-ignore.d/README | 2 |
7 files changed, 169 insertions, 102 deletions
@@ -82,7 +82,8 @@ it. Using other VCSes should be broadly similar. The `etckeeper init` command initialises an /etc/.git/ repository. This command is careful to never overwrite existing files or directories in -/etc. It will create a `.gitignore` if one doesn't already exist, sets up +/etc. It will create a `.gitignore` if one doesn't already exist +(or update content inside a "managed by etckeeper" comment block), sets up pre-commit hooks if they don't already exist, and so on. It does *not* commit any files, but does `git add` all interesting files for an initial commit later. diff --git a/debian/changelog b/debian/changelog index 2ab4c30..15feb06 100644 --- a/debian/changelog +++ b/debian/changelog @@ -3,6 +3,10 @@ etckeeper (0.30) UNRELEASED; urgency=low * Add vim .*.sw? files to default ignores. * Also add emacs #*# autosave files to default ignores. * And DEADJOE files, for good measure. + * etckeeper update-ignore will automatically update the VCS ignore + file, only touching the part inside a "managed by etckeeper" + comment block. + * Run etckeeper update-ignore on upgrade. -- Joey Hess <joeyh@debian.org> Fri, 13 Feb 2009 22:09:28 -0500 diff --git a/debian/postinst b/debian/postinst index 039c4c0..834b069 100644 --- a/debian/postinst +++ b/debian/postinst @@ -72,4 +72,7 @@ configure) fi done fi + + # prints error and exits nonzero if the ignore file cannot be updated + etckeeper update-ignore || true esac diff --git a/etckeeper.8 b/etckeeper.8 index 33f511f..cfb6828 100644 --- a/etckeeper.8 +++ b/etckeeper.8 @@ -39,6 +39,11 @@ repository. (You can also call this by hand after running dpkg by hand.) .TP .B unclean This returns true if the directory contains uncommitted changes. +.TP +.B update-ignore +This updates the VCS ignore file. Content outside a "managed by etckeeper" +block is not touched. This is generally run when upgrading to a new version +of etckeeper. .SH FILES /etc/etckeeper/etckeeper.conf is the configuration file. diff --git a/init.d/50vcs-ignore b/init.d/50vcs-ignore index 3049b95..bcc88ba 100755 --- a/init.d/50vcs-ignore +++ b/init.d/50vcs-ignore @@ -1,104 +1,4 @@ #!/bin/sh set -e -if [ "$VCS" = git ] && [ ! -e .gitignore ]; then - file=.gitignore -elif [ "$VCS" = hg ] && [ ! -e .hgignore ]; then - file=.hgignore -elif [ "$VCS" = bzr ] && [ ! -e .bzrignore ]; then - file=.bzrignore -elif [ "$VCS" = darcs ] && [ ! -e .darcsignore ]; then - file=.darcsignore -fi - -if [ -z "$file" ] || [ -e "$file" ]; then - exit 0 -fi - -nl() { - echo >>$file -} - -comment() { - comment="$1" - echo "# $comment" >>$file -} - -ignore() { - glob="$1" - - case "$VCS" in - git|bzr) - echo "$glob" >> $file - ;; - hg) - # rather than converting the glob to a regexp, just - # configure hg to use globs - if [ -z "$hg_syntax_printed" ]; then - comment "use glob syntax" - echo "syntax: glob" >> $file - nl - hg_syntax_printed=1 - fi - echo "$glob" >> $file - ;; - darcs) - # darcs doesn't understand globs, so we need to translate - # them into regexs. Not a complete converter, but suitable - # for given globs. - if [ "${glob%\*}" != "$glob" ]; then - glob="${glob%\*}" - else - glob="$glob"'($|/)' - fi - if [ "${glob#\*}" != "$glob" ]; then - glob="${glob#\*}" - else - glob='(^|/)'"$glob" - fi - glob="$( printf %s $glob | sed -e 's/\./\\./g;s/\*/[^\/]*/g;s/\?/[^\/]/g' )" - echo "$glob" >> $file - esac -} - -if [ "$VCS" = darcs ]; then - darcs setpref boringfile .darcsignore -fi - -if [ "$LOWLEVEL_PACKAGE_MANAGER" = dpkg ]; then - comment "new and old versions of conffiles, stored by dpkg" - ignore "*.dpkg-*" - nl -elif [ "$LOWLEVEL_PACKAGE_MANAGER" = "rpm" ]; then - comment "new and old versions of conffiles, stored by apt/rpm" - ignore "*.rpm*" - nl -elif [ "$LOWLEVEL_PACKAGE_MANAGER" = "pacman-g2" ]; then - comment "new and old versions of conffiles, stored by pacman" - ignore "*.pacnew" - ignore "*.pacorig" - ignore "*.pacsave" - nl -fi - -comment "mount(8) records system state here, no need to store these" -ignore blkid.tab -ignore blkid.tab.old -nl - -comment "some other files in /etc that typically do not need to be tracked" -ignore nologin -ignore ld.so.cache -ignore mtab -ignore .pwd.lock -ignore network/run -ignore adjtime -ignore lvm/cache -nl - -comment "editor temp files" -ignore "*~" -ignore ".*.sw?" -ignore "#*#" -ignore DEADJOE -nl +etckeeper update-ignore || true diff --git a/update-ignore.d/01update-ignore b/update-ignore.d/01update-ignore new file mode 100755 index 0000000..0d4edf8 --- /dev/null +++ b/update-ignore.d/01update-ignore @@ -0,0 +1,152 @@ +#!/bin/sh +set -e + +if [ "$VCS" = git ]; then + dir=.git + file=.gitignore +elif [ "$VCS" = hg ]; then + dir=.hg + file=.hgignore +elif [ "$VCS" = bzr ]; then + dir=.bzr + file=.bzrignore +elif [ "$VCS" = darcs ]; then + dir=_darcs + file=.darcsignore +else + echo "etckeeper: unsupported VCS $VCS" >&2 + exit 1 +fi + +if [ ! -d "$dir" ]; then + exit 0 +fi + +managed_by_etckeeper="managed by etckeeper" + +nl() { + echo >>"$file" +} + +comment() { + comment="$1" + echo "# $comment" >>"$file" +} + +ignore() { + glob="$1" + + case "$VCS" in + git|bzr) + echo "$glob" >>"$file" + ;; + hg) + # rather than converting the glob to a regexp, just + # configure hg to use globs + if [ -z "$hg_syntax_printed" ]; then + comment "use glob syntax" + echo "syntax: glob" >>"$file" + nl + hg_syntax_printed=1 + fi + echo "$glob" >>"$file" + ;; + darcs) + # darcs doesn't understand globs, so we need to translate + # them into regexs. Not a complete converter, but suitable + # for given globs. + if [ "${glob%\*}" != "$glob" ]; then + glob="${glob%\*}" + else + glob="$glob"'($|/)' + fi + if [ "${glob#\*}" != "$glob" ]; then + glob="${glob#\*}" + else + glob='(^|/)'"$glob" + fi + glob="$( printf %s $glob | sed -e 's/\./\\./g;s/\*/[^\/]*/g;s/\?/[^\/]/g' )" + echo "$glob" >>"$file" + esac +} + +writefile () { + comment "begin section $managed_by_etckeeper (do not edit this section by hand)" + nl + + if [ "$VCS" = darcs ]; then + darcs setpref boringfile .darcsignore + fi + + if [ "$LOWLEVEL_PACKAGE_MANAGER" = dpkg ]; then + comment "new and old versions of conffiles, stored by dpkg" + ignore "*.dpkg-*" + nl + elif [ "$LOWLEVEL_PACKAGE_MANAGER" = "rpm" ]; then + comment "new and old versions of conffiles, stored by apt/rpm" + ignore "*.rpm*" + nl + elif [ "$LOWLEVEL_PACKAGE_MANAGER" = "pacman-g2" ]; then + comment "new and old versions of conffiles, stored by pacman" + ignore "*.pacnew" + ignore "*.pacorig" + ignore "*.pacsave" + nl + fi + + comment "mount(8) records system state here, no need to store these" + ignore blkid.tab + ignore blkid.tab.old + nl + + comment "some other files in /etc that typically do not need to be tracked" + ignore nologin + ignore ld.so.cache + ignore mtab + ignore .pwd.lock + ignore network/run + ignore adjtime + ignore lvm/cache + nl + + comment "editor temp files" + ignore "*~" + ignore ".*.sw?" + ignore "#*#" + ignore DEADJOE + + nl + comment "end section $managed_by_etckeeper" +} + +if [ -e "$file" ]; then + if ! grep -q "$managed_by_etckeeper" "$file"; then + echo "etckeeper: "$file" does not contain \"$managed_by_etckeeper\" comment; not updating" + exit 1 + fi + realfile="$file" + file=$(tempfile) + ( + skipping= + while read line; do + if echo "$line" | grep -q "$managed_by_etckeeper"; then + if [ ! "$skipping" ]; then + skipping=1 + else + skipping= + writefile + fi + elif [ ! "$skipping" ]; then + echo "$line" >> "$file" + fi + done + if [ "$skipping" ]; then + # reached end of file w/o ending block + writefile + fi + ) <"$realfile" + + mv -f "$file" "$realfile" +else + writefile +fi diff --git a/update-ignore.d/README b/update-ignore.d/README new file mode 100644 index 0000000..a573135 --- /dev/null +++ b/update-ignore.d/README @@ -0,0 +1,2 @@ +Executable files in this directory are run to update the VCS ignore file, +or create it if it does not exist. |