aboutsummaryrefslogtreecommitdiffstats
path: root/community/etckeeper/0001-Work-around-git-commit-s-lack-of-robustness-by-provi.patch
blob: 0726f4336279cf019a6266c3052b5c9310eda2e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
From e19e9c51f63fdf6c836310bacf4a7d5caebdd55f Mon Sep 17 00:00:00 2001
From: Joey Hess <joeyh@joeyh.name>
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 <id@joeyh.name>  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