Skip to content

git status porcelain output should include remote details #1715

Closed
@shiftkey

Description

@shiftkey

This isn't a defect but is instead an opportunity to improve Git for scripting scenarios.

In Git 2.16 git for-each-ref learned about how to list upstream and push information - for when a local branch is tracking a remote branch:

* The "--format=..." option "git for-each-ref" takes learned to show
the name of the 'remote' repository and the ref at the remote side
that is affected for 'upstream' and 'push' via "%(push:remotename)"
and friends.

An example of this:

$ git for-each-ref --format="'%(refname)' -> '%(upstream:remotename) %(upstream:lstrip=3)'" refs/heads/
'refs/heads/add-permissions-hash-for-repository' -> ' '
'refs/heads/add-support-for-previewing-svgs' -> ' '
'refs/heads/another-minification-bug' -> 'origin another-minification-bug'
'refs/heads/b-b-b-banner' -> 'origin b-b-b-banner'
'refs/heads/beta-link-to-release-notes-works' -> ' '
'refs/heads/buffer-rule' -> ' '
'refs/heads/bump-for-new-git-lfs' -> 'origin bump-for-new-git-lfs'
'refs/heads/catch-errors-betterer' -> 'origin catch-errors-betterer'
'refs/heads/config-shows-untracked-files' -> ' '
'refs/heads/contributor-stats' -> 'origin contributor-stats'
'refs/heads/database-field-naming' -> 'origin database-field-naming'
'refs/heads/defer-remote-detection-to-dialog' -> 'origin defer-remote-detection-to-dialog'
'refs/heads/detect-bare-repository' -> ' '
'refs/heads/docs-about-labels' -> ' '
'refs/heads/document-discard-changes' -> 'origin document-discard-changes'
'refs/heads/drop-back-to-classic-api' -> 'origin drop-back-to-classic-api'
'refs/heads/dynamically-stylable-svg' -> 'OiYouYeahYou dynamically-stylable-svg'
'refs/heads/encodings-as-a-first-class-thing' -> ' '
'refs/heads/experimental-ssh-setup' -> 'origin experimental-ssh-setup'
'refs/heads/extract-settings-into-own-store' -> ' '
...

This means we can handle scenarios where users have a / in their remote name - it's not something that users often do, but it's something that we should be able to handle when working with Git repositories.

One place related to this is git status - it has a way to emit the ahead/behind information for-free alongside seeing what's changed in your directory:

$ git status --porcelain=2 --branch
# branch.oid 2b111155914cb44824b39ee197deed23bb825a1a
# branch.head master
# branch.upstream origin/master
# branch.ab +0 -0

It'd be nice to be able to emit these new values from (I talked about this with @dscho a while ago and he indicated this should be a new version of the porcelain format for backwards compatibility reasons):

$ git status --porcelain=3 --branch
# branch.oid 2b111155914cb44824b39ee197deed23bb825a1a
# branch.head master
# upstream.remote origin
# upstream.branch master
# branch.ab +0 -0

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions