From 74d3e9daabfbb77cb49a6fc13b5ae1d0e26e3e59 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Sun, 27 Oct 2019 17:42:46 -0700 Subject: [PATCH] move code for readability --- cmd/git-sync/main.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/cmd/git-sync/main.go b/cmd/git-sync/main.go index c95da99..ad2f7a3 100644 --- a/cmd/git-sync/main.go +++ b/cmd/git-sync/main.go @@ -533,6 +533,16 @@ func hashForRev(ctx context.Context, rev, gitRoot string) (string, error) { return strings.Trim(string(output), "\n"), nil } +// remoteHashForRef returns the upstream hash for a given ref. +func remoteHashForRef(ctx context.Context, ref, gitRoot string) (string, error) { + output, err := runCommand(ctx, gitRoot, *flGitCmd, "ls-remote", "-q", "origin", ref) + if err != nil { + return "", err + } + parts := strings.Split(string(output), "\t") + return parts[0], nil +} + func revIsHash(ctx context.Context, rev, gitRoot string) (bool, error) { // If rev is a tag name or HEAD, rev-parse will produce the git hash. If // rev is already a git hash, the output will be the same hash. Of course, a @@ -606,15 +616,6 @@ func getRevs(ctx context.Context, localDir, branch, rev string) (string, string, return local, remote, nil } -func remoteHashForRef(ctx context.Context, ref, gitRoot string) (string, error) { - output, err := runCommand(ctx, gitRoot, *flGitCmd, "ls-remote", "-q", "origin", ref) - if err != nil { - return "", err - } - parts := strings.Split(string(output), "\t") - return parts[0], nil -} - func cmdForLog(command string, args ...string) string { if strings.ContainsAny(command, " \t\n") { command = fmt.Sprintf("%q", command)