Skip to content

Conversation

@rogeralsing
Copy link
Contributor

Summary

  • add an apply_patch internal command that parses headless diff blocks, applies hunks with optional whitespace-insensitive matching, and formats rich error output
  • wire the command into the runtime's default internal command registry and expose configuration via new helpers
  • cover the command with unit tests exercising success, whitespace enforcement, file creation, help output, and missing patch handling while adding the go-diff dependency

Testing

  • go test ./...

https://chatgpt.com/codex/tasks/task_e_68fddddefdd08328b65ac9552f88460c

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +424 to +441
func writeFileState(state *fileState) error {
if state == nil {
return nil
}
content := strings.Join(state.lines, "\n")
if state.originalEndsWithNew != nil {
if *state.originalEndsWithNew && !strings.HasSuffix(content, "\n") {
content += "\n"
} else if !*state.originalEndsWithNew && strings.HasSuffix(content, "\n") {
content = strings.TrimSuffix(content, "\n")
}
}
if err := os.MkdirAll(filepath.Dir(state.path), 0o755); err != nil {
return fmt.Errorf("apply_patch: failed to create parent directory for %s: %v", state.relativePath, err)
}
if err := os.WriteFile(state.path, []byte(content), 0o666); err != nil {
return fmt.Errorf("apply_patch: failed to write %s: %v", state.relativePath, err)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve existing file permissions when writing patched files

The command writes every modified file with os.WriteFile(..., 0o666) without remembering the original mode. If the patch touches an executable or otherwise permissioned file, the execute bits are dropped and the file becomes non-executable after the patch. Standard patch tools preserve existing permissions. Consider recording the source file’s mode in ensureFileState and reusing it (or reapplying it with os.Chmod) when saving the updated content.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants