Skip to content

Commit

Permalink
Make the repo method for pushing more general
Browse files Browse the repository at this point in the history
  • Loading branch information
ojarjur committed Nov 13, 2018
1 parent 0eb8db8 commit b7fdb3f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 33 deletions.
7 changes: 4 additions & 3 deletions commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import (
)

const (
notesRefPattern = "refs/notes/devtools/*"
archiveRefPattern = "refs/devtools/archives/*"
commentFilename = "APPRAISE_COMMENT_EDITMSG"
notesRefPattern = "refs/notes/devtools/*"
devtoolsRefPattern = "refs/devtools/*"
archiveRefPattern = "refs/devtools/archives/*"
commentFilename = "APPRAISE_COMMENT_EDITMSG"
)

// Command represents the definition of a single command.
Expand Down
8 changes: 3 additions & 5 deletions commands/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"errors"
"fmt"

"github.com/google/git-appraise/fork"
"github.com/google/git-appraise/repository"
)

Expand All @@ -35,10 +34,9 @@ func push(repo repository.Repo, args []string) error {
remote = args[0]
}

if err := repo.PushNotesForksAndArchive(remote, notesRefPattern, fork.Ref, archiveRefPattern); err != nil {
return err
}
return nil
notesRefspec := fmt.Sprintf("%s:%s", notesRefPattern, notesRefPattern)
devtoolsRefspec := fmt.Sprintf("+%s*:%s*", devtoolsRefPattern, devtoolsRefPattern)
return repo.Push(remote, notesRefspec, devtoolsRefspec)
}

var pushCmd = &Command{
Expand Down
27 changes: 10 additions & 17 deletions repository/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -953,23 +953,6 @@ func (repo *GitRepo) PushNotesAndArchive(remote, notesRefPattern, archiveRefPatt
return nil
}

// PushNotesForksAndArchive pushes the given notes, forks, and archive refs to a remote repo.
func (repo *GitRepo) PushNotesForksAndArchive(remote, notesRefPattern, forksRef, archiveRefPattern string) error {
if !strings.HasPrefix(forksRef, devtoolsRefPrefix) {
return fmt.Errorf("Unsupported forks ref: %q", forksRef)
}
if !strings.HasPrefix(archiveRefPattern, devtoolsRefPrefix) {
return fmt.Errorf("Unsupported archive ref pattern: %q", archiveRefPattern)
}
notesRefspec := fmt.Sprintf("%s:%s", notesRefPattern, notesRefPattern)
devtoolsRefspec := fmt.Sprintf("+%s*:%s*", devtoolsRefPrefix, devtoolsRefPrefix)
err := repo.runGitCommandInline("push", remote, notesRefspec, devtoolsRefspec)
if err != nil {
return fmt.Errorf("Failed to push the local notes, forks, and archive to the remote '%s': %v", remote, err)
}
return nil
}

func getRemoteNotesRef(remote, localNotesRef string) string {
relativeNotesRef := strings.TrimPrefix(localNotesRef, "refs/notes/")
return "refs/notes/remotes/" + remote + "/" + relativeNotesRef
Expand Down Expand Up @@ -1276,3 +1259,13 @@ func (repo *GitRepo) PullNotesForksAndArchive(remote, notesRefPattern, forksRef,
}
return nil
}

// Push pushes the given refs to a remote repo.
func (repo *GitRepo) Push(remote string, refSpecs ...string) error {
pushArgs := append([]string{"push", remote}, refSpecs...)
err := repo.runGitCommandInline(pushArgs...)
if err != nil {
return fmt.Errorf("Failed to push the local refs to the remote '%s': %v", remote, err)
}
return nil
}
10 changes: 5 additions & 5 deletions repository/mock_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,11 +663,6 @@ func (r *mockRepoForTest) FetchAndReturnNewReviewHashes(remote, notesRefPattern,
return nil, nil
}

// PushNotesForksAndArchive pushes the given notes, forks, and archive refs to a remote repo.
func (r *mockRepoForTest) PushNotesForksAndArchive(remote, notesRefPattern, forksRef, archiveRefPattern string) error {
return nil
}

// PullNotesForksAndArchive fetches the contents of the notes, forks, and archives
// refs from a remote repo, and merges them with the corresponding local refs.
//
Expand All @@ -686,3 +681,8 @@ func (r *mockRepoForTest) PushNotesForksAndArchive(remote, notesRefPattern, fork
func (r *mockRepoForTest) PullNotesForksAndArchive(remote, notesRefPattern, forksRef, archiveRefPattern string) error {
return nil
}

// Push pushes the given refs to a remote repo.
func (r *mockRepoForTest) Push(remote string, refPattern ...string) error {
return nil
}
6 changes: 3 additions & 3 deletions repository/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,6 @@ type Repo interface {
// they point to.
FetchAndReturnNewReviewHashes(remote, notesRefPattern, archiveRefPattern string) ([]string, error)

// PushNotesForksAndArchive pushes the given notes, forks, and archive refs to a remote repo.
PushNotesForksAndArchive(remote, notesRefPattern, forksRef, archiveRefPattern string) error

// PullNotesForksAndArchive fetches the contents of the notes, forks, and archives
// refs from a remote repo, and merges them with the corresponding local refs.
//
Expand All @@ -330,4 +327,7 @@ type Repo interface {
// we merely ensure that their history graph includes every commit that we
// intend to keep.
PullNotesForksAndArchive(remote, notesRefPattern, forksRef, archiveRefPattern string) error

// Push pushes the given refs to a remote repo.
Push(remote string, refPattern ...string) error
}

0 comments on commit b7fdb3f

Please sign in to comment.