Commit 3a5598e3 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Fix .gitlab-ci-pre_commit_run.bash based on unit tests

parent 5f87167a
Loading
Loading
Loading
Loading
Loading
+12 −8
Original line number Diff line number Diff line
@@ -24,24 +24,28 @@ pre_commit_run() (
		local repo=$CI_REPOSITORY_URL current_branch=$CI_COMMIT_BRANCH
		local other_branch=$1

		git fetch $repo --shallow-exclude=$other_branch $current_branch
		git fetch $repo --shallow-exclude=$current_branch $other_branch:refs/other
		git repack -d
		git fetch $repo --deepen=1 $current_branch
		git fetch -q $repo --shallow-exclude=$other_branch $current_branch
		git fetch -q $repo --shallow-exclude=$current_branch $other_branch:refs/other
		git repack -qd
		git fetch -q $repo --deepen=1 $current_branch

		FROM_REF=$(git merge-base $current_branch refs/other)
		FROM_REF=$(git merge-base $current_branch refs/other) || unset FROM_REF
	}

	fetch_ref() {
		git fetch -q $CI_REPOSITORY_URL --depth=1 $1
		FROM_REF=$1
	}

	if [[ ! $CI_COMMIT_BEFORE_SHA =~ ^0{40}$ ]]; then
		find_lca $CI_COMMIT_BEFORE_SHA
	if [[ -v CI_COMMIT_BEFORE_SHA ]] && [[ ! $CI_COMMIT_BEFORE_SHA =~ ^0{40}$ ]]; then
		fetch_ref $CI_COMMIT_BEFORE_SHA
	elif [[ -v CI_MERGE_REQUEST_TARGET_BRANCH_NAME ]]; then
		find_lca $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
	elif [[ $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH ]]; then
		find_lca $CI_DEFAULT_BRANCH
	fi

	if [[ -n "$FROM_REF" ]]; then
	if [[ -v FROM_REF ]]; then
		PRE_COMMIT_ARGS=( --from-ref=$FROM_REF --to-ref=$CI_COMMIT_SHA )
	else
		PRE_COMMIT_ARGS=( --all-files )