summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Sima <bsima@groq.com>2021-12-16 10:10:45 -0800
committerBen Sima <bsima@groq.com>2022-02-09 14:10:46 -0800
commitd04b76c322803528e017e696ff9350c7e160dcdc (patch)
treed95ff85dc76e13edaca85f33f29f92e9d83555e7
parent77501fc15ae6995564b24405657a69f22d60fcfd (diff)
add git watchlist
-rwxr-xr-xgit-watchlist35
1 files changed, 35 insertions, 0 deletions
diff --git a/git-watchlist b/git-watchlist
new file mode 100755
index 0000000..6cd15b5
--- /dev/null
+++ b/git-watchlist
@@ -0,0 +1,35 @@
+#!/usr/bin/env ruby
+#
+# git watchlist - report changes in certain files only
+#
+# To use this, create a file `.git/watchlist' which is simply a list of files
+# that you want to monitor, one file per line. Populate it with `fd' or `find'
+# or `git ls-files | grep'. Then, `git watchlist <range>' can be used to get a
+# changelog for only those files you care about.
+#
+# This is very useful in a post-checkout script, so you can quickly see what
+# changed in the files you care about every time you pull from upstream.
+
+require 'optparse'
+
+gitdir = `git rev-parse --git-common-dir`.chomp
+watchlist = File.readlines(gitdir+"/watchlist").map(&:chomp).join(' ')
+opts = {}
+
+OptionParser.new do |opt|
+ opt.banner = "usage: git watchlist [--short|--stat] <range>"
+ opt.on('--short') do
+ opts[:short] = true
+ end
+ opt.on('--stat') do
+ opts[:stat] = true
+ end
+end.parse!
+
+if opts[:short]
+ puts `git shortlog --no-merges #{ARGV[0]} -- #{watchlist}`
+elsif opts[:stat]
+ puts `git log --stat --color=always --no-merges #{ARGV[0]} -- #{watchlist}`
+else
+ puts `git log --color=always --no-merges #{ARGV[0]} -- #{watchlist}`
+end