github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/review/git-review/sync.go (about)

     1  // Copyright 2014 The Go Authors.  All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import "strings"
     8  
     9  func doSync(args []string) {
    10  	expectZeroArgs(args, "sync")
    11  
    12  	// Get current branch and commit ID for fixup after pull.
    13  	b := CurrentBranch()
    14  	id := b.ChangeID()
    15  
    16  	// Pull remote changes into local branch.
    17  	// We do this in one command so that people following along with 'git sync -v'
    18  	// see fewer commands to understand.
    19  	// We want to pull in the remote changes from the upstream branch
    20  	// and rebase the current pending commit (if any) on top of them.
    21  	// If there is no pending commit, the pull will do a fast-forward merge.
    22  	run("git", "pull", "-q", "-r", "origin", strings.TrimPrefix(b.OriginBranch(), "origin/"))
    23  
    24  	// If the change commit has been submitted,
    25  	// roll back change leaving any changes unstaged.
    26  	// Pull should have done this for us, but check just in case.
    27  	if b.Submitted(id) && b.HasPendingCommit() {
    28  		run("git", "reset", "HEAD^")
    29  	}
    30  }