@@ -9,10 +9,12 @@ PREVIOUS_SHA=""
9
9
CURRENT_SHA=" "
10
10
DIFF=" ..."
11
11
IS_TAG=" false"
12
+ SOURCE_BRANCH=" "
12
13
13
14
if [[ " $GITHUB_REF " == " refs/tags/" * ]]; then
14
15
IS_TAG=" true"
15
16
EXTRA_ARGS=" --prune --no-recurse-submodules"
17
+ SOURCE_BRANCH=${GITHUB_EVENT_BASE_REF# refs/ heads/ }
16
18
fi
17
19
18
20
if [[ -z $GITHUB_EVENT_PULL_REQUEST_BASE_REF || " $GITHUB_EVENT_HEAD_REPO_FORK " == " true" ]]; then
52
54
echo " Valid git version found: ($GIT_VERSION )"
53
55
fi
54
56
57
+ IS_SHALLOW=$( git rev-parse --is-shallow-repository) && exit_status=$? || exit_status=$?
58
+
59
+ if [[ $exit_status -ne 0 ]]; then
60
+ echo " ::error::Unable to determine if the repository is shallow"
61
+ exit 1
62
+ fi
63
+
55
64
if [[ -z $GITHUB_EVENT_PULL_REQUEST_BASE_REF ]]; then
56
65
echo " Running on a push event..."
57
66
TARGET_BRANCH=$GITHUB_REFNAME
58
67
CURRENT_BRANCH=$TARGET_BRANCH
59
68
60
- if $( git rev-parse --is-shallow-repository ) ; then
69
+ if [[ " $IS_SHALLOW " == " true " ]] ; then
61
70
echo " Fetching remote refs..."
62
- # shellcheck disable=SC2086
63
- git fetch $EXTRA_ARGS -u --progress --deepen=" $INPUT_FETCH_DEPTH " origin +refs/heads/" $CURRENT_BRANCH " :refs/remotes/origin/" $CURRENT_BRANCH " 1> /dev/null
71
+ if [[ " $IS_TAG " == " false" ]]; then
72
+ # shellcheck disable=SC2086
73
+ git fetch $EXTRA_ARGS -u --progress --deepen=" $INPUT_FETCH_DEPTH " origin +refs/heads/" $CURRENT_BRANCH " :refs/remotes/origin/" $CURRENT_BRANCH " 1> /dev/null
74
+ elif [[ " $SOURCE_BRANCH " != " " ]]; then
75
+ # shellcheck disable=SC2086
76
+ git fetch $EXTRA_ARGS -u --progress --deepen=" $INPUT_FETCH_DEPTH " origin +refs/heads/" $SOURCE_BRANCH " :refs/remotes/origin/" $SOURCE_BRANCH " 1> /dev/null
77
+ fi
64
78
# shellcheck disable=SC2086
65
79
git submodule foreach git fetch $EXTRA_ARGS -u --progress --deepen=" $INPUT_FETCH_DEPTH " || true
66
80
fi
@@ -102,6 +116,13 @@ if [[ -z $GITHUB_EVENT_PULL_REQUEST_BASE_REF ]]; then
102
116
echo " ::error::Unable to locate a previous commit for the specified date: $INPUT_SINCE "
103
117
exit 1
104
118
fi
119
+ elif [[ " $IS_TAG " == " true" ]]; then
120
+ PREVIOUS_SHA=$( git rev-parse " $( git tag --sort=-v:refname | head -n 2 | tail -n 1) " ) && exit_status=$? || exit_status=$?
121
+
122
+ if [[ -z " $PREVIOUS_SHA " ]]; then
123
+ echo " ::error::Unable to locate a previous commit for the specified tag: $GITHUB_REF "
124
+ exit 1
125
+ fi
105
126
else
106
127
if [[ " $INPUT_SINCE_LAST_REMOTE_COMMIT " == " true" ]]; then
107
128
PREVIOUS_SHA=" "
162
183
TARGET_BRANCH=$CURRENT_BRANCH
163
184
fi
164
185
165
- if $( git rev-parse --is-shallow-repository ) ; then
186
+ if [[ " $IS_SHALLOW " == " true " ]] ; then
166
187
echo " Fetching remote refs..."
167
188
# shellcheck disable=SC2086
168
189
git fetch $EXTRA_ARGS -u --progress origin pull/" $GITHUB_EVENT_PULL_REQUEST_NUMBER " /head:" $CURRENT_BRANCH " 1> /dev/null
213
234
else
214
235
PREVIOUS_SHA=$( git rev-parse origin/" $TARGET_BRANCH " ) && exit_status=$? || exit_status=$?
215
236
216
- if $( git rev-parse --is-shallow-repository ) ; then
237
+ if [[ " $IS_SHALLOW " == " true " ]] ; then
217
238
# check if the merge base is in the local history
218
239
if ! git merge-base " $PREVIOUS_SHA " " $CURRENT_SHA " 1> /dev/null 2>&1 ; then
219
240
echo " ::debug::Merge base is not in the local history, fetching remote target branch..."
0 commit comments