Skip to content

[FEATURE] Detect unpushed commits on branches without an upstream #52

Description

@nilp0inter

What problem does this solve?

A local branch with commits but no remote/<branch> configured is silently reported as clean — the classic "made a feature branch, committed, forgot to push" case.

GetUpstreamStatusForAllRemotes runs git rev-parse --verify <remote>/<branch>, which fails when no upstream exists. CheckRepoState (internal/gitx/gitx.go) records the result as Ahead: -1, Behind: -1. HaveUnpushedCommits() (pkg/report/report.go) tests Ahead > 0, so -1 is not counted, and the repo is reported clean.

This is the most common forgot-to-push case, and it is exactly the false negative the tool exists to prevent.

Proposed solution

Distinguish "no upstream configured" from "0 ahead / 0 behind", and treat "has local commits + no upstream" as unpushed.

A clean implementation that also handles non-current branches (see related issue) is git rev-list --count <branch> --not --remotes — fetch-free, robust regardless of upstream presence: it counts commits on <branch> absent from every remote-tracking ref.

Out of scope

  • Detection on non-current branches (separate issue).
  • Performing the push.

Split off from #46.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions