github / github/gh-stack

`gh stack submit` fails on forks by attempting to create PRs on upstream repository (`Head sha can't be blank`)

未關閉
#509 0 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Go
星號
1.5k
分支
70
平均合併
1 天 8 小時
30 天內合併 PR
7

描述

When using `gh stack submit` on a repository cloned from a **fork**, the command attempts to query and submit the stack against the upstream parent repository instead of the fork (or specified default repository).

Since the feature branches only exist on the fork (`origin`), GitHub's GraphQL API rejects the PR creation because the branches do not exist on the target upstream repository, resulting in `Head sha can't be blank` / `Base sha can't be blank`.

Executing `gh repo set-default /` does not alter this behavior.

### Environment
- **OS:** Windows 11 (Git Bash / MINGW64)
- **`gh` version:** `gh version 2.100.0 (2026-09-03)`
- **`gh stack` extension version:** `github/gh-stack v0.1.1`

### Repository Setup
- **origin:** [https://github.com/Hakzai/pokerpulsepro-tauri.git](https://github.com/Hakzai/pokerpulsepro-tauri.git) (Fork)
- **upstream:** [https://github.com/davidelvar/pokerpulsepro-tauri.git](https://github.com/davidelvar/pokerpulsepro-tauri.git) (Parent Repo)
- `gh repo set-default` is explicitly set to `Hakzai/pokerpulsepro-tauri`.

### Steps to Reproduce
1. Clone a fork repository that has an `upstream` remote configured.
2. Create stacked branches locally and push them to `origin`:
a. `main` -> `feature/branch-1` -> `feature/branch-2`
3. Set the default repository using `gh repo set-default Hakzai/pokerpulsepro-tauri`.
4. Run `gh stack submit`.

### Expected Behavior
`gh stack submit` should resolve stacked PRs against the configured default repository (`Hakzai/pokerpulsepro-tauri`) or provide cross-repository fork support by specifying the head branch owner/ref.

### Actual Behavior
The command targets `davidelvar/pokerpulsepro-tauri` and fails with:

```log
⚠ failed to create PR for feature/add-brazil-real-currency: creating PR: GraphQL: Head sha can't be blank, Base sha can't be blank, No commits between main and feature/add-brazil-real-currency, Head ref must be a branch (createPullRequest)
```

#### Debug Output (`GH_DEBUG=1 gh stack submit`)
Relevant log excerpts showing API requests targeting the upstream repo instead of the fork:

```log
* Request to https://api.github.com/repos/davidelvar/pokerpulsepro-tauri/stacks?per_page=100&page=1
...
[git.exe push origin --force-with-lease=refs/heads/feature/add-brazil-real-currency:... refs/heads/feature/add-brazil-real-currency:refs/heads/feature/add-brazil-real-currency]
* Request to https://api.github.com/graphql
⚠ failed to create PR for feature/add-brazil-real-currency: creating PR: GraphQL: Head sha can't be blank, Base sha can't be blank, No commits between main and feature/add-brazil-real-currency, Head ref must be a branch (createPullRequest)
```

#### Git Config
Git config is pointing correctly the upstream to `davidelvar/pokerpulsepro-tauri` and the origin to the fork at `Hakzai/pokerpulsepro-tauri`.

```ini
submodule.active=.
remote.origin.url=https://github.com/Hakzai/pokerpulsepro-tauri.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
remote.origin.gh-resolved=base
branch.main.remote=origin
branch.main.merge=refs/heads/main
branch.main.vscode-merge-base=origin/main
lfs.repositoryformatversion=0
remote.upstream.url=https://github.com/davidelvar/pokerpulsepro-tauri.git
remote.upstream.fetch=+refs/heads/*:refs/remotes/upstream/*
...
branch.feature/full-backup-impl.vscode-merge-base=origin/main
branch.feature/full-backup-impl.remote=origin
branch.feature/full-backup-impl.merge=refs/heads/feature/full-backup-impl
branch.feature/add-brazil-real-currency.vscode-merge-base=origin/main
branch.feature/add-brazil-real-currency.remote=origin
branch.feature/add-brazil-real-currency.merge=refs/heads/feature/add-brazil-real-currency
branch.feature/create-winners-board.vscode-merge-base=origin/main
branch.feature/create-winners-board.remote=origin
branch.feature/create-winners-board.merge=refs/heads/feature/create-winners-board
branch.bugfix/prize-tab-not-showing-champion.vscode-merge-base=origin/main
branch.bugfix/prize-tab-not-showing-champion.remote=origin
branch.bugfix/prize-tab-not-showing-champion.merge=refs/heads/bugfix/prize-tab-not-showing-champion
branch.chore/deploy-to-github-pages.vscode-merge-base=origin/main
branch.chore/deploy-to-github-pages.remote=origin
branch.chore/deploy-to-github-pages.merge=refs/heads/chore/deploy-to-github-pages
rerere.enabled=true
rerere.autoupdate=true
gh-stack.remote=origin
```

貢獻指南

開啟貢獻指南

研究方向

從 `gh stack submit` 入口開始,追蹤 repository 解析流程,包括 `gh-stack.remote` 和設定的預設 repository,直到 GraphQL `createPullRequest` 呼叫。使用 fork 設定和 `GH_DEBUG=1` 進行重現。完成標準是堆疊 PR 的建立目標為 fork,或明確支援預期的 head repository,且不再出現空白 SHA 錯誤。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
git, github, go
領域
api, cli
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
活躍
描述清晰度
基本清楚
新手友好度
65/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。