Skip to content

Commit

Permalink
[#674] Remove Stash and Unstash from VCS
Browse files Browse the repository at this point in the history
To clean up code now that we don't support commit failures
  • Loading branch information
philou authored and mengdaming committed Oct 1, 2024
1 parent 4d8ddb6 commit ae5e4ce
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 146 deletions.
12 changes: 0 additions & 12 deletions src/vcs/fake/vcs_test_fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ const (
PushCommand Command = "push"
RevertLocalCommand Command = "revertLocal"
RollbackLastCommitCommand Command = "rollbackLastCommit"
StashCommand Command = "stash"
UnStashCommand Command = "unStash"
)

type (
Expand Down Expand Up @@ -162,16 +160,6 @@ func (vf *VCSFake) Log(msgFilter func(msg string) bool) (logs vcs.LogItems, err
return
}

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

// UnStash does nothing. Returns an error if in the list of failing commands
func (vf *VCSFake) UnStash(_ bool) error {
return vf.fakeCommand(UnStashCommand)
}

// RollbackLastCommit does nothing. Returns an error if in the list of failing commands
func (vf *VCSFake) RollbackLastCommit() error {
return vf.fakeCommand(RollbackLastCommitCommand)
Expand Down
19 changes: 0 additions & 19 deletions src/vcs/git/git_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,25 +292,6 @@ func (g *gitImpl) Pull() error {
return g.traceGit("pull", "--no-recurse-submodules", g.GetRemoteName(), g.GetWorkingBranch())
}

// Stash creates a git stash.
// Current implementation uses a direct call to git
func (g *gitImpl) Stash(message string) error {
report.PostInfo("Stashing changes")
return g.traceGit("stash", "push", "--quiet", "--include-untracked", "--message", message)
}

// UnStash applies a git stash. Depending on the keep argument value, either a "stash apply" or a "stash pop"
// command is executed under the hood.
// Current implementation uses a direct call to git
func (g *gitImpl) UnStash(keep bool) error {
report.PostInfo("Applying stashed changes")
stashAction := "pop"
if keep {
stashAction = "apply"
}
return g.traceGit("stash", stashAction, "--quiet")
}

// Diff returns the list of files modified since last commit with diff info for each file
// Current implementation uses a direct call to git
func (g *gitImpl) Diff() (diffs vcs.FileDiffs, err error) {
Expand Down
100 changes: 0 additions & 100 deletions src/vcs/git/git_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,106 +511,6 @@ func Test_git_revert(t *testing.T) {
}
}

func Test_git_stash(t *testing.T) {
testFlags := []struct {
desc string
message string
gitError error
expectError bool
expectedArgs []string
}{
{
"git stash command call succeeds",
"some message",
nil,
false,
[]string{"stash", "push", "--quiet", "--include-untracked", "--message", "some message"},
},
{
"git stash command call fails",
"some message",
errors.New("git stash push error"),
true,
[]string{"stash", "push", "--quiet", "--include-untracked", "--message", "some message"},
},
}
for _, tt := range testFlags {
t.Run(tt.desc, func(t *testing.T) {
var actualArgs []string
g, _ := newGitImpl(inMemoryRepoInit, "")
g.traceGitFunction = func(args ...string) (err error) {
actualArgs = args[2:]
return tt.gitError
}

err := g.Stash(tt.message)
if tt.expectError {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
assert.Equal(t, tt.expectedArgs, actualArgs)
})
}
}

func Test_git_unstash(t *testing.T) {
testFlags := []struct {
desc string
keep bool
gitError error
expectError bool
expectedArgs []string
}{
{
"keep stash and git stash command call succeeds",
true,
nil,
false,
[]string{"stash", "apply", "--quiet"},
},
{
"keep stash and git stash command call fails",
true,
errors.New("git stash apply error"),
true,
[]string{"stash", "apply", "--quiet"},
},
{
"remove stash and git stash command call succeeds",
false,
nil,
false,
[]string{"stash", "pop", "--quiet"},
},
{
"remove stash and git stash command call fails",
false,
errors.New("git stash pop error"),
true,
[]string{"stash", "pop", "--quiet"},
},
}
for _, tt := range testFlags {
t.Run(tt.desc, func(t *testing.T) {
var actualArgs []string
g, _ := newGitImpl(inMemoryRepoInit, "")
g.traceGitFunction = func(args ...string) (err error) {
actualArgs = args[2:]
return tt.gitError
}

err := g.UnStash(tt.keep)
if tt.expectError {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
assert.Equal(t, tt.expectedArgs, actualArgs)
})
}
}

func Test_git_log(t *testing.T) {
// Note: this test may break if for any reason the TCR repository initial commit is altered
tcrInitialCommit := vcs.LogItem{
Expand Down
13 changes: 0 additions & 13 deletions src/vcs/p4/p4_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,6 @@ func (p *p4Impl) Pull() error {
return p.traceP4("sync", path)
}

// Stash creates a p4 stash.
// TODO: VCS Stash - p4 ???
func (*p4Impl) Stash(_ string) error {
return errors.New("VCS stash operation not yet available for p4")
}

// UnStash applies a p4 stash. Depending on the keep argument value, either a "stash apply" or a "stash pop"
// command is executed under the hood.
// TODO: VCS UnStash - p4 ???
func (*p4Impl) UnStash(_ bool) error {
return errors.New("VCS unstash operation not yet available for p4")
}

// Diff returns the list of files modified since last commit with diff info for each file
func (p *p4Impl) Diff() (diffs vcs.FileDiffs, err error) {
var p4Output []byte
Expand Down
2 changes: 0 additions & 2 deletions src/vcs/vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ type Interface interface {
RollbackLastCommit() error
Push() error
Pull() error
Stash(message string) error
UnStash(keep bool) error
Diff() (diffs FileDiffs, err error)
Log(msgFilter func(msg string) bool) (logs LogItems, err error)
EnableAutoPush(flag bool)
Expand Down

0 comments on commit ae5e4ce

Please sign in to comment.