diff --git a/internal/git/gogit/git.go b/internal/git/gogit/git.go index 4314c411..5bbb9c89 100755 --- a/internal/git/gogit/git.go +++ b/internal/git/gogit/git.go @@ -95,6 +95,22 @@ func (g *Git) Commit(commitAuthor *internalgit.CommitAuthor, commitMessage strin return err } + status, err := w.Status() + if err != nil { + return err + } + + // This is a workaround for a bug in go-git where "add all" does not add deleted files + // If https://github.com/go-git/go-git/issues/223 is fixed, this can be removed + for file, s := range status { + if s.Worktree == git.Deleted { + _, err = w.Add(file) + if err != nil { + return err + } + } + } + // Get the current hash to be able to diff it with the committed changes later oldHead, err := g.repo.Head() if err != nil { diff --git a/tests/scripts/remover/main.go b/tests/scripts/remover/main.go new file mode 100644 index 00000000..2d3ec7bc --- /dev/null +++ b/tests/scripts/remover/main.go @@ -0,0 +1,9 @@ +package main + +import ( + "os" +) + +func main() { + os.Remove("test_file") +} diff --git a/tests/table_test.go b/tests/table_test.go index a52815c6..6f242722 100644 --- a/tests/table_test.go +++ b/tests/table_test.go @@ -878,6 +878,34 @@ Repositories with a successful run: assert.True(t, vcMock.PullRequests[0].Draft) }, }, + + { + name: "remove files", + vcCreate: func(t *testing.T) *vcmock.VersionController { + repo := createRepo(t, "owner", "should-delete", "i like apples") + addFile(t, repo.Path, "test_file", "some content", "added test_file") + return &vcmock.VersionController{ + Repositories: []vcmock.Repository{ + repo, + }, + } + }, + args: []string{ + "run", + "--author-name", "Test Author", + "--author-email", "test@example.com", + "-B", "custom-branch-name", + "-m", "custom message", + fmt.Sprintf("go run %s", filepath.ToSlash(filepath.Join(workingDir, "scripts/remover/main.go"))), + }, + verify: func(t *testing.T, vcMock *vcmock.VersionController, runData runData) { + require.Len(t, vcMock.PullRequests, 1) + + changeBranch(t, vcMock.Repositories[0].Path, "custom-branch-name", false) + + assert.False(t, fileExist(t, vcMock.Repositories[0].Path, "test_file")) + }, + }, } for _, gitBackend := range gitBackends {