Skip to content
This repository has been archived by the owner on Sep 12, 2018. It is now read-only.

Adds pre-commit hook, hook config script, and relevant README #856

Merged
merged 1 commit into from
Dec 17, 2014

Conversation

BrianBland
Copy link

The pre-commit hook will automatically gofmt code in place, warning you about any changes. It will also fail to commit if either golint or go vet fails.

As git hooks cannot be added to a repository in a way that automatically applies them, configure-hooks.sh can be ran to link this pre-commit hook.

@dmp42 @stevvooe

cd $REPO_ROOT

GOFMT_CHANGES=$(gofmt -s -l -w . 2>&1)
if [ -n "$GOFMT_CHANGES" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to deviate from the circleci syntax? (eg: maybe it would make maintenance easier down the road if they were "closer"?)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For one, we can actually run gofmt in a way that writes its updates in place pre-commit. Secondly, I want to make sure it's clear to a user why their commit was rejected, which is a lot less obvious without all of the chrome of a CI web interface. We can also port all this syntax over to the circle.yml, but it's not very conducive for complex commands like multiline if-statements.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good enough! Thanks for clarifying Brian. LGTM

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this place the gofmt changes in the index and proceed with the commit? I would prefer that it fails and the results are uncommitted. Also, I am not sure about gating commits on golint. Looking here, it seems like the intent is to make golint quite noisy. This will be problematic when exported APIs migrate from wishes of golint maintainers.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with your concerns about golint, but we're already using it as a gate in our CI setup, so this is no more restrictive. I can also change the gofmt semantics to just fail and complain if you prefer that behavior.

@BrianBland
Copy link
Author

Actually, let me push a fix for this script before you merge this. Just found an edge case.

@BrianBland
Copy link
Author

Alright, I tested this most recent version with various gofmt errors across multiple files and it properly includes the changes in the actual commit.

The pre-commit hook will automatically gofmt code in place, warning you
about any changes. It will also fail to commit if either golint or go
vet fails.
@stevvooe
Copy link
Contributor

Alright, I tested this most recent version with various gofmt errors across multiple files and it properly includes the changes in the actual commit.

Does it give you a change to review the changes before adding them to the commit?

@BrianBland
Copy link
Author

I've removed the auto-fmt behavior in my most recent commit.

@stevvooe
Copy link
Contributor

LGTM!

@stevvooe stevvooe added this to the GO-beta milestone Dec 17, 2014
stevvooe added a commit that referenced this pull request Dec 17, 2014
Adds pre-commit hook, hook config script, and relevant README
@stevvooe stevvooe merged commit b3b5b48 into docker-archive:next-generation Dec 17, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants