Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(git): Handier error message if you get errors pushing to https #2450

Merged
merged 1 commit into from
Dec 7, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions pkg/gits/git_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gits
import (
"bytes"
"fmt"
"github.com/pkg/errors"
"io"
"io/ioutil"
"net/url"
Expand Down Expand Up @@ -198,24 +199,30 @@ func (g *GitCLI) Branch(dir string) (string, error) {
return g.gitCmdWithOutput(dir, "rev-parse", "--abbrev-ref", "HEAD")
}

// WriteOperation performs a generic write operation, with nicer error handling
func (g *GitCLI) WriteOperation(dir string, args ...string) error {
return errors.Wrap(g.gitCmd(dir, args...),
"Have you set up a git credential helper? See https://help.github.com/articles/caching-your-github-password-in-git/\n")
}

// Push pushes the changes from the repository at the given directory
func (g *GitCLI) Push(dir string) error {
return g.gitCmd(dir, "push", "origin", "HEAD")
return g.WriteOperation(dir, "push", "origin", "HEAD")
}

// ForcePushBranch does a force push of the local branch into the remote branch of the repository at the given directory
func (g *GitCLI) ForcePushBranch(dir string, localBranch string, remoteBranch string) error {
return g.gitCmd(dir, "push", "-f", "origin", localBranch+":"+remoteBranch)
return g.WriteOperation(dir, "push", "-f", "origin", localBranch+":"+remoteBranch)
}

// PushMaster pushes the master branch into the origin
func (g *GitCLI) PushMaster(dir string) error {
return g.gitCmd(dir, "push", "-u", "origin", "master")
return g.WriteOperation(dir, "push", "-u", "origin", "master")
}

// Pushtag pushes the given tag into the origin
func (g *GitCLI) PushTag(dir string, tag string) error {
return g.gitCmd(dir, "push", "origin", tag)
return g.WriteOperation(dir, "push", "origin", tag)
}

// Add does a git add for all the given arguments
Expand Down