Commit aba9c984d1420b77b23320520e70b27ecc83acf7

Stefan Sperling 2019-09-08T17:14:34

obtain repo format version and commit author name/email from .git/config

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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
diff --git a/got/Makefile b/got/Makefile
index 8c1fca6..4d88777 100644
--- a/got/Makefile
+++ b/got/Makefile
@@ -8,7 +8,7 @@ SRCS=		got.c blame.c commit_graph.c delta.c diff.c \
 		object_idset.c object_parse.c opentemp.c path.c pack.c \
 		privsep.c reference.c repository.c sha1.c worktree.c \
 		inflate.c buf.c worklist.c rcsutil.c diff3.c lockfile.c \
-		deflate.c object_create.c gitconfig.c
+		deflate.c object_create.c
 MAN =		${PROG}.1 got-worktree.5 git-repository.5
 
 CPPFLAGS = -I${.CURDIR}/../include -I${.CURDIR}/../lib
diff --git a/got/got.1 b/got/got.1
index 8ff5e09..ba35bfd 100644
--- a/got/got.1
+++ b/got/got.1
@@ -90,7 +90,14 @@ The
 .Cm got import
 command requires the
 .Ev GOT_AUTHOR
-environment variable to be set.
+environment variable to be set,
+unless Git's
+.Dv user.name
+and
+.Dv user.email configuration settings can be
+obtained from the repository's
+.Pa .git/config
+file.
 .Pp
 The options for
 .Cm got import
@@ -690,7 +697,14 @@ The
 .Cm got commit
 command requires the
 .Ev GOT_AUTHOR
-environment variable to be set.
+environment variable to be set,
+unless Git's
+.Dv user.name
+and
+.Dv user.email configuration settings can be
+obtained from the repository's
+.Pa .git/config
+file.
 .Pp
 The options for
 .Cm got commit
@@ -1204,7 +1218,7 @@ The author's name and email address for
 and
 .Cm got import ,
 for example:
-.An Flan Hacker Aq Mt flan_hacker@openbsd.org .
+.Dq An Flan Hacker Aq Mt flan_hacker@openbsd.org .
 Because
 .Xr git 1
 may fail to parse commits without an email address in author data,
@@ -1212,6 +1226,13 @@ may fail to parse commits without an email address in author data,
 attempts to reject
 .Ev GOT_AUTHOR
 environment variables with a missing email address.
+Git's
+.Dv user.name
+and
+.Dv user.email configuration settings in the repository's
+.Pa .git/config
+file will override the value of
+.Ev GOT_AUTHOR .
 .It Ev VISUAL , EDITOR
 The editor spawned by
 .Cm got commit ,
diff --git a/got/got.c b/got/got.c
index 4c8177b..5f37798 100644
--- a/got/got.c
+++ b/got/got.c
@@ -492,19 +492,31 @@ import_progress(void *arg, const char *path)
 }
 
 static const struct got_error *
-get_author(const char **author)
+get_author(char **author, struct got_repository *repo)
 {
-	const char *got_author;
+	const struct got_error *err = NULL;
+	const char *got_author, *gitconfig_name, *gitconfig_email;
 
 	*author = NULL;
 
+	gitconfig_name = got_repo_get_gitconfig_author_name(repo);
+	gitconfig_email = got_repo_get_gitconfig_author_email(repo);
+	if (gitconfig_name && gitconfig_email) {
+		if (asprintf(author, "%s <%s>",
+		    gitconfig_name, gitconfig_email) == -1)
+			return got_error_from_errno("asprintf");
+		return NULL;
+	}
+
 	got_author = getenv("GOT_AUTHOR");
 	if (got_author == NULL) {
 		/* TODO: Look up user in password database? */
 		return got_error(GOT_ERR_COMMIT_NO_AUTHOR);
 	}
 
-	*author = got_author;
+	*author = strdup(got_author);
+	if (*author == NULL)
+		return got_error_from_errno("strdup");
 
 	/*
 	 * Really dumb email address check; we're only doing this to
@@ -512,18 +524,26 @@ get_author(const char **author)
 	 */
 	while (*got_author && *got_author != '<')
 		got_author++;
-	if (*got_author != '<')
-		return got_error(GOT_ERR_COMMIT_NO_EMAIL);
+	if (*got_author != '<') {
+		err = got_error(GOT_ERR_COMMIT_NO_EMAIL);
+		goto done;
+	}
 	while (*got_author && *got_author != '@')
 		got_author++;
-	if (*got_author != '@')
-		return got_error(GOT_ERR_COMMIT_NO_EMAIL);
+	if (*got_author != '@') {
+		err = got_error(GOT_ERR_COMMIT_NO_EMAIL);
+		goto done;
+	}
 	while (*got_author && *got_author != '>')
 		got_author++;
 	if (*got_author != '>')
-		return got_error(GOT_ERR_COMMIT_NO_EMAIL);
-
-	return NULL;
+		err = got_error(GOT_ERR_COMMIT_NO_EMAIL);
+done:
+	if (err) {
+		free(*author);
+		*author = NULL;
+	}
+	return err;
 }
 
 static const struct got_error *
