fzf-checkout.vim icon indicating copy to clipboard operation
fzf-checkout.vim copied to clipboard

automatic track for non-existing local branches

Open mdedonno1337 opened this issue 3 years ago • 3 comments

How about add an option to allows automatic tracking for new branches if not available locally?

I know it's possible to track the branch with the 'alt-enter' binding; if forgotten, we go to the detached head situation. I think an option to automatically create the branch and track it could be interessting; this behaviour would be disabled by default, to not break current behaviour.

I can git it a try and do the PR.

mdedonno1337 avatar Mar 06 '21 12:03 mdedonno1337

Sure, I wanted to implement this a time ago, but didn't end with a solution that always worked for all cases.

stsewd avatar Mar 11 '21 23:03 stsewd

I will give it a try.

mdedonno1337 avatar Mar 12 '21 10:03 mdedonno1337

Here my tow pence:

with

git branch --format "%(refname:short)|%(upstream:short)"

you'll get a list of branches with its possible upstream.

  1. Test if you have chosen a local repo (refname = name) => {branch} = refname, {localbranch} = refname, {remotebranch} = upstream
  2. Test if you have chosen a remote repo with local copy (upstream = name) => {branch} = refname, {localbranch} = refname, {remotebranch} = upstream
  3. Otherwise its a remote only => {branch} = chosen name, {localbranch} = empty, {remotebranch} = chosen name

Now you are able in VIML to code somtehing like this

  1. if {localbranch} != '' then system("git switch {localbranch}")
  2. else system("git checkout --track {remotebranch}")

Grueslayer avatar Aug 16 '21 13:08 Grueslayer