Out of bound error in gut squash
julien040 opened this issue · comments
Describe the bug
Gut returns this when running gut squash
panic: runtime error: slice bounds out of range [:-1]
goroutine 1 [running]:
github.com/julien040/gut/src/controller.Squash.func1(...)
/Users/julien/Code/gut/src/controller/squash.go:98
github.com/julien040/gut/src/controller.Squash(0x14000125000?, {0x10348ce20, 0x0, 0x102e7072b?})
/Users/julien/Code/gut/src/controller/squash.go:120 +0x8d4
github.com/spf13/cobra.(*Command).execute(0x103405960, {0x10348ce20, 0x0, 0x0})
/Users/julien/go/pkg/mod/github.com/spf13/cobra@v1.6.1/command.go:920 +0x640
github.com/spf13/cobra.(*Command).ExecuteC(0x103404de0)
/Users/julien/go/pkg/mod/github.com/spf13/cobra@v1.6.1/command.go:1044 +0x320
github.com/spf13/cobra.(*Command).Execute(...)
/Users/julien/go/pkg/mod/github.com/spf13/cobra@v1.6.1/command.go:968
github.com/julien040/gut/cmd.Execute()
/Users/julien/Code/gut/cmd/root.go:50 +0x28
main.main()
/Users/julien/Code/gut/main.go:27 +0x1c
To Reproduce
Steps to reproduce the behavior:
- Create a repo with exactly two commits
- Don't push any of them to the remote
- Run
gut squash
Expected behavior
squash
should be able to squash the first two commits into one.
Desktop (please complete the following information):
- OS: macOS
- Version 0.2.10
This is due to not handling this -1
in this function (src/controller/squash.go
)
func getIndexLatestCommitPushed(commits []object.Commit) int {
for i, commit := range commits {
if executor.GitRemoteContainsHash(commit.Hash.String()) {
return i
}
}
return -1
}
-1
happens when no commits have been pushed so far.