fzf-checkout.vim
fzf-checkout.vim copied to clipboard
automatic track for non-existing local branches
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.
Sure, I wanted to implement this a time ago, but didn't end with a solution that always worked for all cases.
I will give it a try.
Here my tow pence:
with
git branch --format "%(refname:short)|%(upstream:short)"
you'll get a list of branches with its possible upstream.
- Test if you have chosen a local repo (refname = name) => {branch} = refname, {localbranch} = refname, {remotebranch} = upstream
- Test if you have chosen a remote repo with local copy (upstream = name) => {branch} = refname, {localbranch} = refname, {remotebranch} = upstream
- Otherwise its a remote only => {branch} = chosen name, {localbranch} = empty, {remotebranch} = chosen name
Now you are able in VIML to code somtehing like this
- if {localbranch} != '' then system("git switch {localbranch}")
- else system("git checkout --track {remotebranch}")