@@ -531,8 +551,7 @@ cmd_import(int argc, char *argv[])
 {
 	const struct got_error *error = NULL;
 	char *path_dir = NULL, *repo_path = NULL, *logmsg = NULL;
-	char *editor = NULL;
-	const char *author;
+	char *editor = NULL, *author = NULL;
 	const char *branch_name = "master";
 	char *refname = NULL, *id_str = NULL;
 	struct got_repository *repo = NULL;
@@ -581,17 +600,14 @@ cmd_import(int argc, char *argv[])
 	argv += optind;
 
 #ifndef PROFILE
-	if (pledge("stdio rpath wpath cpath fattr flock proc exec unveil",
+	if (pledge("stdio rpath wpath cpath fattr flock proc exec sendfd "
+	    "unveil",
 	    NULL) == -1)
 		err(1, "pledge");
 #endif
 	if (argc != 1)
 		usage_import();
 
-	error = get_author(&author);
-	if (error)
-		return error;
-
 	if (repo_path == NULL) {
 		repo_path = getcwd(NULL, 0);
 		if (repo_path == NULL)
@@ -602,6 +618,10 @@ cmd_import(int argc, char *argv[])
 	if (error)
 		goto done;
 
+	error = get_author(&author, repo);
+	if (error)
+		return error;
+
 	if (asprintf(&refname, "refs/heads/%s", branch_name) == -1) {
 		error = got_error_from_errno("asprintf");
 		goto done;
@@ -684,6 +704,7 @@ done:
 	free(refname);
 	free(new_commit_id);
 	free(id_str);
+	free(author);
 	if (branch_ref)
 		got_ref_close(branch_ref);
 	if (head_ref)
@@ -3659,8 +3680,7 @@ add_tag(struct got_repository *repo, const char *tag_name,
 	struct got_object_id *commit_id = NULL, *tag_id = NULL;
 	char *label = NULL, *commit_id_str = NULL;
 	struct got_reference *ref = NULL;
-	char *refname = NULL, *tagmsg = NULL;
-	const char *tagger;
+	char *refname = NULL, *tagmsg = NULL, *tagger = NULL;
 
 	/*
 	 * Don't let the user create a tag named '-'.
@@ -3670,7 +3690,7 @@ add_tag(struct got_repository *repo, const char *tag_name,
 	if (tag_name[0] == '-' && tag_name[1] == '\0')
 		return got_error(GOT_ERR_BAD_REF_NAME);
 
-	err = get_author(&tagger);
+	err = get_author(&tagger, repo);
 	if (err)
 		return err;
 
@@ -3733,6 +3753,7 @@ done:
 	free(commit_id_str);
 	free(refname);
 	free(tagmsg);
+	free(tagger);
 	return err;
 }
 
@@ -4384,9 +4405,8 @@ cmd_commit(int argc, char *argv[])
 	char *cwd = NULL, *id_str = NULL;
 	struct got_object_id *id = NULL;
 	const char *logmsg = NULL;
-	const char *author;
 	struct collect_commit_logmsg_arg cl_arg;
-	char *editor = NULL;
+	char *editor = NULL, *author = NULL;
 	int ch, rebase_in_progress, histedit_in_progress;
 	struct got_pathlist_head paths;
 
@@ -4412,10 +4432,6 @@ cmd_commit(int argc, char *argv[])
 	    "unveil", NULL) == -1)
 		err(1, "pledge");
 #endif
-	error = get_author(&author);
-	if (error)
-		return error;
-
 	cwd = getcwd(NULL, 0);
 	if (cwd == NULL) {
 		error = got_error_from_errno("getcwd");
@@ -4442,6 +4458,10 @@ cmd_commit(int argc, char *argv[])
 	if (error != NULL)
 		goto done;
 
+	error = get_author(&author, repo);
+	if (error)
+		return error;
+
 	/*
 	 * unveil(2) traverses exec(2); if an editor is used we have
 	 * to apply unveil after the log message has been written.
@@ -4495,6 +4515,7 @@ done:
 	free(cwd);
 	free(id_str);
 	free(editor);
+	free(author);
 	return error;
 }
 
diff --git a/include/got_error.h b/include/got_error.h
index 97f0473..f8e9822 100644
--- a/include/got_error.h
+++ b/include/got_error.h
@@ -123,6 +123,7 @@
 #define GOT_ERR_PATCH_CHOICE	107
 #define GOT_ERR_COMMIT_NO_EMAIL	108
 #define GOT_ERR_TAG_EXISTS	109
+#define GOT_ERR_GIT_REPO_FORMAT	110
 
 static const struct got_error {
 	int code;
@@ -252,6 +253,7 @@ static const struct got_error {
 	    "no email address; an email address is required for compatibility "
 	    "with Git" },
 	{ GOT_ERR_TAG_EXISTS,"specified tag already exists" },
+	{ GOT_ERR_GIT_REPO_FORMAT,"unknown git repository format version" },
 };
 
 /*
diff --git a/include/got_repository.h b/include/got_repository.h
index 16cdca5..f2ecc74 100644
--- a/include/got_repository.h
+++ b/include/got_repository.h
@@ -31,6 +31,12 @@ const char *got_repo_get_path(struct got_repository *);
  */
 const char *got_repo_get_path_git_dir(struct got_repository *);
 
+/* Obtain the commit author name if parsed from gitconfig, else NULL. */
+const char *got_repo_get_gitconfig_author_name(struct got_repository *);
+
+/* Obtain the commit author email if parsed from gitconfig, else NULL. */
+const char *got_repo_get_gitconfig_author_email(struct got_repository *);
+
 /*
  * Obtain paths to various directories within a repository.
  * The caller must dispose of a path with free(3).
diff --git a/lib/gitconfig.c b/lib/gitconfig.c
index 754cbc5..1ddfb97 100644
--- a/lib/gitconfig.c
+++ b/lib/gitconfig.c
@@ -307,7 +307,7 @@ conf_parse(struct got_gitconfig *conf, int trans, char *buf, size_t sz)
 }
 
 const struct got_error *
-got_gitconfig_open(struct got_gitconfig **conf, const char *gitconfig_path)
+got_gitconfig_open(struct got_gitconfig **conf, int fd)
 {
 	unsigned int i;
 
@@ -318,7 +318,7 @@ got_gitconfig_open(struct got_gitconfig **conf, const char *gitconfig_path)
 	for (i = 0; i < nitems((*conf)->bindings); i++)
 		LIST_INIT(&(*conf)->bindings[i]);
 	TAILQ_INIT(&(*conf)->trans_queue);
-	return got_gitconfig_reinit(*conf, gitconfig_path);
+	return got_gitconfig_reinit(*conf, fd);
 }
 
 static void
@@ -390,23 +390,16 @@ conf_begin(struct got_gitconfig *conf)
 
 /* Open the config file and map it into our address space, then parse it.  */
 const struct got_error *
-got_gitconfig_reinit(struct got_gitconfig *conf, const char *gitconfig_path)
+got_gitconfig_reinit(struct got_gitconfig *conf, int fd)
 {
 	const struct got_error *err = NULL;
-	int	 fd, trans;
+	int	 trans;
 	size_t	 sz;
 	char	*new_conf_addr = 0;
 	struct stat st;
 
-	fd = open(gitconfig_path, O_RDONLY, 0);
-	if (fd == -1) {
-		if (errno != ENOENT)
-			return got_error_from_errno2("open", gitconfig_path);
-		return NULL;
-	}
-
 	if (fstat(fd, &st)) {
-		err = got_error_from_errno2("fstat", gitconfig_path);
+		err = got_error_from_errno("fstat");
 		goto fail;
 	}
 
@@ -421,8 +414,6 @@ got_gitconfig_reinit(struct got_gitconfig *conf, const char *gitconfig_path)
 		err = got_error_from_errno("read");
 		goto fail;
 	}
-	close(fd);
-	fd = -1;
 
 	trans = conf_begin(conf);
 
@@ -438,8 +429,6 @@ got_gitconfig_reinit(struct got_gitconfig *conf, const char *gitconfig_path)
 
 fail:
 	free(new_conf_addr);
-	if (fd != -1)
-		close(fd);
 	return err;
 }
 
diff --git a/lib/got_lib_gitconfig.h b/lib/got_lib_gitconfig.h
index 828787b..4d61ab3 100644
--- a/lib/got_lib_gitconfig.h
+++ b/lib/got_lib_gitconfig.h
@@ -39,15 +39,17 @@ struct got_gitconfig_list {
 struct got_gitconfig;
 
 void     got_gitconfig_free_list(struct got_gitconfig_list *);
-struct got_gitconfig_list *got_gitconfig_get_list(struct got_gitconfig *, char *, char *);
+struct got_gitconfig_list *got_gitconfig_get_list(struct got_gitconfig *,
+    char *, char *);
 struct got_gitconfig_list *got_gitconfig_get_tag_list(struct got_gitconfig *, char *);
-int got_gitconfig_get_num(struct got_gitconfig *, char *, char *, int);
-char *got_gitconfig_get_str(struct got_gitconfig *, char *, char *);
-const struct got_error *got_gitconfig_open(struct got_gitconfig **,
-    const char *);
+int got_gitconfig_get_num(struct got_gitconfig *, char *, char *,
+    int);
+char *got_gitconfig_get_str(struct got_gitconfig *, char *,
+    char *);
+const struct got_error *got_gitconfig_open(struct got_gitconfig **, int);
 void got_gitconfig_close(struct got_gitconfig *);
 int      got_gitconfig_match_num(struct got_gitconfig *, char *, char *, int);
-const struct got_error *got_gitconfig_reinit(struct got_gitconfig *, const char *);
+const struct got_error *got_gitconfig_reinit(struct got_gitconfig *, int);
 int      got_gitconfig_remove(struct got_gitconfig *, int, char *, char *);
 int      got_gitconfig_remove_section(struct got_gitconfig *, int, char *);
 int      got_gitconfig_set(struct got_gitconfig *, int, char *, char *, char *, int, int);
diff --git a/lib/got_lib_privsep.h b/lib/got_lib_privsep.h
index 1ad8832..f1e7f2a 100644
--- a/lib/got_lib_privsep.h
+++ b/lib/got_lib_privsep.h
@@ -41,6 +41,7 @@
 #define GOT_PROG_READ_BLOB	got-read-blob
 #define GOT_PROG_READ_TAG	got-read-tag
 #define GOT_PROG_READ_PACK	got-read-pack
+#define GOT_PROG_READ_GITCONFIG	got-read-gitconfig
 
 #define GOT_STRINGIFY(x) #x
 #define GOT_STRINGVAL(x) GOT_STRINGIFY(x)
@@ -58,6 +59,8 @@
 	GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_READ_TAG)
 #define GOT_PATH_PROG_READ_PACK \
 	GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_READ_PACK)
+#define GOT_PATH_PROG_READ_GITCONFIG \
+	GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_READ_GITCONFIG)
 
 struct got_privsep_child {
 	int imsg_fd;
@@ -102,6 +105,14 @@ enum got_imsg_type {
 
 	/* Message sending file descriptor to a temporary file. */
 	GOT_IMSG_TMPFD,
+
+	/* Messages related to gitconfig files. */
+	GOT_IMSG_GITCONFIG_PARSE_REQUEST,
+	GOT_IMSG_GITCONFIG_REPOSITORY_FORMAT_VERSION_REQUEST,
+	GOT_IMSG_GITCONFIG_AUTHOR_NAME_REQUEST,
+	GOT_IMSG_GITCONFIG_AUTHOR_EMAIL_REQUEST,
+	GOT_IMSG_GITCONFIG_INT_VAL,
+	GOT_IMSG_GITCONFIG_STR_VAL,
 };
 
 /* Structure for GOT_IMSG_ERROR. */
@@ -264,3 +275,20 @@ const struct got_error *got_privsep_init_pack_child(struct imsgbuf *,
 const struct got_error *got_privsep_send_packed_obj_req(struct imsgbuf *, int,
     struct got_object_id *);
 const struct got_error *got_privsep_send_pack_child_ready(struct imsgbuf *);
+
+const struct got_error *got_privsep_send_gitconfig_parse_req(struct imsgbuf *,
+    int);
+const struct got_error *
+    got_privsep_send_gitconfig_repository_format_version_req(struct imsgbuf *);
+const struct got_error *got_privsep_send_gitconfig_author_name_req(
+    struct imsgbuf *);
+const struct got_error *got_privsep_send_gitconfig_author_email_req(
+    struct imsgbuf *);
+const struct got_error *got_privsep_send_gitconfig_str(struct imsgbuf *,
+    const char *);
+const struct got_error *got_privsep_recv_gitconfig_str(char **,
+    struct imsgbuf *);
+const struct got_error *got_privsep_send_gitconfig_int(struct imsgbuf *, int);
+const struct got_error *got_privsep_recv_gitconfig_int(int *, struct imsgbuf *);
+
+void got_privsep_exec_child(int[2], const char *, const char *);
diff --git a/lib/got_lib_repository.h b/lib/got_lib_repository.h
index 23ca2d5..71d6c05 100644
--- a/lib/got_lib_repository.h
+++ b/lib/got_lib_repository.h
@@ -42,7 +42,9 @@ struct got_repository {
 	struct got_object_cache tagcache;
 
 	/* Settings read from Git configuration files. */
-	struct got_gitconfig *gitconfig;
+	int gitconfig_repository_format_version;
+	char *gitconfig_author_name;
+	char *gitconfig_author_email;
 };
 
 const struct got_error*got_repo_cache_object(struct got_repository *,
diff --git a/lib/object.c b/lib/object.c
index e5c043c..ca9b147 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -181,30 +181,6 @@ get_packfile_path(char **path_packfile, struct got_packidx *packidx)
 	return NULL;
 }
 
-static void
-exec_privsep_child(int imsg_fds[2], const char *path, const char *repo_path)
-{
-	if (close(imsg_fds[0]) != 0) {
-		fprintf(stderr, "%s: %s\n", getprogname(), strerror(errno));
-		_exit(1);
-	}
-
-	if (dup2(imsg_fds[1], GOT_IMSG_FD_CHILD) == -1) {
-		fprintf(stderr, "%s: %s\n", getprogname(), strerror(errno));
-		_exit(1);
-	}
-	if (closefrom(GOT_IMSG_FD_CHILD + 1) == -1) {
-		fprintf(stderr, "%s: %s\n", getprogname(), strerror(errno));
-		_exit(1);
-	}
-
-	if (execl(path, path, repo_path, (char *)NULL) == -1) {
-		fprintf(stderr, "%s: %s: %s\n", getprogname(), path,
-		    strerror(errno));
-		_exit(1);
-	}
-}
-
 static const struct got_error *
 request_packed_object(struct got_object **obj, struct got_pack *pack, int idx,
     struct got_object_id *id)
@@ -272,7 +248,7 @@ start_pack_privsep_child(struct got_pack *pack, struct got_packidx *packidx)
 		goto done;
 	} else if (pid == 0) {
 		set_max_datasize();
-		exec_privsep_child(imsg_fds, GOT_PATH_PROG_READ_PACK,
+		got_privsep_exec_child(imsg_fds, GOT_PATH_PROG_READ_PACK,
 		    pack->path_packfile);
 		/* not reached */
 	}
@@ -392,7 +368,7 @@ read_object_header_privsep(struct got_object **obj, struct got_repository *repo,
 	if (pid == -1)
 		return got_error_from_errno("fork");
 	else if (pid == 0) {
-		exec_privsep_child(imsg_fds, GOT_PATH_PROG_READ_OBJECT,
+		got_privsep_exec_child(imsg_fds, GOT_PATH_PROG_READ_OBJECT,
 		    repo->path);
 		/* not reached */
 	}
@@ -557,7 +533,7 @@ read_commit_privsep(struct got_commit_object **commit, int obj_fd,
 	if (pid == -1)
 		return got_error_from_errno("fork");
 	else if (pid == 0) {
-		exec_privsep_child(imsg_fds, GOT_PATH_PROG_READ_COMMIT,
+		got_privsep_exec_child(imsg_fds, GOT_PATH_PROG_READ_COMMIT,
 		    repo->path);
 		/* not reached */
 	}
@@ -736,7 +712,7 @@ read_tree_privsep(struct got_tree_object **tree, int obj_fd,
 	if (pid == -1)
 		return got_error_from_errno("fork");
 	else if (pid == 0) {
-		exec_privsep_child(imsg_fds, GOT_PATH_PROG_READ_TREE,
+		got_privsep_exec_child(imsg_fds, GOT_PATH_PROG_READ_TREE,
 		    repo->path);
 		/* not reached */
 	}
@@ -957,7 +933,7 @@ read_blob_privsep(uint8_t **outbuf, size_t *size, size_t *hdrlen,
 	if (pid == -1)
 		return got_error_from_errno("fork");
 	else if (pid == 0) {
-		exec_privsep_child(imsg_fds, GOT_PATH_PROG_READ_BLOB,
+		got_privsep_exec_child(imsg_fds, GOT_PATH_PROG_READ_BLOB,
 		    repo->path);
 		/* not reached */
 	}
@@ -1293,7 +1269,7 @@ read_tag_privsep(struct got_tag_object **tag, int obj_fd,
 	if (pid == -1)
 		return got_error_from_errno("fork");
 	else if (pid == 0) {
-		exec_privsep_child(imsg_fds, GOT_PATH_PROG_READ_TAG,
+		got_privsep_exec_child(imsg_fds, GOT_PATH_PROG_READ_TAG,
 		    repo->path);
 		/* not reached */
 	}
diff --git a/lib/privsep.c b/lib/privsep.c
index f1ce37f..f9961bf 100644
--- a/lib/privsep.c
+++ b/lib/privsep.c
@@ -1216,6 +1216,147 @@ got_privsep_send_packed_obj_req(struct imsgbuf *ibuf, int idx,
 }
 
 const struct got_error *
+got_privsep_send_gitconfig_parse_req(struct imsgbuf *ibuf, int fd)
+{
+	const struct got_error *err = NULL;
+
+	if (imsg_compose(ibuf, GOT_IMSG_GITCONFIG_PARSE_REQUEST, 0, 0, fd,
+	    NULL, 0) == -1) {
+		err = got_error_from_errno("imsg_compose "
+		    "GITCONFIG_PARSE_REQUEST");
+		close(fd);
+		return err;
+	}
+
+	return flush_imsg(ibuf);
+}
+
+const struct got_error *
+got_privsep_send_gitconfig_repository_format_version_req(struct imsgbuf *ibuf)
+{
+	if (imsg_compose(ibuf,
+	    GOT_IMSG_GITCONFIG_REPOSITORY_FORMAT_VERSION_REQUEST, 0, 0, -1,
+	    NULL, 0) == -1)
+		return got_error_from_errno("imsg_compose "
+		    "GITCONFIG_REPOSITORY_FORMAT_VERSION_REQUEST");
+
+	return flush_imsg(ibuf);
+}
+
+const struct got_error *
+got_privsep_send_gitconfig_author_name_req(struct imsgbuf *ibuf)
+{
+	if (imsg_compose(ibuf,
+	    GOT_IMSG_GITCONFIG_AUTHOR_NAME_REQUEST, 0, 0, -1, NULL, 0) == -1)
+		return got_error_from_errno("imsg_compose "
+		    "GITCONFIG_AUTHOR_NAME_REQUEST");
+
+	return flush_imsg(ibuf);
+}
+
+const struct got_error *
+got_privsep_send_gitconfig_author_email_req(struct imsgbuf *ibuf)
+{
+	if (imsg_compose(ibuf,
+	    GOT_IMSG_GITCONFIG_AUTHOR_EMAIL_REQUEST, 0, 0, -1, NULL, 0) == -1)
+		return got_error_from_errno("imsg_compose "
+		    "GITCONFIG_AUTHOR_EMAIL_REQUEST");
+
+	return flush_imsg(ibuf);
+}
+
+const struct got_error *
+got_privsep_send_gitconfig_str(struct imsgbuf *ibuf, const char *value)
+{
+	size_t len = value ? strlen(value) + 1 : 0;
+
+	if (imsg_compose(ibuf, GOT_IMSG_GITCONFIG_STR_VAL, 0, 0, -1,
+	    value, len) == -1)
+		return got_error_from_errno("imsg_compose GITCONFIG_STR_VAL");
+
+	return flush_imsg(ibuf);
+}
+
+const struct got_error *
+got_privsep_recv_gitconfig_str(char **str, struct imsgbuf *ibuf)
+{
+	const struct got_error *err = NULL;
+	struct imsg imsg;
+	size_t datalen;
+	const size_t min_datalen = 0;
+
+	*str = NULL;
+
+	err = got_privsep_recv_imsg(&imsg, ibuf, min_datalen);
+	if (err)
+		return err;
+	datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
+
+	switch (imsg.hdr.type) {
+	case GOT_IMSG_GITCONFIG_STR_VAL:
+		if (datalen == 0)
+			break;
+		*str = malloc(datalen);
+		if (*str == NULL) {
+			err = got_error_from_errno("malloc");
+			break;
+		}
+		if (strlcpy(*str, imsg.data, datalen) >= datalen)
+			err = got_error(GOT_ERR_NO_SPACE);
+		break;
+	default:
+		err = got_error(GOT_ERR_PRIVSEP_MSG);
+		break;
+	}
+
+	imsg_free(&imsg);
+	return err;
+}
+
+const struct got_error *
+got_privsep_send_gitconfig_int(struct imsgbuf *ibuf, int value)
+{
+	if (imsg_compose(ibuf, GOT_IMSG_GITCONFIG_INT_VAL, 0, 0, -1,
+	    &value, sizeof(value)) == -1)
+		return got_error_from_errno("imsg_compose GITCONFIG_INT_VAL");
+
+	return flush_imsg(ibuf);
+}
+
+const struct got_error *
+got_privsep_recv_gitconfig_int(int *val, struct imsgbuf *ibuf)
+{
+	const struct got_error *err = NULL;
+	struct imsg imsg;
+	size_t datalen;
+	const size_t min_datalen =
+	    MIN(sizeof(struct got_imsg_error), sizeof(int));
+
+	*val = 0;
+
+	err = got_privsep_recv_imsg(&imsg, ibuf, min_datalen);
+	if (err)
+		return err;
+	datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
+
+	switch (imsg.hdr.type) {
+	case GOT_IMSG_GITCONFIG_INT_VAL:
+		if (datalen != sizeof(*val)) {
+			err = got_error(GOT_ERR_PRIVSEP_LEN);
+			break;
+		}
+		memcpy(val, imsg.data, sizeof(*val));
+		break;
+	default:
+		err = got_error(GOT_ERR_PRIVSEP_MSG);
+		break;
+	}
+
+	imsg_free(&imsg);
+	return err;
+}
+
+const struct got_error *
 got_privsep_unveil_exec_helpers(void)
 {
 	const char *helpers[] = {
@@ -1225,6 +1366,7 @@ got_privsep_unveil_exec_helpers(void)
 	    GOT_PATH_PROG_READ_TREE,
 	    GOT_PATH_PROG_READ_BLOB,
 	    GOT_PATH_PROG_READ_TAG,
+	    GOT_PATH_PROG_READ_GITCONFIG,
 	};
 	int i;
 
@@ -1236,3 +1378,27 @@ got_privsep_unveil_exec_helpers(void)
 
 	return NULL;
 }
+
+void
+got_privsep_exec_child(int imsg_fds[2], const char *path, const char *repo_path)
+{
+	if (close(imsg_fds[0]) != 0) {
+		fprintf(stderr, "%s: %s\n", getprogname(), strerror(errno));
+		_exit(1);
+	}
+
+	if (dup2(imsg_fds[1], GOT_IMSG_FD_CHILD) == -1) {
+		fprintf(stderr, "%s: %s\n", getprogname(), strerror(errno));
+		_exit(1);
+	}
+	if (closefrom(GOT_IMSG_FD_CHILD + 1) == -1) {
+		fprintf(stderr, "%s: %s\n", getprogname(), strerror(errno));
+		_exit(1);
+	}
+
+	if (execl(path, path, repo_path, (char *)NULL) == -1) {
+		fprintf(stderr, "%s: %s: %s\n", getprogname(), path,
+		    strerror(errno));
+		_exit(1);
+	}
+}
diff --git a/lib/repository.c b/lib/repository.c
index dbee69b..454319a 100644
--- a/lib/repository.c
+++ b/lib/repository.c
@@ -17,6 +17,7 @@
 #include <sys/types.h>
 #include <sys/queue.h>
 #include <sys/uio.h>
+#include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/mman.h>
 #include <sys/syslimits.h>
@@ -56,7 +57,6 @@
 #include "got_lib_sha1.h"
 #include "got_lib_object_cache.h"
 #include "got_lib_repository.h"
-#include "got_lib_gitconfig.h"
 
 #ifndef nitems
 #define nitems(_a) (sizeof(_a) / sizeof((_a)[0]))
@@ -88,6 +88,19 @@ got_repo_get_path_git_dir(struct got_repository *repo)
 	return repo->path_git_dir;
 }
 
+const char *
+got_repo_get_gitconfig_author_name(struct got_repository *repo)
+{
+	return repo->gitconfig_author_name;
+}
+
+/* Obtain the commit author email address parsed from gitconfig. */
+const char *
+got_repo_get_gitconfig_author_email(struct got_repository *repo)
+{
+	return repo->gitconfig_author_email;
+}
+
 int
 got_repo_is_bare(struct got_repository *repo)
 {
@@ -337,12 +350,117 @@ done:
 	return err;
 }
 
+static const struct got_error *
+read_gitconfig(struct got_repository *repo)
+{
+	const struct got_error *err = NULL, *child_err = NULL;
+	char *gitconfig_path = NULL;
+	int fd = -1;
+	int imsg_fds[2] = { -1, -1 };
+	pid_t pid;
+	struct imsgbuf *ibuf;
+
+	/* TODO: Read settings from ~/.gitconfig as well? */
+
+	/* Read repository's .git/config file. */
+	err = get_path_gitconfig(&gitconfig_path, repo);
+	if (err)
+		return err;
+
+	fd = open(gitconfig_path, O_RDONLY);
+	if (fd == -1) {
+		if (errno == ENOENT) {
+			free(gitconfig_path);
+			return NULL;
+		}
+		err = got_error_from_errno2("open", gitconfig_path);
+		free(gitconfig_path);
+		return err;
+	}
+
+	ibuf = calloc(1, sizeof(*ibuf));
+	if (ibuf == NULL) {
+		err = got_error_from_errno("calloc");
+		goto done;
+	}
+
+	if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, imsg_fds) == -1) {
+		err = got_error_from_errno("socketpair");
+		goto done;
+	}
+
+	pid = fork();
+	if (pid == -1) {
+		err = got_error_from_errno("fork");
+		goto done;
+	} else if (pid == 0) {
+		got_privsep_exec_child(imsg_fds, GOT_PATH_PROG_READ_GITCONFIG,
+		    repo->path);
+		/* not reached */
+	}
+
+	if (close(imsg_fds[1]) == -1) {
+		err = got_error_from_errno("close");
+		goto done;
+	}
+	imsg_fds[1] = -1;
+	imsg_init(ibuf, imsg_fds[0]);
+
+	err = got_privsep_send_gitconfig_parse_req(ibuf, fd);
+	if (err)
+		goto done;
+	fd = -1;
+
+	err = got_privsep_send_gitconfig_repository_format_version_req(ibuf);
+	if (err)
+		goto done;
+
+	err = got_privsep_recv_gitconfig_int(
+	    &repo->gitconfig_repository_format_version, ibuf);
+	if (err)
+		goto done;
+
+	err = got_privsep_send_gitconfig_author_name_req(ibuf);
+	if (err)
+		goto done;
+
+	err = got_privsep_recv_gitconfig_str(&repo->gitconfig_author_name,
+	    ibuf);
+	if (err)
+		goto done;
+
+	err = got_privsep_send_gitconfig_author_email_req(ibuf);
+	if (err)
+		goto done;
+
+	err = got_privsep_recv_gitconfig_str(&repo->gitconfig_author_email,
+	    ibuf);
+	if (err)
+		goto done;
+
+	imsg_clear(ibuf);
+	err = got_privsep_send_stop(imsg_fds[0]);
+	child_err = got_privsep_wait_for_child(pid);
+	if (child_err && err == NULL)
+		err = child_err;
+done:
+	if (imsg_fds[0] != -1 && close(imsg_fds[0]) == -1 && err == NULL)
+		err = got_error_from_errno("close");
+	if (imsg_fds[1] != -1 && close(imsg_fds[1]) == -1 && err == NULL)
+		err = got_error_from_errno("close");
+	if (fd != -1 && close(fd) == -1 && err == NULL)
+		err = got_error_from_errno2("close", gitconfig_path);
+	free(gitconfig_path);
+	free(ibuf);
+	return err;
+}
+
 const struct got_error *
 got_repo_open(struct got_repository **repop, const char *path)
 {
 	struct got_repository *repo = NULL;
 	const struct got_error *err = NULL;
-	char *abspath, *gitconfig_path = NULL;
+	char *abspath;
 	int i, tried_root = 0;
 
 	*repop = NULL;
@@ -409,24 +527,17 @@ got_repo_open(struct got_repository **repop, const char *path)
 		}
 	} while (path);
 
-	err = get_path_gitconfig(&gitconfig_path, repo);
-	if (err)
-		goto done;
-
-#ifdef notyet
-	err = got_gitconfig_open(&repo->gitconfig, gitconfig_path);
+	err = read_gitconfig(repo);
 	if (err)
 		goto done;
-#else
-	repo->gitconfig = NULL;
-#endif
+	if (repo->gitconfig_repository_format_version != 0)
+		err = got_error_path(path, GOT_ERR_GIT_REPO_FORMAT);
 done:
 	if (err)
 		got_repo_close(repo);
 	else
 		*repop = repo;
 	free(abspath);
-	free(gitconfig_path);
 	return err;
 }
 
@@ -470,8 +581,9 @@ got_repo_close(struct got_repository *repo)
 		    err == NULL)
 			err = got_error_from_errno("close");
 	}
-	if (repo->gitconfig)
-		got_gitconfig_close(repo->gitconfig);
+
+	free(repo->gitconfig_author_name);
+	free(repo->gitconfig_author_email);
 	free(repo);
 
 	return err;
diff --git a/libexec/Makefile b/libexec/Makefile
index f56d567..a4c900b 100644
--- a/libexec/Makefile
+++ b/libexec/Makefile
@@ -1,4 +1,4 @@
 SUBDIR = got-read-blob got-read-commit got-read-object got-read-tree \
-	got-read-tag got-read-pack
+	got-read-tag got-read-pack got-read-gitconfig
 
 .include <bsd.subdir.mk>
diff --git a/libexec/got-read-gitconfig/Makefile b/libexec/got-read-gitconfig/Makefile
new file mode 100644
index 0000000..f49bf06
--- /dev/null
+++ b/libexec/got-read-gitconfig/Makefile
@@ -0,0 +1,13 @@
+.PATH:${.CURDIR}/../../lib
+
+.include "../../got-version.mk"
+
+PROG=		got-read-gitconfig
+SRCS=		got-read-gitconfig.c error.c inflate.c object_parse.c \
+		path.c privsep.c sha1.c gitconfig.c
+
+CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
+LDADD = -lutil -lz
+DPADD = ${LIBZ} ${LIBUTIL}
+
+.include <bsd.prog.mk>
diff --git a/libexec/got-read-gitconfig/got-read-gitconfig.c b/libexec/got-read-gitconfig/got-read-gitconfig.c
new file mode 100644
index 0000000..c14f37d
--- /dev/null
+++ b/libexec/got-read-gitconfig/got-read-gitconfig.c
@@ -0,0 +1,175 @@
+/*
+ * Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include <sys/queue.h>
+#include <sys/uio.h>
+#include <sys/time.h>
+#include <sys/syslimits.h>
+
+#include <stdint.h>
+#include <imsg.h>
+#include <limits.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sha1.h>
+#include <zlib.h>
+
+#include "got_error.h"
+#include "got_object.h"
+
+#include "got_lib_delta.h"
+#include "got_lib_object.h"
+#include "got_lib_privsep.h"
+#include "got_lib_gitconfig.h"
+
+static volatile sig_atomic_t sigint_received;
+
+static void
+catch_sigint(int signo)
+{
+	sigint_received = 1;
+}
+
+static const struct got_error *
+gitconfig_num_request(struct imsgbuf *ibuf, struct got_gitconfig *gitconfig,
+    char *section, char *tag, int def)
+{
+	int value;
+
+	if (gitconfig == NULL)
+		return got_error(GOT_ERR_PRIVSEP_MSG);
+
+	value = got_gitconfig_get_num(gitconfig, section, tag, def);
+	return got_privsep_send_gitconfig_int(ibuf, value);
+}
+
+static const struct got_error *
+gitconfig_str_request(struct imsgbuf *ibuf, struct got_gitconfig *gitconfig,
+    char *section, char *tag)
+{
+	char *value;
+
+	if (gitconfig == NULL)
+		return got_error(GOT_ERR_PRIVSEP_MSG);
+
+	value = got_gitconfig_get_str(gitconfig, section, tag);
+	return got_privsep_send_gitconfig_str(ibuf, value);
+}
+
+int
+main(int argc, char *argv[])
+{
+	const struct got_error *err = NULL;
+	struct imsgbuf ibuf;
+	size_t datalen;
+	struct got_gitconfig *gitconfig = NULL;
+#if 0
+	static int attached;
+
+	while (!attached)
+		sleep(1);
+#endif
+	signal(SIGINT, catch_sigint);
+
+	imsg_init(&ibuf, GOT_IMSG_FD_CHILD);
+
+#ifndef PROFILE
+	/* revoke access to most system calls */
+	if (pledge("stdio recvfd", NULL) == -1) {
+		err = got_error_from_errno("pledge");
+		got_privsep_send_error(&ibuf, err);
+		return 1;
+	}
+#endif
+
+	for (;;) {
+		struct imsg imsg;
+
+		memset(&imsg, 0, sizeof(imsg));
+		imsg.fd = -1;
+
+		if (sigint_received) {
+			err = got_error(GOT_ERR_CANCELLED);
+			break;
+		}
+
+		err = got_privsep_recv_imsg(&imsg, &ibuf, 0);
+		if (err) {
+			if (err->code == GOT_ERR_PRIVSEP_PIPE)
+				err = NULL;
+			break;
+		}
+
+		if (imsg.hdr.type == GOT_IMSG_STOP)
+			break;
+
+		switch (imsg.hdr.type) {
+		case GOT_IMSG_GITCONFIG_PARSE_REQUEST:
+			datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
+			if (datalen != 0) {
+				err = got_error(GOT_ERR_PRIVSEP_LEN);
+				break;
+			}
+			if (imsg.fd == -1){
+				err = got_error(GOT_ERR_PRIVSEP_NO_FD);
+				break;
+			}
+
+			if (gitconfig)
+				got_gitconfig_close(gitconfig);
+			err = got_gitconfig_open(&gitconfig, imsg.fd);
+			break;
+		case GOT_IMSG_GITCONFIG_REPOSITORY_FORMAT_VERSION_REQUEST:
+			err = gitconfig_num_request(&ibuf, gitconfig, "core",
+			    "repositoryformatversion", 0);
+			break;
+		case GOT_IMSG_GITCONFIG_AUTHOR_NAME_REQUEST:
+			err = gitconfig_str_request(&ibuf, gitconfig, "user",
+			    "name");
+			break;
+		case GOT_IMSG_GITCONFIG_AUTHOR_EMAIL_REQUEST:
+			err = gitconfig_str_request(&ibuf, gitconfig, "user",
+			    "email");
+			break;
+		default:
+			err = got_error(GOT_ERR_PRIVSEP_MSG);
+			break;
+		}
+
+		if (imsg.fd != -1) {
+			if (close(imsg.fd) == -1 && err == NULL)
+				err = got_error_from_errno("close");
+		}
+
+		imsg_free(&imsg);
+		if (err)
+			break;
+	}
+
+	imsg_clear(&ibuf);
+	if (err) {
+		if (!sigint_received && err->code != GOT_ERR_PRIVSEP_PIPE) {
+			fprintf(stderr, "%s: %s\n", getprogname(), err->msg);
+			got_privsep_send_error(&ibuf, err);
+		}
+	}
+	if (close(GOT_IMSG_FD_CHILD) != 0 && err == NULL)
+		err = got_error_from_errno("close");
+	return err ? 1 : 0;
+}
diff --git a/regress/cmdline/commit.sh b/regress/cmdline/commit.sh
index 451b7e6..55340c7 100755
--- a/regress/cmdline/commit.sh
+++ b/regress/cmdline/commit.sh
@@ -607,6 +607,44 @@ function test_commit_tree_entry_sorting {
 	test_done "$testroot" "$ret"
 }
 
+function test_commit_gitconfig_author {
+	local testroot=`test_init commit_gitconfig_author`
+
+	got checkout $testroot/repo $testroot/wt > /dev/null
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	(cd $testroot/repo && git config user.name 'Flan Luck')
+	(cd $testroot/repo && git config user.email 'flan_luck@openbsd.org')
+
+	echo "modified alpha" > $testroot/wt/alpha
+	(cd $testroot/wt && got commit -m 'test gitconfig author' > /dev/null)
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	(cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	echo "from: Flan Luck <flan_luck@openbsd.org>" \
+		> $testroot/stdout.expected
+	cmp -s $testroot/stdout.expected $testroot/stdout
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/stdout.expected $testroot/stdout
+	fi
+	test_done "$testroot" "$ret"
+}
+
 run_test test_commit_basic
 run_test test_commit_new_subdir
 run_test test_commit_subdir
@@ -622,3 +660,4 @@ run_test test_commit_selected_paths
 run_test test_commit_outside_refs_heads
 run_test test_commit_no_email
 run_test test_commit_tree_entry_sorting
+run_test test_commit_gitconfig_author
diff --git a/tog/Makefile b/tog/Makefile
index c4fa14f..85f9a89 100644
--- a/tog/Makefile
+++ b/tog/Makefile
@@ -8,7 +8,7 @@ SRCS=		tog.c blame.c commit_graph.c delta.c diff.c \
 		object_idset.c object_parse.c opentemp.c path.c pack.c \
 		privsep.c reference.c repository.c sha1.c worktree.c \
 		utf8.c inflate.c buf.c worklist.c rcsutil.c diff3.c \
-		lockfile.c deflate.c object_create.c gitconfig.c
+		lockfile.c deflate.c object_create.c
 MAN =		${PROG}.1
 
 CPPFLAGS = -I${.CURDIR}/../include -I${.CURDIR}/../lib