Repository: lindell/multi-gitter (go)

Issue:
Deleting files produces empty commits
**Describe the bug**
Deleting a file produces empty commits instead of deleting them

**To Reproduce**

Run the following command on a test repository containing a `README.md` (you can fork [mine](https://github.com/klieret/multi-gitter-delete-bug-demonstration)):

```bash
multi-gitter run "rm README.md" -R klieret/multi-gitter-delete-bug-demonstration -m "Remove file"
```

**Expected behavior**

I expect a commit that has `README.md` deleted.

**What happens instead**

The output looks normal:

```
INFO[0000] Running on 1 repositories
INFO[0000] Cloning and running script                    repo=klieret/multi-gitter-delete-bug-demonstration
INFO[0000] Pushing changes to remote                     repo=klieret/multi-gitter-delete-bug-demonstration
INFO[0001] Creating pull request                         repo=klieret/multi-gitter-delete-bug-demonstration
Repositories with a successful run:
  klieret/multi-gitter-delete-bug-demonstration #1
```

But you get a [PR with an empty commit](https://github.com/klieret/multi-gitter-delete-bug-demonstration/pull/1). Which is bad because the `README.md` should be deleted, but also bad because empty commits shouldn't be added by multi-gitter.


Pull request:
fix: deleted files are now detected with `git-type: go`
# What does this change
Implements workaround where go-git would not add deleted files to the commit. It can hopefully be removed in the future. 

# What issue does it fix
Closes #266 

# Checklist
- [x] Made sure the PR follows the [CONTRIBUTING.md](CONTRIBUTING.md) guidelines
- [x] Tests if something new is added


Patch:
diff --git a/internal/git/gogit/git.go b/internal/git/gogit/git.go
index 4314c41..5bbb9c8 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 {


Test patch:
diff --git a/tests/scripts/remover/main.go b/tests/scripts/remover/main.go
new file mode 100644
index 0000000..2d3ec7b
--- /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 a52815c..6f24272 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 {