Skip to content

Instantly share code, notes, and snippets.

@s4parke
Created October 14, 2015 14:52
Show Gist options
  • Save s4parke/84e834e028f027b90028 to your computer and use it in GitHub Desktop.
Save s4parke/84e834e028f027b90028 to your computer and use it in GitHub Desktop.
#! /usr/bin/ruby
# Git before-update hook
def check_uncommitted_changes
diff_paths = `git diff-index --name-only HEAD`.split("\n")
diff_stats = `git diff-index --stat HEAD`.split("\n").join("\n ")
error_msg = %(
[GIT POLICY: DIRTY WORKING COPY]
There are uncommitted changes in server's working copy. Please commit or stash them.
#{diff_stats}
)
puts error_msg
unless diff_paths.nil? || diff_paths.empty?
puts error_msg
exit 1
end
end
check_uncommitted_changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment