Skip to content

Fix Git pull for branches with different upstream names - #8974

Open
gvdutra wants to merge 1 commit into
apache:mainfrom
gvdutra:8934-pull-tracking-branch
Open

gvdutra wants to merge 1 commit into
apache:mainfrom
gvdutra:8934-pull-tracking-branch

Conversation

@gvdutra

@gvdutra gvdutra commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #8934.

Use the current branch's configured upstream when pulling instead of assuming that the remote branch has the same name. The existing origin/<local-branch> fallback remains available for branches without upstream configuration.

Pulling a branch with no configured upstream and no matching branch on origin now reports a clear error instead of failing with a NullPointerException.

Tests:

  • Added coverage for pulling from an upstream with a different branch name.
  • Added coverage for the missing-upstream error.
  • ./mvnw -pl plugins/misc/git test (234 standard tests and 90 UI tests)
  • ./mvnw -pl plugins/misc/git spotless:apply spotless:check

  • Run mvn clean install apache-rat:check to make sure basic checks pass. A more thorough check will be performed on this pull request automatically.
  • The change is a single commit.
  • The related issue is mentioned above.
  • I hereby declare this contribution to be licensed under the Apache License Version 2.0, January 2004

@bamaer

bamaer commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Thanks @gvdutra, this fixes the case from #8934. I built the PR and ran the git plugin tests: all 324 pass, and both new tests fail on main.

Should fix

  • When the upstream is on a remote other than origin (for example feature tracking upstream/master), pull() still fetches only origin (UIGit.java:777). It then merges a stale upstream/master and reports "already up to date" even though upstream has new commits. On main this case failed with the NPE; with this PR, nothing happens and no error is shown.
    Suggested fix: fetch the branch's configured remote, new BranchConfig(config, branch).getRemote(), fall back to origin, and skip the fetch when the remote is . (the upstream is a local branch). With that change, a test with a second remote pulls the new commit and the existing tests still pass. A variant of testPullFromConfiguredUpstreamWithDifferentName with a second remote would cover it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Pull fails with a NullPointerException on a branch without a matching branch on origin

2 participants