Skip to content

Commit

Permalink
Merge pull request #490 from tj-actions/fix/usage-of-fork-point
Browse files Browse the repository at this point in the history
  • Loading branch information
jackton1 committed May 15, 2022
2 parents f0da059 + 9e1cda0 commit 581eef0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 25 deletions.
29 changes: 6 additions & 23 deletions diff-sha.sh
Expand Up @@ -15,21 +15,6 @@ if [[ -n $INPUT_PATH ]]; then
cd "$REPO_DIR"
fi

SERVER_URL=$(echo "$GITHUB_SERVER_URL" | awk -F/ '{print $3}')

echo "Setting up 'temp_changed_files' remote..."

git ls-remote --exit-code temp_changed_files 1>/dev/null 2>&1 && exit_status=$? || exit_status=$?

if [[ $exit_status -ne 0 ]]; then
echo "No 'temp_changed_files' remote found"
echo "Creating 'temp_changed_files' remote..."
git remote remove temp_changed_files 2>/dev/null || true
git remote add temp_changed_files "https://${INPUT_TOKEN}@${SERVER_URL}/${GITHUB_REPOSITORY}"
else
echo "Found 'temp_changed_files' remote"
fi

echo "Getting HEAD SHA..."

if [[ -z $INPUT_SHA ]]; then
Expand All @@ -43,7 +28,6 @@ git rev-parse --quiet --verify "$CURRENT_SHA^{commit}" 1>/dev/null 2>&1 && exit_
if [[ $exit_status -ne 0 ]]; then
echo "::warning::Unable to locate the current sha: $CURRENT_SHA"
echo "::warning::You seem to be missing 'fetch-depth: 0' or 'fetch-depth: 2'. See https://github.com/tj-actions/changed-files#usage"
git remote remove temp_changed_files
exit 1
fi

Expand All @@ -52,7 +36,8 @@ if [[ -z $GITHUB_BASE_REF ]]; then
CURRENT_BRANCH=$TARGET_BRANCH

if [[ -z $INPUT_BASE_SHA ]]; then
git fetch --no-tags -u --progress --depth=2 temp_changed_files "${CURRENT_BRANCH}":"${CURRENT_BRANCH}" && exit_status=$? || exit_status=$?
git fetch --no-tags -u --progress --depth=2 origin "${CURRENT_BRANCH}":"${CURRENT_BRANCH}" &&
exit_status=$? || exit_status=$?

if [[ $(git rev-list --count HEAD) -gt 1 ]]; then
PREVIOUS_SHA=$(git rev-list --no-merges -n 1 HEAD^1 2>&1) && exit_status=$? || exit_status=$?
Expand All @@ -70,7 +55,6 @@ if [[ -z $GITHUB_BASE_REF ]]; then
if [[ $exit_status -ne 0 ]]; then
echo "::warning::Unable to locate the previous sha: $PREVIOUS_SHA"
echo "::warning::You seem to be missing 'fetch-depth: 0' or 'fetch-depth: 2'. See https://github.com/tj-actions/changed-files#usage"
git remote remove temp_changed_files
exit 1
fi
else
Expand All @@ -80,14 +64,14 @@ else
if [[ -z $INPUT_BASE_SHA ]]; then
if [[ "$INPUT_USE_FORK_POINT" == "true" ]]; then
echo "Getting fork point..."
git fetch --no-tags -u --progress temp_changed_files "${TARGET_BRANCH}":"${TARGET_BRANCH}" && exit_status=$? || exit_status=$?
PREVIOUS_SHA=$(git merge-base --fork-point "temp_changed_files/${TARGET_BRANCH}") && exit_status=$? || exit_status=$?
git fetch --no-tags -u --progress origin "${TARGET_BRANCH}":"${TARGET_BRANCH}" && exit_status=$? || exit_status=$?
PREVIOUS_SHA=$(git merge-base --fork-point "${TARGET_BRANCH}" "$(git name-rev --name-only "$CURRENT_SHA")") && exit_status=$? || exit_status=$?
else
git fetch --no-tags -u --progress --depth=1 temp_changed_files "${TARGET_BRANCH}":"${TARGET_BRANCH}" && exit_status=$? || exit_status=$?
git fetch --no-tags -u --progress origin --depth=1 "${TARGET_BRANCH}":"${TARGET_BRANCH}" && exit_status=$? || exit_status=$?
PREVIOUS_SHA=$(git rev-list --no-merges -n 1 "${TARGET_BRANCH}" 2>&1) && exit_status=$? || exit_status=$?
fi
else
git fetch --no-tags -u --progress --depth=1 temp_changed_files "$INPUT_BASE_SHA" && exit_status=$? || exit_status=$?
git fetch --no-tags -u --progress origin --depth=1 "$INPUT_BASE_SHA" && exit_status=$? || exit_status=$?
PREVIOUS_SHA=$INPUT_BASE_SHA
TARGET_BRANCH=$(git name-rev --name-only "$PREVIOUS_SHA" 2>&1) && exit_status=$? || exit_status=$?
fi
Expand All @@ -98,7 +82,6 @@ else
if [[ $exit_status -ne 0 ]]; then
echo "::warning::Unable to locate the previous sha: $PREVIOUS_SHA"
echo "::warning::You seem to be missing 'fetch-depth: 0' or 'fetch-depth: 2'. See https://github.com/tj-actions/changed-files#usage"
git remote remove temp_changed_files
exit 1
fi
fi
Expand Down
2 changes: 0 additions & 2 deletions entrypoint.sh
Expand Up @@ -196,8 +196,6 @@ else
ALL_MODIFIED=$(echo "${ALL_MODIFIED}" | awk '{gsub(/\|/,"\n"); print $0;}' | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
fi

git remote remove temp_changed_files

echo "Added files: $ADDED"
echo "Copied files: $COPIED"
echo "Deleted files: $DELETED"
Expand Down

0 comments on commit 581eef0

Please sign in to comment.