vscode-gitlens icon indicating copy to clipboard operation
vscode-gitlens copied to clipboard

"Create Pull Request on Remote" does not target default branch

Open ericman314 opened this issue 10 months ago • 3 comments

Description

When running "Create Pull Request on Remote" from a feature branch, the webpage that is opened targets "master" or "main" or probably whatever your first branch was called, instead of the default branch. Previously, the page that was opened targeted the default branch. I first noticed this today.

To reproduce:

  1. On GitHub, have a repository with a "master" or "main" branch, and then create one other branch, such as "dev".
  2. Set "dev" as the default branch on github. (New pull requests should target this branch.)
  3. In VS Code, create a new branch "feature", commit some changes, then push the branch to remote.
  4. Run "GitLens: Create Pull Request on Remote".
  5. The webpage that is opened targets "master" or "main", instead of the default "dev" branch.

GitLens Version

17.0.1

VS Code Version

Version: 1.98.2 Commit: ddc367ed5c8936efe395cffeec279b04ffd7db78 Date: 2025-03-12T13:32:45.399Z Electron: 34.2.0 ElectronBuildId: 11161602 Chromium: 132.0.6834.196 Node.js: 20.18.2 V8: 13.2.152.36-electron.0 OS: Linux x64 6.12.10-76061203-generic

Git Version

git version 2.34.1

Logs, Screenshots, Screen Captures, etc

gitlens.log

ericman314 avatar Apr 04 '25 19:04 ericman314

Hi @ericman314 Thank you for your submissions, we see the problem and we are going to address it.

For now we can suggest the following workaround:

  1. update local HEAD ref, so it is sync with the remote: git remote set-head origin -a
  2. reload VS Code window, so the caches are cleared

sergeibbb avatar Apr 10 '25 10:04 sergeibbb

That worked, thanks for the tip!

ericman314 avatar Apr 10 '25 14:04 ericman314

We use the origin/HEAD link to determine the target branch that, for GitHub.com, refers to the main branch on remote.

There are 2 points related to the current problem:

  1. When the main branch is updated on remote, usual git pull or git fetch do not update the origin/HEAD. For fixing it git remote set-head origin -a is needed. So, here we can determine strategy or an event when we do such update. What events should it be? Maybe it can be any time we detect that the repo has been updated?
  2. If we read origin/HEAD value once, then even if user manually updates the ref by git remote set-head origin -a, we don't see it, because the value is cached in cache.defaultBranchName and never get updated. So, here we need a way to drop this cache sometimes as well. What events it should be? Probably, it could be based on expiration. Expire if after few seconds?

This ticket is waiting for the decision whether we are going to do anything on n.1. and n.2. and what strategy to use. cc @eamodio

sergeibbb avatar Apr 11 '25 15:04 sergeibbb