diff options
| author | Oling Cat <olingcat@gmail.com> | 2014-12-18 16:29:12 +0800 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2014-12-23 21:33:09 +0000 |
| commit | 4a9b48bf245380ef5427c95d362a553ddbd780a7 (patch) | |
| tree | f3329fd3d48b8c1f6a8a2c736bbafd69a25d40f9 /git-codereview/api.go | |
| parent | 54e90cf22404776b710d9144802a935aec8dbd74 (diff) | |
| download | go-x-review-4a9b48bf245380ef5427c95d362a553ddbd780a7.tar.xz | |
git-codereview: accept more forms of hosts in cookies file
If the user selects "all of googlesource.com" option when generating
the password, the host will be ".googlesource.com", the tool needs
to also support this form.
Change-Id: Id2669e4b7a7b137c9b99399dbfb8c14dd330b368
Reviewed-on: https://go-review.googlesource.com/1771
Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'git-codereview/api.go')
| -rw-r--r-- | git-codereview/api.go | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/git-codereview/api.go b/git-codereview/api.go index f79d770..f6bda31 100644 --- a/git-codereview/api.go +++ b/git-codereview/api.go @@ -86,14 +86,19 @@ func loadAuth() { // now tells users to store this information. if cookieFile, _ := getOutputErr("git", "config", "http.cookiefile"); cookieFile != "" { data, _ := ioutil.ReadFile(cookieFile) + maxMatch := -1 for _, line := range strings.Split(string(data), "\n") { f := strings.Split(line, "\t") - if len(f) >= 7 && f[0] == auth.host { - auth.cookieName = f[5] - auth.cookieValue = f[6] - return + if len(f) >= 7 && (f[0] == auth.host || strings.HasPrefix(f[0], ".") && strings.HasSuffix(auth.host, f[0])) { + if len(f[0]) > maxMatch { + auth.cookieName = f[5] + auth.cookieValue = f[6] + } } } + if maxMatch > 0 { + return + } } // If not there, then look in $HOME/.netrc, which is where Gerrit |
