Skip to content

chore: prevent commit signing in tests #13222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 10, 2024
Merged

Conversation

dannykopping
Copy link
Contributor

@dannykopping dannykopping commented May 10, 2024

In my workspace, my git config contains this alias:

$ git config -l | grep alias.commit
alias.commit=commit -s

When TestDotfiles is called, it runs git commit which tries to sign the commits and causes my tests to hang and fail. We need to prevent this behaviour.

I tried using GIT_CONFIG_NOSYSTEM, but that doesn't prevent the use of the git config in my home directory.
(source)

This feels like the cleanest approach to me; an alternative would be to override the HOME env var, but that could have other side-effects.

Edit: @mafredri suggesting using GIT_CONFIG_GLOBAL=/dev/nullandGIT_CONFIG_SYSTEM=/dev/null` which solves the problem more elegantly than my original solution.

Signed-off-by: Danny Kopping <danny@coder.com>
@dannykopping dannykopping changed the title Do not attempt to sign commits in tests chore: do not attempt to sign commits in tests May 10, 2024
@dannykopping dannykopping requested review from mafredri, Emyrk and f0ssel May 10, 2024 09:17
@dannykopping dannykopping changed the title chore: do not attempt to sign commits in tests chore: prevent commit signing in tests May 10, 2024
Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

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

Interesting find! How about we set GIT_CONFIG_GLOBAL=/dev/null (and GIT_CONFIG_SYSTEM=/dev/null?) instead? This seems like it would be a more robust approach vs handling any special cases in user configurations?

@dannykopping
Copy link
Contributor Author

Interesting find! How about we set GIT_CONFIG_GLOBAL=/dev/null (and GIT_CONFIG_SYSTEM=/dev/null?) instead? This seems like it would be a more robust approach vs handling any special cases in user configurations?

I believe that it's not using the global config at all, but rather the one from my home dir which it doesn't seem possible to override.

@mafredri
Copy link
Member

I believe that it's not using the global config at all, but rather the one from my home dir which it doesn't seem possible to override.

That's what global is for, to avoid using your home dir config. The system variant is for /etc.

@dannykopping
Copy link
Contributor Author

I believe that it's not using the global config at all, but rather the one from my home dir which it doesn't seem possible to override.

That's what global is for, to avoid using your home dir config. The system variant is for /etc.

Oh interesting! I didn't see GIT_CONFIG_GLOBAL listed in the docs weirdly, but it appears to work

$ git config -l | grep alias.commit
alias.commit=commit -s
$ GIT_CONFIG_GLOBAL=/dev/null git config -l | grep alias.commit
$ 

Signed-off-by: Danny Kopping <danny@coder.com>
@dannykopping dannykopping requested a review from mafredri May 10, 2024 12:57
Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

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

Hmm, interesting. It is described in the man page, though:

   GIT_CONFIG_GLOBAL, GIT_CONFIG_SYSTEM
      Take the configuration from the given files instead from global or system-level configuration files. If
      GIT_CONFIG_SYSTEM is set, the system config file defined at build time (usually /etc/gitconfig) will not be read.
      Likewise, if GIT_CONFIG_GLOBAL is set, neither $HOME/.gitconfig nor $XDG_CONFIG_HOME/git/config will be read. Can be
      set to /dev/null to skip reading configuration files of the respective level.

@dannykopping dannykopping merged commit 989575c into coder:main May 10, 2024
33 checks passed
@dannykopping dannykopping deleted the dk/nosign branch May 10, 2024 14:36
@github-actions github-actions bot locked and limited conversation to collaborators May 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants