Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: git remote set-url completion



On 21 May, pseyfert wrote:
>
> I was not happy with the completion of
> git remote set-url <some remote> TAB
>
> in my usage this should yield the same completions as `git clone TAB`
> (a url like https://gitlab.my_project.tld or git@xxxxxxxxxx or some path to a local repository)

git clone doesn't seem to complete http: style URLs either.

> So I put the below patch together which uses __git_repositories (and _urls) instead of _urls.

Thanks for this. I've got a few comments.

> I also saw there was a todo left in _git for doing
> git remote set-url <some remote> <new url> <old url>
> which used to just use _urls for the completion of old url,
> here I get the output of `git remote get-url <some remote> --all`

Except the --all is missing.

> +          # TODO: Old URL does not get completed if --push, --add, or --delete are present

With --push, the old URL is, I believe, still valid. And with --delete, it
is the new one that should be excluded.

The (3) exclusion should work. Perhaps add the numbers into the next arg
specifications to make it clearer given that they're being referenced.

> +          # TODO: assumes $line[1] is always the remote name

That seems correct to me and not an assumption.

> +          _message "the line is: $line"

That looks like leftover debug.

> +(( $+functions[__git_repositories_or_url] )) ||
> +__git_repositories_or_url () {
> +  _alternative \
> +    'repositories::__git_repositories' \
> +    'url::_urls'

The tag should be 'urls' rather than 'url'.

> +}
> +
> +(( $+functions[__git_current_remote_url] )) ||
> +__git_current_remote_url () {
> +    # TODO: is ${(@)*[1,4]} a proper replacement for $* and passing extra arguments?

NO.

Various styles can affect what _description adds. matcher-list for
example. Don't rely on that.

I'd be inclined to throw away the inherited arguments. A space in the
_arguments spec prevents them from being added:

  '3:old url: __git_current_remote_url $line[1]'

Or make the helper function not be a completion function so that you
have something like:
  
  '3:old url:compadd - $(__git_current_remote_url $line[1])'

> +    # TODO: add --push to the `git remote get-url` command in case `git remote set-url --push origin <new url> <TAB>` is completed

Adding ${(k)opt_args[--push]} should get you that. It also needs --all
adding in case there are more than one.

Oliver



Messages sorted by: Reverse Date, Date, Thread, Author