Using ls-remote for media push --dry-run is more accurate

This commit is contained in:
rubyist 2014-09-29 15:35:59 -04:00
parent 321c1a51c6
commit e6b143a965
3 changed files with 31 additions and 8 deletions

@ -1,7 +1,6 @@
package commands
import (
"fmt"
"github.com/github/git-media/git"
"github.com/github/git-media/gitmedia"
"github.com/github/git-media/gitmediaclient"
@ -57,18 +56,31 @@ func pushCommand(cmd *cobra.Command, args []string) {
var left, right string
if dryRun {
var repo, refspec string
if len(args) < 1 {
Print("Usage: git media push --dry-run <repo> [refspec]")
return
}
ref, err := gitmedia.CurrentRef()
if err != nil {
Panic(err, "Error getting current ref")
}
left = ref
repo = args[0]
if len(args) == 2 {
right = fmt.Sprintf("^%s/%s", args[0], args[1])
refspec = args[1]
}
localRef, err := gitmedia.CurrentRef()
if err != nil {
Panic(err, "Error getting local ref")
}
left = localRef
remoteRef, err := git.LsRemote(repo, refspec)
if err != nil {
Panic(err, "Error getting remote ref")
}
if remoteRef != "" {
right = strings.Split(remoteRef, "\t")[0]
}
} else {
refsData, err := ioutil.ReadAll(os.Stdin)

@ -41,7 +41,7 @@ func TestPushToNewBranch(t *testing.T) {
repo := NewRepository(t, "empty")
defer repo.Test()
cmd := repo.Command("push", "--dry-run", "origin")
cmd := repo.Command("push", "--dry-run", "origin", "newbranch")
cmd.Output = "push a.dat\npush b.dat"
cmd.Before(func() {

@ -29,6 +29,17 @@ func HashObject(data []byte) (string, error) {
return simpleExec(buf, "git", "hash-object", "--stdin")
}
func LsRemote(repo, refspec string) (string, error) {
if repo == "" {
return "", errors.New("repo required")
}
if refspec == "" {
return simpleExec(nil, "git", "ls-remote", repo)
}
return simpleExec(nil, "git", "ls-remote", repo, refspec)
}
var z40 = regexp.MustCompile(`\^?0{40}`)
type GitObject struct {