Commit 10ea00e8 authored by Ben Boeckel's avatar Ben Boeckel

git-check-third-party: add tool for getting the root commit of an import

This tool can be used on an import to discover the imported project's
root commit. It also sanity checks the status of the import to make sure
that it adheres to the process.
parent 4908a743
. git-sh-setup
set -e
readonly directory="$1"
if ! [ -d "$directory" ]; then
die "fatal: not a directory"
readonly last_import_merge="$( git rev-list --max-count=1 HEAD -- "$directory" )"
if [ -z "$last_import_merge" ]; then
die "fatal: not tracked by git"
if ! git rev-parse "$last_import_merge^2" >/dev/null 2>/dev/null; then
die "fatal: not imported via a merge commit"
readonly last_imported_commit="$( git rev-parse "$last_import_merge^2" )"
if [ -z "$last_imported_commit" ]; then
die "fatal: not modified via a merge commit"
readonly main_root="$( git rev-list --max-count=1 --first-parent --max-parents=0 HEAD )"
readonly import_root="$( git rev-list --max-count=1 --first-parent --max-parents=0 "$last_imported_commit" )"
if [ "$main_root" = "$import_root" ]; then
die "fatal: not imported via a separate branch"
readonly last_imported_tree="$( git rev-parse "$last_imported_commit^{tree}" )"
readonly current_tree="$( git ls-tree HEAD -- "$directory" | tr $'\t' ' ' | cut '-d ' -f3 )"
if ! [ "$current_tree" = "$last_imported_tree" ]; then
git diff "$last_imported_tree" "$current_tree"
die "fatal: import has been modified"
echo "root commit: $import_root"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment