Monorepo for Tangled
0

Configure Feed

Select the types of activity you want to include in your feed.

knotserver/git: don't commit patchfile

Lewis: May this revision serve well! <lewis@tangled.org>

authored by

Lewis and committed by
Tangled
(Jul 13, 2026, 6:18 PM +0300) a00289e3 1a161332

+49 -10
+1 -10
knotserver/git/merge.go
··· 187 187 } 188 188 189 189 // else, apply using 'git apply' and commit it manually 190 - applyCmd, err := wrapCmd(exec.Command("git", "-C", g.path, "apply", patchFile)) 190 + applyCmd, err := wrapCmd(exec.Command("git", "-C", g.path, "apply", "--index", patchFile)) 191 191 if err != nil { 192 192 return fmt.Errorf("sandbox wrap for git apply: %w", err) 193 193 } 194 194 applyCmd.Stderr = &stderr 195 195 if err := applyCmd.Run(); err != nil { 196 196 return fmt.Errorf("patch application failed: %s", stderr.String()) 197 - } 198 - 199 - stderr.Reset() 200 - stageCmd, err := wrapCmd(exec.Command("git", "-C", g.path, "add", ".")) 201 - if err != nil { 202 - return fmt.Errorf("sandbox wrap for git add: %w", err) 203 - } 204 - if err := stageCmd.Run(); err != nil { 205 - return fmt.Errorf("failed to stage changes: %w", err) 206 197 } 207 198 208 199 commitArgs := []string{"-C", g.path, "commit", "--allow-empty"}
+48
knotserver/git/merge_test.go
··· 197 197 assert.Equal(t, "hello\n", content) 198 198 } 199 199 200 + func TestApplyPatch_DoesNotCommitPatchFile(t *testing.T) { 201 + h := helper(t) 202 + defer h.cleanup() 203 + 204 + repo := h.initRepo() 205 + 206 + patch := `diff --git a/scallop.txt b/scallop.txt 207 + new file mode 100644 208 + index 0000000..ce01362 209 + --- /dev/null 210 + +++ b/scallop.txt 211 + @@ -0,0 +1 @@ 212 + +hello 213 + ` 214 + 215 + patchFile, err := createTempIn(repo.path, patch) 216 + require.NoError(t, err) 217 + defer os.Remove(patchFile) 218 + 219 + opts := MergeOptions{ 220 + CommitMessage: "Add scallop.txt", 221 + CommitterName: "nel", 222 + CommitterEmail: "nel@nel.pet", 223 + FormatPatch: false, 224 + } 225 + 226 + err = repo.applyPatch(patch, patchFile, opts) 227 + require.NoError(t, err) 228 + 229 + refreshed, err := PlainOpen(repo.path) 230 + require.NoError(t, err) 231 + 232 + head, err := refreshed.r.Head() 233 + require.NoError(t, err) 234 + 235 + commit, err := refreshed.r.CommitObject(head.Hash()) 236 + require.NoError(t, err) 237 + 238 + tree, err := commit.Tree() 239 + require.NoError(t, err) 240 + 241 + _, err = tree.File("scallop.txt") 242 + assert.NoError(t, err, "patched file should be committed") 243 + 244 + _, err = tree.File(filepath.Base(patchFile)) 245 + assert.ErrorIs(t, err, object.ErrFileNotFound, "temporary patch file must not be committed") 246 + } 247 + 200 248 func TestApplyPatch_DeleteFile(t *testing.T) { 201 249 h := helper(t) 202 250 defer h.cleanup()