Skip to content

Commit 5d1c495

Browse files
authored
expand on undiverged branches (#2072)
1 parent 52e966e commit 5d1c495

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

docs/ce/howto/apply-requirements.mdx

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,59 @@ workflows:
2626
on_pull_request_closed: ["digger unlock"]
2727
on_commit_to_default: ["digger unlock"]
2828
skip_merge_check: true
29-
```
29+
```
30+
31+
## Requiring undiverged branches in PRs
32+
33+
While PR locks prevent you from PRs stepping on eachother in parallel, they still do not protect you from a stale branch
34+
that is behind the current main head. In order to safeguard against this you have a few options:
35+
36+
Force your repo to always have rebased branches from main. In github this is done by adding the branch protection rule:
37+
38+
Under settings > branch protection rules > Require branches to be up to date before merging → check this
39+
40+
Since digger will always query github api for mergability status, this protects you from any stale apply from PRs being performed.
41+
42+
![](/images/howto/force-refactor-into-main.png)
43+
44+
Understandably this may not be feasible to mark especially for monorepos that mix code and terraform. In such cases you can achieve a similar effect by using a custom workflow like below (digger.yml):
45+
46+
```
47+
projects:
48+
- name: gcp-infra
49+
dir: cloud/terraform/gcp
50+
workflow: terraform-strict
51+
52+
workflows:
53+
terraform-strict:
54+
plan:
55+
steps:
56+
- run: |
57+
echo "Checking if branch is up-to-date with main..."
58+
git fetch --unshallow origin main || git fetch origin main
59+
git fetch --unshallow origin HEAD || git fetch origin HEAD
60+
if ! git merge-base --is-ancestor origin/main HEAD; then
61+
echo "❌ Branch is not up-to-date with main. Please rebase or merge main into your branch."
62+
echo "Run: git fetch origin && git rebase origin/main"
63+
exit 1
64+
fi
65+
echo "✅ Branch is up-to-date with main"
66+
- init
67+
- plan
68+
apply:
69+
steps:
70+
- run: |
71+
echo "Checking if branch is up-to-date with main..."
72+
git fetch --unshallow origin main || git fetch origin main
73+
git fetch --unshallow origin HEAD || git fetch origin HEAD
74+
if ! git merge-base --is-ancestor origin/main HEAD; then
75+
echo "❌ Branch is not up-to-date with main. Please rebase or merge main into your branch."
76+
echo "Run: git fetch origin && git rebase origin/main"
77+
exit 1
78+
fi
79+
echo "✅ Branch is up-to-date with main"
80+
- init
81+
- apply
82+
```
83+
84+
We plan to eventually support this natively as a flag in digger
101 KB
Loading

0 commit comments

Comments
 (0)