From 24f77fb55049a4c3006c35b1cb4283d9b9db0b4c Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Sat, 11 Aug 2018 19:32:39 +0100 Subject: [PATCH] Add aliases for working with autosquash rebases * Rename the `squash` alias to `prepare` to repurpose it. * Change `squash` alias to `git commit --squash=`. * Add `fixup` alias to `git commit --fixup=`. * Set the `rebase.autoSquash` config option to `true`. --- .conduit.yaml | 2 ++ README.md | 27 ++++++++++++++++++++++----- _git-changes | 3 +-- _git-fixup | 6 ++++++ _git-squash | 6 ++++++ config | 10 ++++++++-- 6 files changed, 45 insertions(+), 9 deletions(-) create mode 100644 _git-fixup create mode 100644 _git-squash diff --git a/.conduit.yaml b/.conduit.yaml index 4bf0a0e..a12878d 100644 --- a/.conduit.yaml +++ b/.conduit.yaml @@ -3,5 +3,7 @@ - symlink: - {src: config, dst: ~/.gitconfig} - {src: _git-changes, dst: ~/.local/share/zsh/site-functions/_git-changes} + - {src: _git-fixup, dst: ~/.local/share/zsh/site-functions/_git-fixup} + - {src: _git-squash, dst: ~/.local/share/zsh/site-functions/_git-squash} - repo: - git@code.infektor.net:benie/config.git diff --git a/README.md b/README.md index 82918a6..d3c12c9 100644 --- a/README.md +++ b/README.md @@ -2,14 +2,18 @@ ## Aliases -A set of [Git][git] aliases which follow the idea "say what you mean" rather -than remember the plumbing term of a specific command. +A set of [Git][git] [aliases][aliases] which follow the idea "say what you mean" +rather than remembering the plumbing term of a specific command. * `abandon` abandons all local changes leave a clean repository. -* `amend` amends the last commit, shorthand for `git commit --amend`. * `unstage` unstage staged changes, shorthand for `git reset -q HEAD --`. -* `squash` perform an interactive rebase to squash all commits since branching, - shorthand for `git rebase -i --fork-point`. +* `amend` amends the last commit, shorthand for `git commit --amend`. +* `fixup` prepare a fixup commit for use with `git rebase --autosquash`, + shorthand for `git commit --fixup=`. +* `squash` prepare a squash commit for use with `git rebase --autosquash`, + shorthand for `git commit --squash=`. +* `prepare` prepare a branch for merging into another, shorthand for + `git rebase --interactive --fork-point`. * `list` list local branches, a shorthand for `git branch`. * `create` creates a new branch, shorthand for `git checkout -b`. * `delete` deletes an existing branch, shorthand for `git branch -D`. @@ -31,4 +35,17 @@ than remember the plumbing term of a specific command. `HEAD` has the subject `temp!` then `git reset --mixed HEAD~` is executed, otherwise the message `error: commit subject is not: temp!` is output. +## Zsh Completions + +The excellent [Git][git] completions provided by [Zsh][zsh] which can see +through [aliases][aliases] however some aliases involve multiple commands or +rely on the shell to function. The following aliases extend the default +[Git][git] completions. + +* `git changes` completions for the branch name to compare with are provided. +* `git fixup`/`git squash` completions for recent commits to fixup/squash are + provided. + [git]: https://git-scm.com +[aliases]: https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases +[zsh]: https://www.zsh.org diff --git a/_git-changes b/_git-changes index d703871..4795197 100644 --- a/_git-changes +++ b/_git-changes @@ -1,7 +1,6 @@ #compdef git-changes #description Compare changes on this branch with another. -_arguments \ - '1: :__git_remote_branch_names_noprefix' +_arguments '1: :__git_remote_branch_names_noprefix' # vim: ft=zsh diff --git a/_git-fixup b/_git-fixup new file mode 100644 index 0000000..4a134fc --- /dev/null +++ b/_git-fixup @@ -0,0 +1,6 @@ +#compdef git-fixup +#description Prepare a commit for fixup during autosquash rebase. + +_arguments '1: :__git_recent_commits' + +# vim: ft=zsh diff --git a/_git-squash b/_git-squash new file mode 100644 index 0000000..4fdd65e --- /dev/null +++ b/_git-squash @@ -0,0 +1,6 @@ +#compdef git-squash +#description Prepare a commit for squashing during autosquash rebase. + +_arguments '1: :__git_recent_commits' + +# vim: ft=zsh diff --git a/config b/config index 4beddc6..09bcf4c 100644 --- a/config +++ b/config @@ -2,9 +2,12 @@ [alias] abandon = !git reset --hard HEAD && git clean -d -f - amend = commit --amend unstage = reset -q HEAD -- - squash = rebase -i --fork-point + + amend = commit --amend + fixup = !sh -c 'git commit --fixup=$1' -- + squash = !sh -c 'git commit --squash=$1' -- + prepare = rebase -i --fork-point list = branch create = checkout -b @@ -49,6 +52,9 @@ [push] default = simple +[rebase] + autoSquash = true + [user] useConfigOnly = true