Skip to content

Commit 156ce3d

Browse files
author
Jacob Marble
committed
Fix an error when git config is called.
os.user.User.Name is "" when the operating system reports it to be such. Similarly, /dev/mailname contains just "debian" if nothing better has been set, so I added a check for that.
1 parent 1221041 commit 156ce3d

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2015, Michael Stapelberg and contributors
1+
Copyright (c) 2015, Michael Stapelberg, Google Inc. and contributors
22
All rights reserved.
33

44
Redistribution and use in source and binary forms, with or without

make.go

+14-8
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,16 @@ func createGitRepository(debsrc, gopkg, orig string) (string, error) {
236236
return dir, err
237237
}
238238

239-
if err := runGitCommandIn(dir, "config", "user.name", getDebianName()); err != nil {
240-
return dir, err
239+
if debianName := getDebianName(); debianName != "TODO" {
240+
if err := runGitCommandIn(dir, "config", "user.name", debianName); err != nil {
241+
return dir, err
242+
}
241243
}
242244

243-
if err := runGitCommandIn(dir, "config", "user.email", getDebianEmail()); err != nil {
244-
return dir, err
245+
if debianEmail := getDebianEmail(); debianEmail != "TODO" {
246+
if err := runGitCommandIn(dir, "config", "user.email", debianEmail); err != nil {
247+
return dir, err
248+
}
245249
}
246250

247251
if err := runGitCommandIn(dir, "config", "push.default", "matching"); err != nil {
@@ -321,7 +325,7 @@ func getDebianName() string {
321325
if name := strings.TrimSpace(os.Getenv("DEBNAME")); name != "" {
322326
return name
323327
}
324-
if u, err := user.Current(); err == nil {
328+
if u, err := user.Current(); err == nil && u.Name != "" {
325329
return u.Name
326330
}
327331
return "TODO"
@@ -331,9 +335,11 @@ func getDebianEmail() string {
331335
if email := strings.TrimSpace(os.Getenv("DEBEMAIL")); email != "" {
332336
return email
333337
}
334-
if mailname, err := ioutil.ReadFile("/etc/mailname"); err == nil {
335-
if u, err := user.Current(); err == nil {
336-
return u.Name + "@" + strings.TrimSpace(string(mailname))
338+
mailname, err := ioutil.ReadFile("/etc/mailname")
339+
if err == nil && strings.Contains(string(mailname), ".") {
340+
// By default, /etc/mailname contains "debian" which is not useful; check for ".".
341+
if u, err := user.Current(); err == nil && u.Username != "" {
342+
return u.Username + "@" + strings.TrimSpace(string(mailname))
337343
}
338344
}
339345
return "TODO"

0 commit comments

Comments
 (0)