<commit_before>let s:Console = vital#gina#import('Vim.Console')


function! gina#action#branch#define(binder) abort
  call a:binder.define('branch:refresh', function('s:on_refresh'), {
        \ 'description': 'Refresh remote branches',
        \ 'mapping_mode': 'nv',
        \ 'requirements': [],
        \ 'options': {},
        \})
  call a:binder.define('branch:checkout', function('s:on_checkout'), {
        \ 'description': 'Checkout a branch',
        \ 'mapping_mode': 'n',
        \ 'requirements': ['branch'],
        \ 'options': {},
        \})
  call a:binder.define('branch:delete', function('s:on_delete'), {
        \ 'description': 'Delete a branch',
        \ 'mapping_mode': 'nv',
        \ 'requirements': ['branch'],
        \ 'options': {},
        \})
  call a:binder.define('branch:delete:force', function('s:on_delete'), {
        \ 'description': 'Delete a branch',
        \ 'mapping_mode': 'nv',
        \ 'requirements': ['branch'],
        \ 'options': { 'force': 1 },
        \})
  call a:binder.define('branch:move', function('s:on_move'), {
        \ 'description': 'Rename a branch',
        \ 'mapping_mode': 'nv',
        \ 'requirements': ['branch'],
        \ 'options': {},
        \})
  call a:binder.define('branch:move:force', function('s:on_move'), {
        \ 'description': 'Rename a branch',
        \ 'mapping_mode': 'nv',
        \ 'requirements': ['branch'],
        \ 'options': { 'force': 1 },
        \})
  call a:binder.define('branch:new', function('s:on_new'), {
        \ 'description': 'Create a new branch',
        \ 'mapping_mode': 'n',
        \ 'requirements': ['branch'],
        \ 'options': {},
        \})
  call a:binder.define('branch:set-upstream-to', function('s:on_set_upstream_to'), {
        \ 'description': 'Set upstream of a branch',
        \ 'mapping_mode': 'nv',
        \ 'requirements': ['branch'],
        \ 'options': {},
        \})
  call a:binder.define('branch:unset-upstream', function('s:on_unset_upstream'), {
        \ 'description': 'Unset upstream of a branch',
        \ 'mapping_mode': 'nv',
        \ 'requirements': ['branch'],
        \ 'options': {},
        \})
endfunction


" Private --------------------------------------------------------------------
function! s:on_refresh(candidates, options) abort
  let git = gina#core#get_or_fail()
  execute 'Gina remote update --prune'
endfunction

function! s:on_checkout(candidates, options) abort
  if empty(a:candidates)
    return
  endif
  let git = gina#core#get_or_fail()
  let options = extend({}, a:options)
  for candidate in a:candidates
    execute printf(
          \ 'Gina checkout %s',
          \ gina#util#shellescape(candidate.branch),
          \)
  endfor
endfunction

