File tree Expand file tree Collapse file tree 1 file changed +55
-0
lines changed
Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Original file line number Diff line number Diff line change 1+ name : mergebase
2+
3+ on :
4+ push :
5+
6+ jobs :
7+ get_merge_base :
8+ runs-on : ubuntu-latest
9+ env :
10+ UPSTREAM_REMOTE : torvalds
11+ UPSTREAM_URL : https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
12+ UPSTREAM_BRANCH : master
13+ FETCH_STEP : 100
14+ FETCH_MAX : 2000
15+
16+ steps :
17+ - name : Checkout
18+ uses : actions/checkout@v4
19+ with :
20+ fetch-depth : 200
21+
22+ - name : Add upstream remote (torvalds)
23+ run : |
24+ git remote add $UPSTREAM_REMOTE $UPSTREAM_URL 2>/dev/null || true
25+
26+ - name : Find upstream merge-base (torvalds/master)
27+ run : |
28+ set -e
29+
30+ DEPTH=$FETCH_STEP
31+
32+ # get Upstream initial flat
33+ git fetch $UPSTREAM_REMOTE $UPSTREAM_BRANCH --depth=$DEPTH
34+
35+ while true; do
36+ BASE=$(git merge-base HEAD FETCH_HEAD || true)
37+
38+ if [ -n "$BASE" ]; then
39+ echo "Found merge-base: $BASE"
40+ echo "BASE=$BASE" >> $GITHUB_ENV
41+ break
42+ fi
43+
44+ if [ $DEPTH -ge $FETCH_MAX ]; then
45+ echo "Fallback to full fetch..."
46+ git fetch $UPSTREAM_REMOTE $UPSTREAM_BRANCH --unshallow
47+ BASE=$(git merge-base HEAD FETCH_HEAD)
48+ echo "BASE=$BASE" >> $GITHUB_ENV
49+ break
50+ fi
51+
52+ echo "No base yet till $DEPTH, deepening by $FETCH_STEP..."
53+ git fetch $UPSTREAM_REMOTE $UPSTREAM_BRANCH --deepen=$FETCH_STEP
54+ DEPTH=$((DEPTH + FETCH_STEP))
55+ done
You can’t perform that action at this time.
0 commit comments