aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2017-06-19 14:04:47 +0900
committerKazuki Yamaguchi <k@rhe.jp>2017-06-19 14:04:47 +0900
commit8a078146a3e56031151c686adcc566d2a3ba7e48 (patch)
tree5141fa95dc06f35011c00d1a4281b884be7d09d3
parent27167b1fd7d098f453f1460221d972dea43c59ae (diff)
downloadgit-test-8a078146a3e56031151c686adcc566d2a3ba7e48.tar.gz
Ensure the working tree isn't used by another instance
Make a locking file at $GIT_DIR/git-test/current.lock.
-rwxr-xr-xgit-test11
1 files changed, 9 insertions, 2 deletions
diff --git a/git-test b/git-test
index 0652ede..ed50dd1 100755
--- a/git-test
+++ b/git-test
@@ -115,12 +115,14 @@ OptionParser.new { |o|
die("too many arguments") if ARGV.size > 1
range = ARGV.shift || "master..HEAD"
+git_test_dir = File.join(sh("git", "rev-parse", "--git-dir").chomp, "git-test")
+FileUtils.mkdir_p(git_test_dir)
+
# Read from git-config
opts[:test] ||= config_multi("git-test.test") or
die("no test commands given")
opts[:checkout] ||= (
- config("git-test.checkout") ||
- File.join(sh("git", "rev-parse", "--git-dir").chomp, "git-test", "current")
+ config("git-test.checkout") || File.join(git_test_dir, "current")
)
# Check the commit range
@@ -139,6 +141,11 @@ puts color(:green, "Commits to test (in order):")
sh("git", "log", "--reverse", "--oneline", "--decorate", "--color", range,
quiet: false)
+# Acquire the lock; let Ruby unlock on exit
+lockfile = File.open(File.join(git_test_dir, "current.lock"), "w")
+lockfile.flock(File::LOCK_EX | File::LOCK_NB) or
+ die("could not acquire lock for #{lockfile.path}")
+
# Prepare the working tree
puts color(:green, "Preparing a working tree at #{opts[:checkout]}...")
unless opts[:dry_run]