๐Ÿ“ฆ William9923 / hook-the-git

A sample repository to try git-hooks feature

โ˜… 0 stars โ‘‚ 0 forks ๐Ÿ‘ 0 watching
๐Ÿ“ฅ Clone https://github.com/William9923/hook-the-git.git
HTTPS git clone https://github.com/William9923/hook-the-git.git
SSH git clone git@github.com:William9923/hook-the-git.git
CLI gh repo clone William9923/hook-the-git
William9923 William9923 refactor(project): edit workflow b18666c 4 years ago ๐Ÿ“ History
๐Ÿ“‚ master View all commits โ†’
๐Ÿ“ .github
๐Ÿ“ cmd
๐Ÿ“ docs
๐Ÿ“ scripts
๐Ÿ“„ .gitignore
๐Ÿ“„ go.mod
๐Ÿ“„ go.sum
๐Ÿ“„ README.md
๐Ÿ“„ run-hookthegit.sh
๐Ÿ“„ runtest.sh
๐Ÿ“„ setup.sh
๐Ÿ“„ README.md

Hook The Git

Why?

To increase the productivity of a developer, I would like to simplify the workflow when trying to develop an application.

One way to do that are by using git hooks. Git hooks are scripts that Git executes before or after events such as: commit, push, and receive. Git hooks are a built-in feature - no need to download anything. Git hooks are run locally.

In this repo, I present to you 4 types of hook that i like to use (pre-commit, commit-msg, pre-push and post-checkout). You could see more details on each hooks here.

Hooks Overview

In this repo, there are 4 hooks that I implemented for Golang (could be used for other programming languange too):
  • pre-commit: Used to apply gofmt & goimports before committing the code.
  • commit-msg: Used to check the format of commit message before commit. Will fail if not suitable from predetermined template
  • pre-push: Used to check with unit test before pushing items into remote repo. But, will pass if commit message contains WIP (work in progress). Also, prevent from accidental push to master.
  • post-checkout: Used to perform dependencies check (vendor, etc) when switching branch.

Prerequisites

  • Golang minimum v1.12 (https://golang.org/doc/install)
  • Go Modules (https://blog.golang.org/using-go-modules)

How to Run

  • Clone the repository
git clone git@github.com:William9923/hook-the-git.git
  • Setup the hooks
sh ./setup.sh
  • (Optional) Run the project
sh ./run-hookthegit.sh
  • (Optional) Run the test
sh ./runtest.sh