Skip to content

Instantly share code, notes, and snippets.

@jacks0n
Last active April 13, 2017 00:00
Show Gist options
  • Save jacks0n/1c9a964fc1d7e3a145a7f08b19db22e7 to your computer and use it in GitHub Desktop.
Save jacks0n/1c9a964fc1d7e3a145a7f08b19db22e7 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# vim: filetype=sh
REPO_1="$(readlink -f "${1:-$(pwd)}")"
REPO_2="$(readlink -f "$2")"
quit() {
echo "quit_with_error()"
echo "ERROR: $@" >&2
exit 1
}
dump_git_files() {
cd "$1"
local GIT_FILE_LIST="$(mktemp)"
git ls-files > "$GIT_FILE_LIST"
echo "$GIT_FILE_LIST"
}
check_git_repo_path() {
cd "$1" 2>/dev/null || {
quit "'$1' directory does not exist!"
}
git rev-parse --git-dir &>/dev/null || {
quit "'$1' is not a Git repository!"
}
}
diff_repo_files() {
check_git_repo_path "$1"
check_git_repo_path "$2"
local REPO_1_FILE_LIST="$(dump_git_files "$1")"
local REPO_2_FILE_LIST="$(dump_git_files "$2")"
comm -12 "$REPO_1_FILE_LIST" "$REPO_2_FILE_LIST" | while read REPO_FILE ; do
if ! cmp -s "$REPO_1/$REPO_FILE" "$REPO_2/$REPO_FILE" ; then
echo "$REPO_FILE"
fi
done
rm "$REPO_1_FILE_LIST"
rm "$REPO_2_FILE_LIST"
}
if [[ -z "$REPO_1" || -z "$REPO_2" ]] ; then
quit 'Missing argument!'
fi
diff_repo_files "$REPO_1" "$REPO_2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment