Skip to content

Instantly share code, notes, and snippets.

@veloce
Created November 20, 2011 23:20
Show Gist options
  • Save veloce/1381140 to your computer and use it in GitHub Desktop.
Save veloce/1381140 to your computer and use it in GitHub Desktop.
post-merge hook to manage "dist" config files
#!/usr/bin/env sh
# File extension to check for changes
OBSERVE='dist'
# check if user configured mergetool
mergetool=`git config --get merge.tool`
if [[ -n "$mergetool" ]]; then
PROG=$mergetool
else
PROG='vimdiff'
fi
# get a list of files changed by the merge
changes=`git diff --name-only HEAD@{1} HEAD`
do_diff()
{
distfile=$1
configfile=${distfile%.*}
echo "$1 has changed since the merge. Open the diff? (y n q) "
while true; do
read action
case $action in
y)
$PROG $distfile $configfile
return
;;
n)
return
;;
q)
exit 0
;;
*)
echo "Unknown action"
;;
esac
done
}
for line in $changes
do
filename=$(basename "$line")
extension=${filename##*.}
if [[ "$extension" == "$OBSERVE" ]]; then
do_diff $line
fi
done
exit 0
@docteurklein
Copy link

je like

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment