-
Notifications
You must be signed in to change notification settings - Fork 34
Add git hooks
./godelw git-hooks
installs a Git commit hook that ensures
that all of the files in a project are formatted using ./godelw format
before they are committed (requires the project
to be a Git repository).
-
${GOPATH}/src/${PROJECT_PATH}
exists, is the working directory and is initialized as a Git repository and Go module - Project contains
godel
andgodelw
Install the Git hooks for gödel in the current project by running the following:
➜ ./godelw git-hooks
With the repository initialized and hooks installed, we start writing code. Run the following to generate the initial
version of a main.go
file echoes the arguments provided by the user:
➜ echo 'package main
import "fmt"
import "strings"
import "os"
func main() {
fmt.Println(strings.Join(os.Args[1:], " "))
}' > main.go
This is valid Go that compiles and runs properly:
➜ go run main.go foo
foo
However, if we attempt to add and commit this file to the repository, it will fail:
➜ git add main.go
➜ git commit -m "Add main.go"
Unformatted files exist -- run ./godelw format to format these files:
main.go
This is because the commit hook has determined that main.go
is not formatted properly. We can run ./godelw format
(this is covered in more detail in the Format section of the tutorial)
to format the file and then verify that adding and committing the file works:
➜ ./godelw format
➜ git add main.go
➜ git commit -m "Add main.go"
[master d461fb7] Add main.go
1 file changed, 11 insertions(+)
create mode 100644 main.go
We now have a repository that contains the first version of our echgo2 program and have a commit hook that ensures that all of the code we check in for our program will be properly formatted.
-
${GOPATH}/src/${PROJECT_PATH}
exists, is the working directory and is initialized as a Git repository and Go module - Project contains
godel
andgodelw
- Project contains
main.go
Generate IDE project for GoLand
Running ./godelw git-hooks
will overwrite the .git/hooks/pre-commit
file (including any previous customizations).
The commit hook can be uninstalled by removing the generated commit hook file at .git/hooks/pre-commit
.
- Home
-
Tutorial
- Add gödel to a project
- Add Git hooks to enforce formatting
- Generate IDE project for GoLand
- Format Go files
- Run static checks on code
- Run tests
- Build
- Run
- Dist
- Publish
- Build and push Docker images
- Generate license headers
- Go generate tasks
- Define excludes
- Write integration tests
- Sync a documentation directory with GitHub wiki
- Verify project
- Set up CI to run tasks
- Update gödel
- Update legacy gödel
- Other commands
- Conclusion
- Name
- Philosophy
- Architecture
- Plugins
- Configuration