On 22/05/12 16:25, Joey Hess wrote:
Squared Financial IT wrote:
If you have added entries to .gitignore outside its "managed by
etckeeper" section, they are lost upon uninit, as uninit naively
deletes the whole file. This is in contrast to update-ignore
behaviour, which afaics carefully only munges the "managed by etckeeper"
section. IMHO etckeeper should be more careful upon uninit, and only nuke
the "managed by etckeeper" section rather than the whole file -
at least if the .gitignore has entries outside the managed section.
I agree with this change in principle. If you'd like to develop a patch,
I will probably commit it. The code run by update-ignore could be reused
with slight changes to delete, rather than updating the content.
Right so. Patch attached in "works for us" state - it is now yours to do
with as you will. Thanks!
--
IT Department
Squared Financial Services Limited
www.squaredfinancial.com
Custom House Plaza 2
Harbourmaster Place, IFSC, Dublin 1
Ireland
Switch: + 353 1 661 0500
Direct: + 353 1 662 1930
Fax: + 353 1 661 1087
Squared Financial Services Limited is regulated by the Central Bank of Ireland.
Registered Office: Custom House Plaza 2, Harbourmaster Place, IFSC, Dublin 1,
Ireland. Registered No. 399289.
Directors: Philippe Ghanem (Swiss), Magid Khoury (Swiss), Ronnie Culliton,
Bachir Rabbat (Canadian), Jeff Grossman, Youssef
Barakat (Lebanese).
----------------------------------------------------------------------------------------------------------------------------------
This email (including any attachments) may contain confidential and/or
privileged information. If you are not the intended
recipient (or have received this email by mistake), please notify the sender
and kindly destroy this email. Any unauthorised
copying, disclosure or dissemination of the material in this email in whole or
in part is strictly prohibited. Email transmission
security and error-free status cannot be guaranteed as information could be
intercepted, corrupted, destroyed, delayed,
incomplete, or contain viruses. The sender therefore does not accept liability
for any errors or omissions in the contents of this
message, which may arise as a result of email transmission.
diff --git a/etckeeper.8 b/etckeeper.8
index a49c4b6..6d3ffb2 100644
--- a/etckeeper.8
+++ b/etckeeper.8
@@ -41,10 +41,11 @@ repository. (You can also call this by hand after running dpkg by hand.)
.B unclean
This returns true if the directory contains uncommitted changes.
.TP
-.B update-ignore
+.B update-ignore [-a]
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.
+of etckeeper. (The -a switch will add a "managed by etckeeper" block if
+one is not present.)
.TP
.B vcs subcommand [options ...]
You can use this to run any subcommand of the VCS that etckeeper is
diff --git a/init.d/50vcs-ignore b/init.d/50vcs-ignore
index bcc88ba..33d79d3 100755
--- a/init.d/50vcs-ignore
+++ b/init.d/50vcs-ignore
@@ -1,4 +1,4 @@
#!/bin/sh
set -e
-etckeeper update-ignore || true
+etckeeper update-ignore -a || true
diff --git a/uninit.d/01prompt b/uninit.d/01prompt
index 07f2e41..8b43937 100755
--- a/uninit.d/01prompt
+++ b/uninit.d/01prompt
@@ -3,7 +3,7 @@ set -e
if [ "$1" != "-f" ]; then
echo "** Warning: This will DESTROY all recorded history for $ETCKEEPER_DIR,"
- echo "** including the $VCS repository and ignore file."
+ echo "** including the $VCS repository."
echo ""
printf "Are you sure you want to do this? [yN] "
read answer
diff --git a/uninit.d/50vcs-uninit b/uninit.d/50vcs-uninit
index eb9f13a..165d415 100755
--- a/uninit.d/50vcs-uninit
+++ b/uninit.d/50vcs-uninit
@@ -19,6 +19,38 @@ managed_by_etckeeper="managed by etckeeper"
if ! grep -q "$managed_by_etckeeper" "$file"; then
echo "etckeeper: "$file" does not contain \"$managed_by_etckeeper\" comment; not removing"
+ exit 0
else
- rm -f $file
+ realfile="$file"
+ if [ -n "`type -p tempfile`" ]; then
+ tempfile="tempfile"
+ elif [ -n "`type -p mktemp`" ]; then
+ tempfile="mktemp"
+ else
+ echo "etckeeper warning: can't find tempfile or mktemp" >&2
+ exit 1
+ fi
+ file=$($tempfile)
+ otherentries=
+ skipping=
+ while read line; do
+ if echo "$line" | grep -q "$managed_by_etckeeper"; then
+ if [ ! "$skipping" ]; then
+ skipping=1
+ else
+ skipping=
+ fi
+ elif [ ! "$skipping" ]; then
+ echo "$line" >> "$file"
+ otherentries=1
+ fi
+ done <"$realfile"
+
+ if [ "$otherentries" ]; then
+ echo "etckeeper: "$realfile" nonempty after \"$managed_by_etckeeper\" section removal; preserving other entries"
+ mv -f "$file" "$realfile"
+ else
+ rm -f "$file"
+ rm -f "$realfile"
+ fi
fi
diff --git a/update-ignore.d/01update-ignore b/update-ignore.d/01update-ignore
index b6acf17..8cf524a 100755
--- a/update-ignore.d/01update-ignore
+++ b/update-ignore.d/01update-ignore
@@ -160,8 +160,14 @@ writefile () {
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
+ if [ "$1" != "-a" ]; then
+ echo "etckeeper: "$file" does not contain \"$managed_by_etckeeper\" comment; not updating"
+ exit 1
+ else
+ echo "etckeeper: "$file" exists but does not contain \"$managed_by_etckeeper\" comment; updating"
+ writefile
+ exit 0
+ fi
fi
realfile="$file"
if [ -n "`type -p tempfile`" ]; then