From cd6e398dae38fb8b0b57f221b13c4b75c0a53fb9 Mon Sep 17 00:00:00 2001 From: Koichi Shiraishi Date: Wed, 21 Jun 2017 14:51:24 +0900 Subject: [PATCH] cmd/git-contrib-init: support http.cookiefile config for gitcookies Change-Id: I097905122e1cb7298c31c330731f0fc3c6fc9b59 Reviewed-on: https://go-review.googlesource.com/46235 Reviewed-by: Brad Fitzpatrick --- cmd/go-contrib-init/contrib.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/cmd/go-contrib-init/contrib.go b/cmd/go-contrib-init/contrib.go index 3e92f61fe9..e9a2906d3a 100644 --- a/cmd/go-contrib-init/contrib.go +++ b/cmd/go-contrib-init/contrib.go @@ -80,7 +80,27 @@ func checkCLA() { " * Run go-contrib-init again.\n") } +func expandUser(s string) string { + env := "HOME" + if runtime.GOOS == "windows" { + env = "USERPROFILE" + } else if runtime.GOOS == "plan9" { + env = "home" + } + if home := os.Getenv(env); home != "" { + return strings.Replace(s, "~", home, 1) + } + return s +} + func cookiesFile() string { + out, _ := exec.Command("git", "config", "http.cookiefile").Output() + if s := strings.TrimSpace(string(out)); s != "" { + if strings.Contains(s, "~") { + s = expandUser(s) + } + return s + } if runtime.GOOS == "windows" { return filepath.Join(os.Getenv("USERPROFILE"), ".gitcookies") }