Skip to content

ZSaberLv0/ZFVimGitUtil

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 

Repository files navigation

some git util for vim

if you like my work, check here for a list of my vim plugins, or buy me a coffee

Install

use Vundle or any other plugin manager is recommended

Plugin 'ZSaberLv0/ZFVimGitUtil'
Plugin 'tpope/vim-fugitive' " optional, for :ZFGitRebase only

Main Feature

  • :ZFGitPushQuickly[!] [comment]

    "stash > pull > unstash > commit > push" quickly

    usage:

    • cd to a git repo
    • :ZFGitPushQuickly[!] [commit message]
    • show commit info before actually perform, unless the <bang> token ! is set
    • if [commit message] omitted, g:ZFGitPushQuickly_defaultMsg would be used

    features:

    • all changed and added files would be committed
    • if conflicts, push would abort, and conflicted files would be opened automatically
    • user name/email/password would be saved temporarily, stop input them repeatly like a nerd

    note:

    • only http(s) repo is directly supported: http(s)://user(:pwd)@server.xx(:port)/path
    • ssh repo is not directly supported: (ssh://)user@server:/path
    • to support ssh repo:
      1. on YourClient: ssh-keygen

      2. on YourClient: ssh-copy-id -i ~/.ssh/id_rsa.pub -p 22 YourServerUserName@YourServerDomain

      3. make sure it works before actually use quick push:

        git fetch --all, if fetch success without password required, then you are done

  • :ZFGitBatchPull / :ZFGitBatchPush [comment]

    find and go through all git repo under cwd, and try to pull/push

  • :ZFGitClean

    fill a temp file with untracked and ignored files, save the temp file to remove all of these files

  • :ZFGitFetch

    quickly fetch from remote, and prune local and remote merged branches

  • :ZFGitCheckout

    quickly switch between branches

  • :ZFGitMergeToAndPush

    merge current branch to specified branch, push, then go back to current branch

  • :ZFGitRemoveBranch

    remove branch from remote and local quickly

  • :ZFGitRebase

    perform 'git rebase -i' inside vim, require tpope/vim-fugitive

  • :ZFGitStatus

    find and go through all git repo under cwd, echo its changes by git status -s

  • :ZFGitConflictOpen / :ZFGitConflictResolve

    util to open or resolve conflict files

  • :ZFGitMirror

    config git mirror quickly

  • :ZFGitHardRemoveAllHistory

    like the name, use with caution

  • NOTE: github would no longer support plain password push method (https://YourName:YourPlainPassword@github.com/xxx), you must use access token for now, see here for more info, and see below for how to use the access token for short

Configs

  • to make things more convenient and more safe, it's recommended to setup access token

    • private repos are also supported, but your access token must have push permission to your private repos, otherwise, this confusing error message may occur:

      remote: Repository not found.
      fatal: repository 'https://YourName@github.com/YourName/YourRepo/' not found
      
      • for public repos, check Access public repositories would be fine
      • for private repos, you must check Full control of private repositories
  • we are trying hard to make ZFGitPushQuickly more quickly, the git user name/email/password are detected automatically with these order:

    1. your custom setting

      let g:zf_git = [
              \   {
              \     'repo' : 'https://github.com/YourName/YourRepo', " match by string compare
              \     'repo_regexp' : 'github\.com', " match by regexp `match()`
              \
              \     'git_user_email' : '',
              \     'git_user_name' : '',
              \     'git_user_pwd' : '', " optional
              \   },
              \ ]
      
    2. git config user.name / git config user.email to check from local repo

    3. your global custom setting

      let g:zf_git_user_email = ''
      let g:zf_git_user_name = ''
      let g:zf_git_user_pwd = '' " optional
      
    4. git config --global user.name / git config --global user.email to check from git global setting

  • the git_user_pwd mentioned above, can be your git password, or access token mentioned above

  • the email and user name would be saved to git config of local repo, the password would be saved temporarily until vim exit

  • by default, we would apply some git configs to local repo config:

    let g:zf_git_extra_config = [
            \   'git config core.filemode false',
            \   'git config core.autocrlf false',
            \   'git config core.safecrlf true',
            \ ]
    

Util functions

  • ZFGitPwdSet(git_remoteurl, git_user_name, git_user_pwd)

    update the password stored by ZFGitPushQuickly, cached in memory until vim exit, set empty git_user_pwd to remove saved password

  • ZFGitPrepare(options)

    prepare necessary git info

    options:

    • module : module name, ZFGit by default

    • needPwd : whether need pwd, false by default

    • confirm : whether need confirm, true by default

    • extraInfo : extra info when confirm, empty by default

    • extraChoice : extra choice options

      {
          'key1' : 'text1',
          'key2' : 'text2',
      }
      

    return:

    • choice : y/extraChoice
    • git_remoteurl
    • git_user_email
    • git_user_name
    • git_user_pwd
  • ZFGitGetInfo()

    return current git config (see ZFGitPushQuickly above)

    return:

    • git_remoteurl
    • git_user_email
    • git_user_name
    • git_user_pwd
  • get various info

    • ZFGitGetRemoteUrl()
    • ZFGitGetCurCommit()
    • ZFGitGetCurBranch()
    • ZFGitGetAllLocalBranch()
    • ZFGitGetAllRemoteBranch()
    • ZFGitGetAllBranch()
    • ZFGitGetAllConflictFiles()
  • command line complete

    • ZFGitCmdComplete_branch
    • ZFGitCmdComplete_branch_remote
    • ZFGitCmdComplete_branch_local
    • ZFGitCmdComplete_changedPath