summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar David Alexander <opensource@thelonelyghost.com>2016-11-11 02:46:00 -0500
committerGravatar Mike Burns <mike@mike-burns.com>2016-11-12 16:19:13 -0500
commitbc0d5b63f6c4762b7d39fb32b525f977015ff4b3 (patch)
tree004ed26a2af69caf3985e0415a84660d9f067136
parentee6318598939ec0e1c147430bb2cac036a90f754 (diff)
Run hooks in a defined order
Run the hooks in alphabetical order so that people can more predictably manage their hooks. While here, clean up the NEWS.md.in.
-rw-r--r--.mailmap1
-rw-r--r--Makefile.am4
-rw-r--r--NEWS.md.in11
-rw-r--r--man/rcdn.110
-rw-r--r--man/rcup.19
-rw-r--r--share/rcm.sh.in6
-rw-r--r--test/rcdn-hooks-run-in-order.t37
-rw-r--r--test/rcup-hooks-run-in-order.t37
8 files changed, 110 insertions, 5 deletions
diff --git a/.mailmap b/.mailmap
index 49fcdc4..bc80742 100644
--- a/.mailmap
+++ b/.mailmap
@@ -6,3 +6,4 @@ Mike Burns <mburns@thoughtbot.com> <mike@mike-burns.com>
Pablo Olmos de Aguilera Corradini <pablo@glatelier.org>
Patrick Brisbin <pat@thoughtbot.com> <pbrisbin@gmail.com>
Martin Frost <frost@ceri.se> <martin@frost.ws>
+David Alexander <davidpaulalexander@gmail.com> <opensource@thelonelyghost.com>
diff --git a/Makefile.am b/Makefile.am
index ed8ea2a..fd760ad 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -39,8 +39,10 @@ TESTS = \
test/rcup-usage.t \
test/rcdn-hooks.t \
test/rcdn-hooks-run-in-situ.t \
+ test/rcdn-hooks-run-in-order.t \
test/rcup-hooks.t \
- test/rcup-hooks-run-in-situ.t
+ test/rcup-hooks-run-in-situ.t \
+ test/rcup-hooks-run-in-order.t
dist_check_SCRIPTS = $(TESTS)
dist_check_DATA = test/helper.sh
diff --git a/NEWS.md.in b/NEWS.md.in
index 0cdc0aa..d4b9996 100644
--- a/NEWS.md.in
+++ b/NEWS.md.in
@@ -1,5 +1,16 @@
rcm (@PACKAGE_VERSION@) unstable; urgency=low
+ * BUGFIX: Use $LOGNAME instead of $USER for compatibility (Mike Burns).
+ * BUGFIX: rcdn(1) stops at DEST_DIR (Kyle Cook, Mike Burns).
+ * BUGFIX: Symlink existing files, even when identical (Graham Bennett).
+ * BUGFIX: Sort hooks by filename before execution instead of arbitrary order
+ (David Alexander).
+ * Documentation improvements (Nick Novitski, Ben Stephens, Casey Rodarmor).
+
+ -- Mike Burns <mburns@thoughtbot.com> Sat, 12 Nov 2016 16:16:00 -0500
+
+rcm (1.3.0) unstable; urgency=low
+
* BUGFIX: Control whether hooks should run in rcdn(1) with the -K and -k
flags (Ben Turrubiates, Christopher Koch, Mike Burns, Mikkel Fahnøe
Jørgensen).
diff --git a/man/rcdn.1 b/man/rcdn.1
index fabd9a3..df83e60 100644
--- a/man/rcdn.1
+++ b/man/rcdn.1
@@ -47,7 +47,15 @@ and
These hooks are run each time
.Nm
is run and therefore must be idempotent.
-.
+.Pp
+Hooks will be executed one at a time, sorted alphabetically. For instance,
+.Pa hooks/pre-down/animals
+will run before
+.Pa hooks/pre-down/aquariums ,
+and
+.Pa hooks/pre-down/4-eyes
+will run before
+.Pa hooks/post-down/2-u-nothing-compares .
.Bl -tag -width "-I EXCL_PAT"
.It Fl B Ar HOSTNAME
treat
diff --git a/man/rcup.1 b/man/rcup.1
index 2498125..f4fb89e 100644
--- a/man/rcup.1
+++ b/man/rcup.1
@@ -183,6 +183,15 @@ and
These files must be executable. They are run every time
.Nm
is run, and therefore must be idempotent.
+.Pp
+Hooks will be executed one at a time, sorted alphabetically. For instance,
+.Pa hooks/pre-up/animals
+will run before
+.Pa hooks/pre-up/aquariums ,
+and
+.Pa hooks/pre-up/4-eyes
+will run before
+.Pa hooks/post-up/2-u-nothing-compares .
.Sh ALGORITHM
It is instructive to understand the process
.Nm rcup
diff --git a/share/rcm.sh.in b/share/rcm.sh.in
index ed5d6f9..f0d3364 100644
--- a/share/rcm.sh.in
+++ b/share/rcm.sh.in
@@ -131,9 +131,9 @@ run_hooks() {
# running these hooks imply some level of trust; surely one doesn't clone somebody
# else's dotfiles repository without reviewing the hooks before doing an `rcup`?
find "$hook_file" -type f \( \( -user $LOGNAME -perm -100 \) -o -perm -001 \) \
- -exec \
- sh -c 'cd "`dirname $1`" && ./"`basename $1`"' arg0 '{}' \
- \;
+ | sort | while read file; do
+ sh -c 'cd "`dirname $1`" && ./"`basename $1`"' arg0 "$file"
+ done
else
$DEBUG "no $when-$direction hook present for $dotfiles_dir, skipping"
fi
diff --git a/test/rcdn-hooks-run-in-order.t b/test/rcdn-hooks-run-in-order.t
new file mode 100644
index 0000000..8dff253
--- /dev/null
+++ b/test/rcdn-hooks-run-in-order.t
@@ -0,0 +1,37 @@
+ $ . "$TESTDIR/helper.sh"
+
+Pre-down and post-down hooks should run in order according to their name
+
+ $ mkdir -p .dotfiles/hooks/pre-down .dotfiles/hooks/post-down
+ > printf "#!/bin/sh\necho '1'\n" > .dotfiles/hooks/pre-down/00-test.sh
+ > printf "#!/bin/sh\necho '2'\n" > .dotfiles/hooks/pre-down/01-test.sh
+ > printf "#!/bin/sh\necho '3'\n" > .dotfiles/hooks/pre-down/02-test.sh
+ > printf "#!/bin/sh\necho '4'\n" > .dotfiles/hooks/post-down/00-test.sh
+ > printf "#!/bin/sh\necho '5'\n" > .dotfiles/hooks/post-down/01-test.sh
+ > printf "#!/bin/sh\necho '6'\n" > .dotfiles/hooks/post-down/02-test.sh
+
+ $ chmod +x .dotfiles/hooks/pre-down/00-test.sh
+ > chmod +x .dotfiles/hooks/pre-down/01-test.sh
+ > chmod +x .dotfiles/hooks/pre-down/02-test.sh
+ > chmod +x .dotfiles/hooks/post-down/00-test.sh
+ > chmod +x .dotfiles/hooks/post-down/01-test.sh
+ > chmod +x .dotfiles/hooks/post-down/02-test.sh
+
+ $ rcdn
+ 1
+ 2
+ 3
+ 4
+ 5
+ 6
+
+
+Ensure that hooks run when output of lsrc is non-empty
+ $ touch .dotfiles/testrc
+ > rcdn
+ 1
+ 2
+ 3
+ 4
+ 5
+ 6
diff --git a/test/rcup-hooks-run-in-order.t b/test/rcup-hooks-run-in-order.t
new file mode 100644
index 0000000..cc5b402
--- /dev/null
+++ b/test/rcup-hooks-run-in-order.t
@@ -0,0 +1,37 @@
+ $ . "$TESTDIR/helper.sh"
+
+Pre-up hooks should run in order according to their name
+
+ $ mkdir -p .dotfiles/hooks/pre-up .dotfiles/hooks/post-up
+ > printf "#!/bin/sh\necho '1'\n" > .dotfiles/hooks/pre-up/00-test.sh
+ > printf "#!/bin/sh\necho '2'\n" > .dotfiles/hooks/pre-up/01-test.sh
+ > printf "#!/bin/sh\necho '3'\n" > .dotfiles/hooks/pre-up/02-test.sh
+ > printf "#!/bin/sh\necho '4'\n" > .dotfiles/hooks/post-up/00-test.sh
+ > printf "#!/bin/sh\necho '5'\n" > .dotfiles/hooks/post-up/01-test.sh
+ > printf "#!/bin/sh\necho '6'\n" > .dotfiles/hooks/post-up/02-test.sh
+
+ $ chmod +x .dotfiles/hooks/pre-up/00-test.sh
+ > chmod +x .dotfiles/hooks/pre-up/01-test.sh
+ > chmod +x .dotfiles/hooks/pre-up/02-test.sh
+ > chmod +x .dotfiles/hooks/post-up/00-test.sh
+ > chmod +x .dotfiles/hooks/post-up/01-test.sh
+ > chmod +x .dotfiles/hooks/post-up/02-test.sh
+
+ $ rcup
+ 1
+ 2
+ 3
+ 4
+ 5
+ 6
+
+
+Ensure that hooks run when output of lsrc is non-empty
+ $ touch .dotfiles/testrc
+ > rcup
+ 1
+ 2
+ 3
+ 4
+ 5
+ 6