aboutsummaryrefslogtreecommitdiff
path: root/git-codereview
diff options
context:
space:
mode:
authorDmitri Shuralyov <dmitri@shuralyov.com>2018-06-03 14:03:53 -0400
committerBrad Fitzpatrick <bradfitz@golang.org>2018-06-12 19:14:31 +0000
commitabfd23779f7118d331eb23f79506debc5f95b511 (patch)
tree4edea89bc67ecab466c73841d76ca2a5d5f1b04c /git-codereview
parent0d7a66991c6e16602c02f2deda6f7b0908be4b7a (diff)
downloadgo-x-review-abfd23779f7118d331eb23f79506debc5f95b511.tar.xz
git-codereview: use --path option of git config to expand ~
This change largely reverts CL 115576, and applies a simpler version. It uses the --path option of git config to achieve equivalent behavior. The --path option is available as far back as git 1.7.0, according to https://git-scm.com/docs/git-config/1.7.0, making it safe to rely on: The type specifier can be [...] --path, which does some path expansion (see --path below). If no type specifier is passed, no checks or transformations are performed on the value. --path git-config will expand leading ~ to the value of $HOME, and ~user to the home directory for the specified user. Change-Id: I74bb543ab488d24fe4cf66da0c6dbc087dc368a6 Reviewed-on: https://go-review.googlesource.com/116016 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'git-codereview')
-rw-r--r--git-codereview/api.go22
1 files changed, 9 insertions, 13 deletions
diff --git a/git-codereview/api.go b/git-codereview/api.go
index 65bc3a2..8440cb5 100644
--- a/git-codereview/api.go
+++ b/git-codereview/api.go
@@ -143,21 +143,9 @@ 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, "~/"))
- }
+ if cookieFile, _ := trimErr(cmdOutputErr("git", "config", "--path", "http.cookiefile")); cookieFile != "" {
data, _ := ioutil.ReadFile(cookieFile)
maxMatch := -1
for _, line := range lines(string(data)) {
@@ -179,6 +167,14 @@ 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 {