This comment was a WIP draft note.
The separate `git show` command call is not necessary because
`get-all-git-local-refs` through `for-each-ref` already includes the
commit title. So the comment can be dropped without further
consideration / is already resolved.
* Fix previous logic assuming single remote name `origin`
* Fix wrong Local vs Remote branch name descriptions
* Fix git branch output with multiple branches per line breaking
auto-completions
* Fix current branch not showing up in git checkout branch completions
* Fix remote branches not showing up when local branch with upstream
exists despite them being different refs
* Show more contextual information in completion descriptions
* Use consistent sorting between command completions; Local branches
before remote branches before files before commits, with sorting from
git kept intact
Change implementation to a more encapsulated and type-specific approach:
* Use for-each-ref instead of git branch with manual current branch
query and current and HEAD ref removal
* Separate local and remote branch logic for good case separation
* Use separate for-each-ref calls for early case separation
* Decorate local and remote branch information in their respective cases
instead of content-conditional
* Decorate with 'Branch, Local|Remote, Commit Sha1 Subject, upstream
[head|behind x]
* Use new consistent description format '{Type}' | '{Type}, Commit
{Sha1} Subject | '{Type}, {Subtype}, {Commit Sha1+Subject}, {upstream
name + track}
* Dissolves some spread out logic, dropping commands
get-all-git-branches and extract-remote-branches-nonlocal-short and
extract-mergable-sources
Influenced completions: `git checkout`, `git switch`, `git merge`
---
Screenshot:

Should resolve#1041
Screenshot from before, showing a wrong classification of a local branch
as remote branch:

This is to provide completion for when user types `git [Tab]`.
There is already completion for `git help [Tab]` but I don't know why
author don't add it to `git` alone.
Fixes#1043
### motivation
Hi! This is something I wanted since [#14424 of
nushell/nushell](https://github.com/nushell/nushell/pull/14424) landed.
Unsorted completions on the `git checkout` command
### The problem
is that git checkout accepts lots of things: commits hashes, filenames,
local branches and remote branches. Since the mentioned pr all the
completions were sorted, but for this command it didn't make sense.
I used `git switch` to checkout a branch for the time being, but it's a
little annoying that you can't push "unsorted" completions on a command.
### the result
With the help of ysthakur and weirdan, I managed to achieve this:
```
git checkout <tab>
```
before: (these are sorted)

after: (these aren't)

### How?
Citing the docs:
https://www.nushell.sh/book/custom_completions.html#options-for-custom-completions
```
{
options: {
case_sensitive: false,
completion_algorithm: prefix,
positional: false,
sort: false,
},
completions: [cat, rat, bat]
}
}
```
and I passed **a table** to the `completions` key, instead of a _list_.
```
completions: $table_of_checkouts
```
I removed `gstat` plugin dependency need by replacing the command.
~~The only problem is that the aliases don't work for the current
nushell version~~
Done!
fixes#973 and closes#974
Hi! I realized if you use worktrees, with at least one branch checked
out and you:
```
git switch <tab>
```
the autocompletion is wrong, putting a `+ ` before the branch, and
piping it into the cmdline.
This comes from `nu-complete git local branches` function, it which it
only replaces `* ` for the current branch, but it doesn't for `+ ` for
worktrees.
Here is a sample:

I tested on my pc and works allright!
This remove a duplicate: the `--no-edit` was there twice in the "git
commit" command completion.
After my change, the only remaining `--no-edit` is at line 455.
Just using the completions I realized that:
```nu
# Create a new git repository
export extern "git init" [
--initial-branch(-b) # initial branch name
#should be
--initial-branch(-b): string # initial branch name
]
```
because initial branch takes a string, it not a boolean
Added completions for most of the flags for `git grep`.
A few flags have been omitted for this PR due to Git expecting arguments
for those be passed without whitespaces. The arguments are optional, but
the flags would not work when passed arguments (see `--open-with-pager`
and `--color` flags in [this
commit](ffa9ceab73)
for how I tried to do it).
Ex.
`--open-with-pager(-O)` expects the optional argument to be passed as
either `--open-with-pager=<pager>` or `-O<pager>`. Including it in the
completions list as I had implemented it breaks the flag when using the
optional parameter.
Feedback appreciated for how to handle that. I'm still new to the Nu
language, so I might have missed something obvious that could fix that.
Git `nu-complete` defs where outdated, using a removed function
`nu-complete git switachable branches`, now using `nu-complete git
switch`
Already tested (except for tags)
Added `git restore` to git completions, as I was missing tab completion
for that.
I've begun to use Nushell regularly, so I hope this addition will be
useful to others as it is to me.
Feedback is appreciated if there's any conventions I've missed, or
options that need better wording.
Reverts nushell/nu_scripts#868
I found that this works, if you source these files like
```
use aliases/git/git-aliases.nu *
use custom-completions/git/git-completions.nu *
```
but if you source them like this, it doesn't work.
```
use custom-completions/git/git-completions.nu *
use aliases/git/git-aliases.nu *
```
This changed recently somewhere in nushell.
I used [typos](https://github.com/crate-ci/typos/).
I manually checked all the corrections and they seem safe to me.
There are still some left, but those in this PR are good
Hi! Another bug I found, in `git`, you can
```bash
git stash show
```
with no args and should be alright, but the .nu script is requiring a
git name. (maybe for a previous version of git it was needed)
This PR fixes the conflicts between git-completions.nu and
git-aliases.nu.
Prior to this PR you would see problems like this
```nushell
❯ use custom-completions\git\git-completions.nu *
❯ use aliases\git\git-aliases.nu
Error: nu::parser::missing_flag_param
× Missing flag argument.
╭─[D:\nu_scripts\aliases\git\git-aliases.nu:64:1]
64 │ export alias gco = git checkout
65 │ export alias gcor = git checkout --recurse-submodules
· ──────────┬─────────
· ╰── flag missing string argument
66 │ export alias gcount = git shortlog --summary --numbered
╰────
```
This is because, in this example, in git-completions.nu, there is a
custom command named `git checkout` that takes a `--recurse-submodules:
string` parameter, which means it's expecting a string. Removing the `:
string` part fixes the issue and allows the files to be sourced/used as
expected.
This seems more like a hack than a fix. I'm not sure if this behavior is
intended or not, but this PR fixes it anyway.
close#493
The different commands such as `git checkout`, `git switch`, `git
cherry-pick` and `git rebase` all accept slightly differing refspecs.
This commit separates the extraction of refspecs and combines them in
individual completion commands for the different external commands.
All git commands complete with a table of `value | description` now.
Addresses #406
Co-authored-by: Simon Gasse <sgasse@users.noreply.github.com>
Added branch, remote, diff, commit, pull, stash, init, status, add, rm,
help, log, bisect
Also removed ? from `git rebase --onto` which was putting a literal `?`
into the flag when completing.