Skip to content

Commit 38d738d

Browse files
authored
fix(repo init): validate trunk branch is local (#749)
Add validation to ensure that the trunk branch specified with --trunk is a local branch rather than a remote reference. When a non-local branch is specified, show a error message and fail. Resolves #734
1 parent 5c6a9de commit 38d738d

File tree

9 files changed

+44
-20
lines changed

9 files changed

+44
-20
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
kind: Fixed
2+
body: repo init now validates that the trunk branch is a local branch
3+
time: 2025-07-13T18:46:07.569257-07:00

.github/workflows/autofix.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ jobs:
1515
- uses: actions/checkout@v4
1616
name: Check out repository
1717
- uses: jdx/mise-action@v2
18-
env:
19-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18+
with:
19+
github_token: ${{ secrets.GITHUB_TOKEN }}
2020
- name: Go cache
2121
uses: ./.github/actions/go-cache
22-
- run: |
23-
mise run generate
22+
- run: mise run generate
2423
- uses: autofix-ci/action@635ffb0c9798bd160680f18fd73371e355b85f27
2524
with:
2625
fail-fast: true

.github/workflows/changelog-merge.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ jobs:
2626
token: ${{ secrets.PAT }} # for push
2727

2828
- uses: jdx/mise-action@v2
29-
env:
30-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
with:
30+
github_token: ${{ secrets.GITHUB_TOKEN }}
3131
- run: changie merge
3232

3333
- name: Push changes

.github/workflows/ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ jobs:
2020
- uses: actions/checkout@v4
2121
name: Check out repository
2222
- uses: jdx/mise-action@v2
23-
env:
24-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23+
with:
24+
github_token: ${{ secrets.GITHUB_TOKEN }}
2525
- run: mise run lint
2626

2727
test-matrix:
@@ -31,8 +31,8 @@ jobs:
3131
- uses: actions/checkout@v4
3232
name: Check out repository
3333
- uses: jdx/mise-action@v2
34-
env:
35-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
with:
35+
github_token: ${{ secrets.GITHUB_TOKEN }}
3636
- name: Go cache
3737
uses: ./.github/actions/go-cache
3838
- name: Generate test matrix
@@ -64,8 +64,8 @@ jobs:
6464
steps:
6565
- uses: actions/checkout@v4
6666
- uses: jdx/mise-action@v2
67-
env:
68-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67+
with:
68+
github_token: ${{ secrets.GITHUB_TOKEN }}
6969
- name: Go cache
7070
uses: ./.github/actions/go-cache
7171

.github/workflows/doc.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ jobs:
2727
- uses: jdx/mise-action@v2
2828
with:
2929
working_directory: doc
30-
env:
31-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30+
github_token: ${{ secrets.GITHUB_TOKEN }}
3231

3332
- name: Build
3433
run: mise run doc:build --verbose

.github/workflows/prepare-release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ jobs:
2323
uses: actions/checkout@v4
2424

2525
- uses: jdx/mise-action@v2
26-
env:
27-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
with:
27+
github_token: ${{ secrets.GITHUB_TOKEN }}
2828
- id: run
2929
run: |
3030
mise run release:prepare ${{ inputs.version }}

.github/workflows/publish-release.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ jobs:
2828
token: ${{ secrets.PAT }}
2929

3030
- uses: jdx/mise-action@v2
31-
env:
32-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
with:
32+
github_token: ${{ secrets.GITHUB_TOKEN }}
3333

3434
- name: Set version (changie)
3535
if: inputs.version == ''
@@ -86,8 +86,8 @@ jobs:
8686
ref: ${{ inputs.ref }}
8787

8888
- uses: jdx/mise-action@v2
89-
env:
90-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89+
with:
90+
github_token: ${{ secrets.GITHUB_TOKEN }}
9191

9292
- name: Set version (changie)
9393
if: inputs.version == ''

repo_init.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ func (cmd *repoInitCmd) Run(
104104
if err != nil {
105105
return fmt.Errorf("guess trunk: %w", err)
106106
}
107+
} else if !repo.BranchExists(ctx, cmd.Trunk) {
108+
// User-provided trunk must be a local branch.
109+
log.Errorf("Are you sure %v is a local branch?", cmd.Trunk)
110+
return fmt.Errorf("not a branch: %v", cmd.Trunk)
107111
}
108112
must.NotBeBlankf(cmd.Trunk, "trunk branch must have been set")
109113

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# 'repo init' should fail when --trunk is a remote ref like origin/main
2+
3+
as 'Test <test@example.com>'
4+
at '2025-07-14T12:00:00Z'
5+
6+
# Set up a repository with a shamhub remote
7+
mkdir repo
8+
cd repo
9+
git init -b main
10+
git commit --allow-empty -m 'Initial commit'
11+
12+
shamhub init
13+
shamhub new origin alice/example.git
14+
git push origin main
15+
16+
# Try to initialize with a remote ref as trunk - should fail
17+
! gs repo init --trunk origin/main
18+
stderr 'Are you sure origin/main is a local branch?'
19+
stderr 'not a branch: origin/main'

0 commit comments

Comments
 (0)