function! s:on_new(candidates, options) abort
  if empty(a:candidates)
    return
  endif
  let git = gina#core#get_or_fail()
  let options = extend({}, a:options)
  for candidate in a:candidates
    let name = s:Console.ask(
          \ 'Name: ', '',
          \)
    let from = s:Console.ask(
          \ 'From: ', candidate.branch,
          \ 'customlist,gina#complete#commit#branch',
          \)
    execute printf(
          \ 'Gina checkout -b %s %s',
          \ gina#util#shellescape(name),
          \ gina#util#shellescape(from),<commit_msg>Add branch:checkout:track action to track a remote branch<commit_after>let s:Console = vital#gina#import('Vim.Console')


function! gina#action#branch#define(binder) abort
  call a:binder.define('branch:refresh', function('s:on_refresh'), {
        \ 'description': 'Refresh remote branches',
        \ 'mapping_mode': 'nv',
        \ 'requirements': [],
        \ 'options': {},
        \})
  call a:binder.define('branch:checkout', function('s:on_checkout'), {
        \ 'description': 'Checkout a branch',
        \ 'mapping_mode': 'n',
        \ 'requirements': ['branch'],
        \ 'options': {},
        \})
  call a:binder.define('branch:checkout:track', function('s:on_checkout'), {
        \ 'description': 'Checkout a branch and create a local branch',
        \ 'mapping_mode': 'n',
        \ 'requirements': ['branch'],
        \ 'options': {'track': 1},
        \})
  call a:binder.define('branch:delete', function('s:on_delete'), {
        \ 'description': 'Delete a branch',
        \ 'mapping_mode': 'nv',
        \ 'requirements': ['branch'],
        \ 'options': {},
        \})
  call a:binder.define('branch:delete:force', function('s:on_delete'), {
        \ 'description': 'Delete a branch',
        \ 'mapping_mode': 'nv',
        \ 'requirements': ['branch'],
        \ 'options': { 'force': 1 },
        \})
  call a:binder.define('branch:move', function('s:on_move'), {
        \ 'description': 'Rename a branch',
        \ 'mapping_mode': 'nv',
        \ 'requirements': ['branch'],
        \ 'options': {},
        \})
  call a:binder.define('branch:move:force', function('s:on_move'), {
        \ 'description': 'Rename a branch',
        \ 'mapping_mode': 'nv',
        \ 'requirements': ['branch'],
        \ 'options': { 'force': 1 },
        \})
  call a:binder.define('branch:new', function('s:on_new'), {
        \ 'description': 'Create a new branch',
        \ 'mapping_mode': 'n',
        \ 'requirements': ['branch'],
        \ 'options': {},
        \})
  call a:binder.define('branch:set-upstream-to', function('s:on_set_upstream_to'), {
        \ 'description': 'Set upstream of a branch',
        \ 'mapping_mode': 'nv',
        \ 'requirements': ['branch'],
        \ 'options': {},
        \})
  call a:binder.define('branch:unset-upstream', function('s:on_unset_upstream'), {
        \ 'description': 'Unset upstream of a branch',
        \ 'mapping_mode': 'nv',
        \ 'requirements': ['branch'],
        \ 'options': {},
        \})
endfunction


" Private --------------------------------------------------------------------
function! s:on_refresh(candidates, options) abort
  let git = gina#core#get_or_fail()
  execute 'Gina remote update --prune'
endfunction

function! s:on_checkout(candidates, options) abort
  if empty(a:candidates)
    return
  endif
  let git = gina#core#get_or_fail()
  let options = extend({
        \ 'track': 0,
        \}, a:options)
  for candidate in a:candidates
    let is_remote = !empty(get(candidate, 'remote'))
    let branch = is_remote
          \ ? substitute(candidate.branch, '^origin/', '', '')
          \ : candidate.branch
    if is_remote && options.track
      execute printf(
            \ 'Gina checkout -b %s %s',
            \ gina#util#shellescape(branch),
            \ gina#util#shellescape(candidate.branch),
            \)
    else
      execute printf(
            \ 'Gina checkout %s',
            \ gina#util#shellescape(candidate.branch),
            \)
    endif
  endfor
endfunction

function! s:on_new(candidates, options) abort
  if empty(a:candidates)
    return
  endif
  let git = gina#core#get_or_fail()
  let options = extend({}, a:options)
  for candidate in a:candidates
    let name = s:Console.ask(
          \ 'Name: ', '',
          \)
    let from = s:Console.ask(
          \ 'From: ', candidate.branch,
          \ 'customlist,gina#complete#commit#branch',
          \)
    execute printf(
          \ 'Gina checkout -b %s %s',
          \ gina#util#shellescape(name),
          \ gina#util#shellescape(from),
{'fraction_non_alphanumeric': 0.19151548219888145, 'fraction_numerical': 0.0008184422316191515, 'mean_word_length': 2.3146473779385173, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5192938', 'n_tokens_mistral': 2305, 'n_tokens_neox': 2258, 'n_words': 455}