From 034ae2d1438ed59a131e5611e90732be7eede205 Mon Sep 17 00:00:00 2001 From: Ade Attwood Date: Wed, 14 Jul 2021 14:24:17 +0100 Subject: [PATCH] feat(shell): override "gc" alias to open up the ".git/COMMIT_EDITMSG" When using tools like commitlint to lint your commits there is always that time you write an invalid commit. In this situation you are dumped back into the terminal with an error message and your invalid commit. This function will now load the invalid commit message back in to the editor so you can fix the errors and commit successfully. --- site-modules/core/files/oh-my-zsh/custom/git.zsh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/site-modules/core/files/oh-my-zsh/custom/git.zsh b/site-modules/core/files/oh-my-zsh/custom/git.zsh index e3b8596..7f6408a 100644 --- a/site-modules/core/files/oh-my-zsh/custom/git.zsh +++ b/site-modules/core/files/oh-my-zsh/custom/git.zsh @@ -21,3 +21,11 @@ function ggpushpr() { ggpush -o merge_request.merge_when_pipeline_succeeds -o merge_request.create -o merge_request.remove_source_branch -o merge_request.target="$1" fi } + +function gc() { + if [[ -f "$(git rev-parse --show-toplevel)/.git/COMMIT_EDITMSG" ]]; then + git commit -t "$(git rev-parse --show-toplevel)/.git/COMMIT_EDITMSG" + else + git commit -v + fi +}