From e19e9c51f63fdf6c836310bacf4a7d5caebdd55f Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 8 Jun 2017 13:26:34 -0400 Subject: [PATCH] Work around git commit's lack of robustness, by providing reasonable default values for GIT_COMMITTER_EMAIL etc. This was already done as part of the su/sudo handling, and is now always done. This commit was sponsored by Trenton Cronholm on Patreon. --- commit.d/50vcs-commit | 9 +++++++- debian/changelog | 9 ++++++++ ...___be_set_under_undocumented_circumstances.mdwn | 2 ++ ...ent_1_f8399058ebbf3059000e6528296cc1e9._comment | 26 ++++++++++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 doc/todo/requires___96__user.email__96___be_set_under_undocumented_circumstances/comment_1_f8399058ebbf3059000e6528296cc1e9._comment diff --git a/commit.d/50vcs-commit b/commit.d/50vcs-commit index 55f0db2..f970d3d 100755 --- a/commit.d/50vcs-commit +++ b/commit.d/50vcs-commit @@ -41,9 +41,16 @@ else fi if [ "$VCS" = git ] && [ -d .git ]; then + # When not su'd to root, still set environment variables, + # since git's own code to determine the author and committer + # has several edge cases where it fails and would prevent the + # commit. + if [ -z "$USER" ]; then + USER="$(whoami)" + fi if [ -n "$USER" ]; then # Use user.name and user.email from the gitconfig belonging - # to the user who became root. + # to USER. USER_HOME="$(getent passwd "$USER" | cut -d: -f6)" if [ -n "$USER_HOME" ] && [ -e "$USER_HOME/.gitconfig" ]; then if [ -z "$GIT_AUTHOR_NAME" ]; then diff --git a/debian/changelog b/debian/changelog index 23783bd..46df223 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,12 @@ +etckeeper (1.18.8) UNRELEASED; urgency=medium + + * Work around git commit's lack of robustness, by providing + reasonable default values for GIT_COMMITTER_EMAIL etc. + This was already done as part of the su/sudo handling, + and is now always done. + + -- Joey Hess Thu, 08 Jun 2017 13:22:01 -0400 + etckeeper (1.18.7) unstable; urgency=medium * Added some unit tests. diff --git a/doc/todo/requires___96__user.email__96___be_set_under_undocumented_circumstances.mdwn b/doc/todo/requires___96__user.email__96___be_set_under_undocumented_circumstances.mdwn index 93177d8..5ddd8ad 100644 --- a/doc/todo/requires___96__user.email__96___be_set_under_undocumented_circumstances.mdwn +++ b/doc/todo/requires___96__user.email__96___be_set_under_undocumented_circumstances.mdwn @@ -34,3 +34,5 @@ This is not Ansible-specific: the last two conditions will also arise in the dai IMO, considering how to document this behaviour shows it to be user-unfriendly. Therefore, it would be simplest if etckeeper could fall back to using `$(id -un)`, once `$(tty)` fails. + +> Set `USER=$(whoami)`, for git only. [[done]] --[[Joey]] diff --git a/doc/todo/requires___96__user.email__96___be_set_under_undocumented_circumstances/comment_1_f8399058ebbf3059000e6528296cc1e9._comment b/doc/todo/requires___96__user.email__96___be_set_under_undocumented_circumstances/comment_1_f8399058ebbf3059000e6528296cc1e9._comment new file mode 100644 index 0000000..16e907f --- /dev/null +++ b/doc/todo/requires___96__user.email__96___be_set_under_undocumented_circumstances/comment_1_f8399058ebbf3059000e6528296cc1e9._comment @@ -0,0 +1,26 @@ +[[!comment format=mdwn + username="joey" + subject="""comment 1""" + date="2017-06-08T17:00:19Z" + content=""" +What actually requires user.email be set under +undocumented circumstances? git does. Personally, I feel this is a total +misfeature on git's part; git commit should succeed under all +configuraations. Every single program that automates `git commit` +is potentially buggy otherwise. + +Anyway, yes, setting `USER=$(id -un)` (or whoami) would make +the code that currently is used to handle sudo users be always +run, and so git and any other VCSs that break in unusual circumstances +would always work (at least as far as username and email goes, who knows +what other requirements VCSs may have). + +The downside is that this could change etckeeper's behavior, since +it would now be guessing at the user name and email, and may make +different choices than git does. + +Setting USER would also impact the code for other VCSs than git. For +example, the code for hg always sets HGUSER when USER is set. I don't know +if the others VCSs are as picky as git; if this kind of breakage is not a +problem for them it might be best to only set USER when using git. +"""]] -- 2.11.0