git has an internal concept of a branch's upstream branch, and the remote need
not be 'origin', and also, the upstream branch name may differ completely. So,
use git's {u} keyword to obtain the upstream branch name.
This removes all 'origin' strings from gits. Also, git_branch_exists() is no
longer needed, drop it.
Also remove a couple of default arguments which aren't ever used because we
always pass arguments anyway.
In the case of git_ahead_behind(), we would have use for a default
branch_upstream=None to imply calling git_branch_upstream(), but then during
rebase, if no upstream exists, we would invoke it twice to get None a second
time. So just call the function explicitly. I thought about returning an empty
string instead of None, but it's too convoluted.
In git_output(), pipe STDERR to STDOUT, because every time we parse a remote
ref (git ref-parse --abbrev-ref '%s{u}') and there is no remote branch, git
prints 'Fatal: there is no remote bla bla' on stdout, and that error is
expected / ok to happen, so it just clutters the 'gits' output. The easiest way
to achieve silence then is to pipe to STDOUT, IIUC otherwise we'd have to use
Popen() and communicate()... In the case of error, subprocess raises an
exception and we see that an error happens. In the ref-parse case we can simply
catch the exception and be quiet.
Change-Id: Ife146903ae1323a4e568587ccfd4018725e9d719
Use 'git diff' instead of 'git diff-index'. The latter does not look at
the content. It listed a file with an updated timestap as modified
(indicated in gits with "MODS"), whereas 'git diff' and 'git status'
did not (and we want this behavior, not marking it as modified).
This was a regression from b93f50 ("gits: use git plumbing commands").
Change-Id: I6726190912a1b3eb865cda77fbea6bf58a635d6e
Instead of 'git status' and 'git branch', which change their output
depending on the git version and locale, use the low-level plumbing
commands.
'gits status' output is exactly the same, 'gits rebase' output is
a bit less redundant now (that was easier to implement).
Change-Id: I42544313d14db126c99e2d9a02b8f63031944947
I keep re-using this functionality in completely unrelated realms, and decided
to unify the oddly named scripts in a single 'gits' meta-repos tool, so I can
just symlink this script into my ~/bin and use it everywhere.
Change-Id: I579e7af26d76d5c5d83b2349695456bc7b54f5a2