Skip to content

Commit b7fdb3f

Browse files
committed
Make the repo method for pushing more general
1 parent 0eb8db8 commit b7fdb3f

File tree

5 files changed

+25
-33
lines changed

5 files changed

+25
-33
lines changed

commands/commands.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ import (
2424
)
2525

2626
const (
27-
notesRefPattern = "refs/notes/devtools/*"
28-
archiveRefPattern = "refs/devtools/archives/*"
29-
commentFilename = "APPRAISE_COMMENT_EDITMSG"
27+
notesRefPattern = "refs/notes/devtools/*"
28+
devtoolsRefPattern = "refs/devtools/*"
29+
archiveRefPattern = "refs/devtools/archives/*"
30+
commentFilename = "APPRAISE_COMMENT_EDITMSG"
3031
)
3132

3233
// Command represents the definition of a single command.

commands/push.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"errors"
2121
"fmt"
2222

23-
"github.com/google/git-appraise/fork"
2423
"github.com/google/git-appraise/repository"
2524
)
2625

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

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

4442
var pushCmd = &Command{

repository/git.go

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -953,23 +953,6 @@ func (repo *GitRepo) PushNotesAndArchive(remote, notesRefPattern, archiveRefPatt
953953
return nil
954954
}
955955

956-
// PushNotesForksAndArchive pushes the given notes, forks, and archive refs to a remote repo.
957-
func (repo *GitRepo) PushNotesForksAndArchive(remote, notesRefPattern, forksRef, archiveRefPattern string) error {
958-
if !strings.HasPrefix(forksRef, devtoolsRefPrefix) {
959-
return fmt.Errorf("Unsupported forks ref: %q", forksRef)
960-
}
961-
if !strings.HasPrefix(archiveRefPattern, devtoolsRefPrefix) {
962-
return fmt.Errorf("Unsupported archive ref pattern: %q", archiveRefPattern)
963-
}
964-
notesRefspec := fmt.Sprintf("%s:%s", notesRefPattern, notesRefPattern)
965-
devtoolsRefspec := fmt.Sprintf("+%s*:%s*", devtoolsRefPrefix, devtoolsRefPrefix)
966-
err := repo.runGitCommandInline("push", remote, notesRefspec, devtoolsRefspec)
967-
if err != nil {
968-
return fmt.Errorf("Failed to push the local notes, forks, and archive to the remote '%s': %v", remote, err)
969-
}
970-
return nil
971-
}
972-
973956
func getRemoteNotesRef(remote, localNotesRef string) string {
974957
relativeNotesRef := strings.TrimPrefix(localNotesRef, "refs/notes/")
975958
return "refs/notes/remotes/" + remote + "/" + relativeNotesRef
@@ -1276,3 +1259,13 @@ func (repo *GitRepo) PullNotesForksAndArchive(remote, notesRefPattern, forksRef,
12761259
}
12771260
return nil
12781261
}
1262+
1263+
// Push pushes the given refs to a remote repo.
1264+
func (repo *GitRepo) Push(remote string, refSpecs ...string) error {
1265+
pushArgs := append([]string{"push", remote}, refSpecs...)
1266+
err := repo.runGitCommandInline(pushArgs...)
1267+
if err != nil {
1268+
return fmt.Errorf("Failed to push the local refs to the remote '%s': %v", remote, err)
1269+
}
1270+
return nil
1271+
}

repository/mock_repo.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -663,11 +663,6 @@ func (r *mockRepoForTest) FetchAndReturnNewReviewHashes(remote, notesRefPattern,
663663
return nil, nil
664664
}
665665

666-
// PushNotesForksAndArchive pushes the given notes, forks, and archive refs to a remote repo.
667-
func (r *mockRepoForTest) PushNotesForksAndArchive(remote, notesRefPattern, forksRef, archiveRefPattern string) error {
668-
return nil
669-
}
670-
671666
// PullNotesForksAndArchive fetches the contents of the notes, forks, and archives
672667
// refs from a remote repo, and merges them with the corresponding local refs.
673668
//
@@ -686,3 +681,8 @@ func (r *mockRepoForTest) PushNotesForksAndArchive(remote, notesRefPattern, fork
686681
func (r *mockRepoForTest) PullNotesForksAndArchive(remote, notesRefPattern, forksRef, archiveRefPattern string) error {
687682
return nil
688683
}
684+
685+
// Push pushes the given refs to a remote repo.
686+
func (r *mockRepoForTest) Push(remote string, refPattern ...string) error {
687+
return nil
688+
}

repository/repo.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,6 @@ type Repo interface {
311311
// they point to.
312312
FetchAndReturnNewReviewHashes(remote, notesRefPattern, archiveRefPattern string) ([]string, error)
313313

314-
// PushNotesForksAndArchive pushes the given notes, forks, and archive refs to a remote repo.
315-
PushNotesForksAndArchive(remote, notesRefPattern, forksRef, archiveRefPattern string) error
316-
317314
// PullNotesForksAndArchive fetches the contents of the notes, forks, and archives
318315
// refs from a remote repo, and merges them with the corresponding local refs.
319316
//
@@ -330,4 +327,7 @@ type Repo interface {
330327
// we merely ensure that their history graph includes every commit that we
331328
// intend to keep.
332329
PullNotesForksAndArchive(remote, notesRefPattern, forksRef, archiveRefPattern string) error
330+
331+
// Push pushes the given refs to a remote repo.
332+
Push(remote string, refPattern ...string) error
333333
}

0 commit comments

Comments
 (0)