Skip to content

Commit

Permalink
[#674] Rename VCS.Restore to RevertLocal
Browse files Browse the repository at this point in the history
To have clearer names for all VCS
- rename interface function
- adapt fake
  • Loading branch information
philou authored and mengdaming committed Oct 1, 2024
1 parent f406fc2 commit 2d82966
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/engine/tcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ func (tcr *TCREngine) shouldRevertFile(path string) bool {
}

func (tcr *TCREngine) revertFile(file string) error {
return tcr.vcs.Restore(file)
return tcr.vcs.RevertLocal(file)
}

// GetSessionInfo provides the information related to the current TCR session.
Expand Down
10 changes: 5 additions & 5 deletions src/engine/tcr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func Test_tcr_operation_end_state(t *testing.T) {
{
"revert with VCS restore failure",
func() {
tcr, _ := initTCREngineWithFakes(nil, nil, fake.Commands{fake.RestoreCommand}, nil)
tcr, _ := initTCREngineWithFakes(nil, nil, fake.Commands{fake.RevertLocalCommand}, nil)
tcr.revert(*events.ATcrEvent())
},
status.VCSError,
Expand All @@ -235,7 +235,7 @@ func Test_tcr_operation_end_state(t *testing.T) {
func Test_relaxed_source_revert(t *testing.T) {
tcr, vcsFake := initTCREngineWithFakes(nil, nil, nil, nil)
tcr.revert(*events.ATcrEvent())
assert.Equal(t, fake.RestoreCommand, vcsFake.GetLastCommand())
assert.Equal(t, fake.RevertLocalCommand, vcsFake.GetLastCommand())
}

func Test_relaxed_doesnt_revert_test_files(t *testing.T) {
Expand All @@ -244,7 +244,7 @@ func Test_relaxed_doesnt_revert_test_files(t *testing.T) {
vcs.NewFileDiff("fake-test", 1, 1),
})
tcr.revert(*events.ATcrEvent())
assert.NotEqual(t, fake.RestoreCommand, vcsFake.GetLastCommand())
assert.NotEqual(t, fake.RevertLocalCommand, vcsFake.GetLastCommand())
}

func Test_variant_specific_reverts(t *testing.T) {
Expand Down Expand Up @@ -305,7 +305,7 @@ func Test_variant_specific_reverts(t *testing.T) {
nil, nil, nil, tt.fileDiffs)
tcr.revert(*events.ATcrEvent())
sniffer.Stop()
assert.Equal(t, fake.RestoreCommand, vcsFake.GetLastCommand())
assert.Equal(t, fake.RevertLocalCommand, vcsFake.GetLastCommand())
assert.Equal(t, 1, sniffer.GetMatchCount())
})
}
Expand Down Expand Up @@ -368,7 +368,7 @@ func Test_tcr_cycle_end_state(t *testing.T) {
},
{
"with test and VCS restore failure",
toolchain.Operations{toolchain.TestOperation}, fake.Commands{fake.RestoreCommand},
toolchain.Operations{toolchain.TestOperation}, fake.Commands{fake.RevertLocalCommand},
status.VCSError,
},
}
Expand Down
26 changes: 13 additions & 13 deletions src/vcs/fake/vcs_test_fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ func (gc Commands) contains(command Command) bool {

// List of supported VCS commands
const (
AddCommand Command = "add"
CommitCommand Command = "commit"
DiffCommand Command = "diff"
LogCommand Command = "log"
PullCommand Command = "pull"
PushCommand Command = "push"
RestoreCommand Command = "restore"
RevertCommand Command = "revert"
StashCommand Command = "stash"
UnStashCommand Command = "unStash"
AddCommand Command = "add"
CommitCommand Command = "commit"
DiffCommand Command = "diff"
LogCommand Command = "log"
PullCommand Command = "pull"
PushCommand Command = "push"
RevertLocalCommand Command = "revertLocal"
RevertCommand Command = "revert"
StashCommand Command = "stash"
UnStashCommand Command = "unStash"
)

type (
Expand Down Expand Up @@ -125,9 +125,9 @@ func (vf *VCSFake) Commit(_ bool, _ ...string) error {
return vf.fakeCommand(CommitCommand)
}

// Restore does nothing. Returns an error if in the list of failing commands
func (vf *VCSFake) Restore(_ string) error {
return vf.fakeCommand(RestoreCommand)
// RevertLocal does nothing. Returns an error if in the list of failing commands
func (vf *VCSFake) RevertLocal(_ string) error {
return vf.fakeCommand(RevertLocalCommand)
}

// Push does nothing. Returns an error if in the list of failing commands
Expand Down
4 changes: 2 additions & 2 deletions src/vcs/git/git_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ func (g *gitImpl) nothingToCommit() bool {
return status.IsClean()
}

// Restore restores to last commit for the provided path.
// RevertLocal restores to last commit for the provided path.
// Current implementation uses a direct call to git
func (g *gitImpl) Restore(path string) error {
func (g *gitImpl) RevertLocal(path string) error {
report.PostWarning("Reverting ", path)
return g.traceGit("checkout", "HEAD", "--", path)
}
Expand Down
2 changes: 1 addition & 1 deletion src/vcs/git/git_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ func Test_git_restore(t *testing.T) {
return tt.gitError
}

err := g.Restore("some-path")
err := g.RevertLocal("some-path")
if tt.expectError {
assert.Error(t, err)
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/vcs/p4/p4_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ func (p *p4Impl) Commit(_ bool, messages ...string) error {
return p.submitChangeList(cl)
}

// Restore restores to last commit for the provided path.
func (p *p4Impl) Restore(path string) error {
// RevertLocal restores to last commit for the provided path.
func (p *p4Impl) RevertLocal(path string) error {
// in order to work, p4 revert requires that the file be reconciled beforehand
err := p.reconcile(path)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion src/vcs/p4/p4_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ func Test_p4_restore(t *testing.T) {
return tt.p4Error
}

err := p.Restore("some-path")
err := p.RevertLocal("some-path")
if tt.expectError {
assert.Error(t, err)
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/vcs/vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type Interface interface {
IsOnRootBranch() bool
Add(paths ...string) error
Commit(amend bool, messages ...string) error
Restore(path string) error
RevertLocal(path string) error
Revert() error
Push() error
Pull() error
Expand Down

0 comments on commit 2d82966

Please sign in to comment.