aboutsummaryrefslogtreecommitdiff
path: root/git-codereview
diff options
context:
space:
mode:
authorFilippo Valsorda <filippo@golang.org>2018-05-31 16:21:45 +0000
committerFilippo Valsorda <filippo@golang.org>2018-06-01 23:22:47 +0000
commitd4998e72643e8f0b9edc1c6e63c8ba6fb2a2a949 (patch)
treea8f3db441788c7b1254122d0c046e39c1027908e /git-codereview
parent8545223bc1b05b842f3f3a11e66cd902bf046efe (diff)
downloadgo-x-review-d4998e72643e8f0b9edc1c6e63c8ba6fb2a2a949.tar.xz
git-codereview: support ~ in http.cookiefile
http.cookiefile is a pathname value, which means a leading tilde is automatically expanded by git-config. https://git-scm.com/docs/git-config#git-config-httpcookieFile https://git-scm.com/docs/git-config#git-config-pathname Change-Id: Ia208b8a8a7dd5e07de58481b9010051569d0d8c8 Reviewed-on: https://go-review.googlesource.com/115576 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'git-codereview')
-rw-r--r--git-codereview/api.go20
-rw-r--r--git-codereview/api_test.go2
2 files changed, 13 insertions, 9 deletions
diff --git a/git-codereview/api.go b/git-codereview/api.go
index 77d2c08..c8f6da3 100644
--- a/git-codereview/api.go
+++ b/git-codereview/api.go
@@ -144,9 +144,21 @@ func loadAuth() {
loadGerritOrigin()
+ homeDir := testHomeDir
+ if homeDir == "" {
+ usr, err := user.Current()
+ if err != nil {
+ dief("failed to get current user home directory to look for auth tokens: %v", err)
+ }
+ homeDir = usr.HomeDir
+ }
+
// First look in Git's http.cookiefile, which is where Gerrit
// now tells users to store this information.
if cookieFile, _ := trimErr(cmdOutputErr("git", "config", "http.cookiefile")); cookieFile != "" {
+ if strings.HasPrefix(cookieFile, "~/") {
+ cookieFile = filepath.Join(homeDir, strings.TrimPrefix(cookieFile, "~/"))
+ }
data, _ := ioutil.ReadFile(cookieFile)
maxMatch := -1
for _, line := range lines(string(data)) {
@@ -168,14 +180,6 @@ func loadAuth() {
// used to tell users to store the information, until the passwords
// got so long that old versions of curl couldn't handle them.
netrc := netrcName()
- homeDir := testHomeDir
- if homeDir == "" {
- usr, err := user.Current()
- if err != nil {
- dief("failed to get current user home directory to look for %q: %v", netrc, err)
- }
- homeDir = usr.HomeDir
- }
data, _ := ioutil.ReadFile(filepath.Join(homeDir, netrc))
for _, line := range lines(string(data)) {
if i := strings.Index(line, "#"); i >= 0 {
diff --git a/git-codereview/api_test.go b/git-codereview/api_test.go
index 02132a2..997a347 100644
--- a/git-codereview/api_test.go
+++ b/git-codereview/api_test.go
@@ -110,7 +110,7 @@ func TestLoadAuth(t *testing.T) {
if tt.cookiefile != "MISSING" {
write(t, gt.client+"/.cookies", tt.cookiefile)
}
- trun(t, gt.client, "git", "config", "http.cookiefile", gt.client+"/.cookies")
+ trun(t, gt.client, "git", "config", "http.cookiefile", "~/.cookies")
}
// Run command via testMain to trap stdout, stderr, death.