Add repo sync

Change-Id: I6b61873c97e9ff46a699151fc52aa937248bcf81
diff --git a/server/git/git.go b/server/git/git.go
index 29cee16..9ee3074 100644
--- a/server/git/git.go
+++ b/server/git/git.go
@@ -32,6 +32,7 @@
 	Checkout(ctx context.Context, ref string) error
 	DeleteBranch(ctx context.Context, name string, force bool) error
 	GetCurrentBranch(ctx context.Context) (string, error)
+	GetUpstreamBranch(ctx context.Context, branch string) (string, error)
 
 	// Commit operations
 	Add(ctx context.Context, paths []string) error
@@ -394,6 +395,22 @@
 	return strings.TrimSpace(output), nil
 }
 
+// GetUpstreamBranch returns the upstream branch for a given branch
+func (g *Git) GetUpstreamBranch(ctx context.Context, branch string) (string, error) {
+	cmd := exec.CommandContext(ctx, "git", "rev-parse", "--abbrev-ref", branch+"@{upstream}")
+	cmd.Dir = g.repoPath
+	output, err := g.runCommandWithOutput(cmd, "rev-parse")
+	if err != nil {
+		return "", err
+	}
+
+	// The output will be in format "origin/branch-name", we want just "branch-name"
+	upstream := strings.TrimSpace(output)
+	upstream = strings.TrimPrefix(upstream, "origin/")
+
+	return upstream, nil
+}
+
 // Add stages files for commit
 func (g *Git) Add(ctx context.Context, paths []string) error {
 	args := append([]string{"add"}, paths...)