Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement commutable auto-commit mechanism #235

Open
wants to merge 2 commits into
base: gh/ezyang/181/base
Choose a base branch
from

Conversation

ezyang
Copy link
Owner

@ezyang ezyang commented Apr 7, 2025

Stack from ghstack (oldest at bottom):

We're going to tighten up our auto-commit mechanism. Currently, before we run a command, we commit ALL pending changes (including untracked files) before running the command. What I want to do now is create this commit, to be called PRE_COMMIT, but then reset the HEAD/index to the state it was before doing this commit (commit-tree might work too although we'll have to handle new untracked files correctly. They should remain untracked after the commit.) We run the command as usual. Now, we must assess the impact of the command. Easy case: no changes were made by command. Then we do nothing and can ignore the commit we made. Harder case: some changes were made. We now need to understand if the local changes and the new changes commute. First, synthetically construct the new change POST_COMMIT by creating a new commit (including all untracked files) but having its base be the PRE_COMMIT. This gives us a commit history POST_COMMIT -> PRE_COMMIT (where the arrow denotes parent). Now, we try to commute them, so we have PRE_COMMIT -> POST_COMMIT, using git cherry-pick. If the cherry-pick fails, or the new commuted patches have a different final tree than the original, we abort, and move HEAD to the un-commuted POST_COMMIT. However, if the cherry-pick succeeds, we can directly reset HEAD to be the commuted POST_COMMIT, in particular, the working tree will now have PRE_COMMIT's changes uncommitted, just like they were before hand.

4e2423b  (Base revision)
2513f81  Implement commutable auto-commit mechanism in run_code_command
5f456d2  Implement error handling for commutable auto-commit mechanism
dbf98a0  Create test file for commutable auto-commit mechanism
47ccb43  Create an improved test for commutable auto-commit mechanism
09bae9a  Auto-commit lint changes
HEAD     Auto-commit format changes

codemcp-id: 250-feat-implement-commutable-auto-commit-mechanism

[ghstack-poisoned]
ezyang added a commit that referenced this pull request Apr 7, 2025
We're going to tighten up our auto-commit mechanism. Currently, before we run a command, we commit ALL pending changes (including untracked files) before running the command. What I want to do now is create this commit, to be called PRE_COMMIT, but then reset the HEAD/index to the state it was before doing this commit (commit-tree might work too although we'll have to handle new untracked files correctly. They should remain untracked after the commit.) We run the command as usual. Now, we must assess the impact of the command. Easy case: no changes were made by command. Then we do nothing and can ignore the commit we made. Harder case: some changes were made. We now need to understand if the local changes and the new changes commute. First, synthetically construct the new change POST_COMMIT by creating a new commit (including all untracked files) but having its base be the PRE_COMMIT. This gives us a commit history POST_COMMIT -> PRE_COMMIT (where the arrow denotes parent). Now, we try to commute them, so we have PRE_COMMIT -> POST_COMMIT, using git cherry-pick. If the cherry-pick fails, or the new commuted patches have a different final tree than the original, we abort, and move HEAD to the un-commuted POST_COMMIT. However, if the cherry-pick succeeds, we can directly reset HEAD to be the *commuted* POST_COMMIT, in particular, the working tree will now have PRE_COMMIT's changes uncommitted, just like they were before hand.

```git-revs
4e2423b  (Base revision)
2513f81  Implement commutable auto-commit mechanism in run_code_command
5f456d2  Implement error handling for commutable auto-commit mechanism
dbf98a0  Create test file for commutable auto-commit mechanism
47ccb43  Create an improved test for commutable auto-commit mechanism
09bae9a  Auto-commit lint changes
HEAD     Auto-commit format changes
```

codemcp-id: 250-feat-implement-commutable-auto-commit-mechanism
ghstack-source-id: 2c99768ed135b1341eef8354531a46dd361af25c
Pull-Request-resolved: #235
[ghstack-poisoned]
ezyang added a commit that referenced this pull request Apr 8, 2025
We're going to tighten up our auto-commit mechanism. Currently, before we run a command, we commit ALL pending changes (including untracked files) before running the command. What I want to do now is create this commit, to be called PRE_COMMIT, but then reset the HEAD/index to the state it was before doing this commit (commit-tree might work too although we'll have to handle new untracked files correctly. They should remain untracked after the commit.) We run the command as usual. Now, we must assess the impact of the command. Easy case: no changes were made by command. Then we do nothing and can ignore the commit we made. Harder case: some changes were made. We now need to understand if the local changes and the new changes commute. First, synthetically construct the new change POST_COMMIT by creating a new commit (including all untracked files) but having its base be the PRE_COMMIT. This gives us a commit history POST_COMMIT -> PRE_COMMIT (where the arrow denotes parent). Now, we try to commute them, so we have PRE_COMMIT -> POST_COMMIT, using git cherry-pick. If the cherry-pick fails, or the new commuted patches have a different final tree than the original, we abort, and move HEAD to the un-commuted POST_COMMIT. However, if the cherry-pick succeeds, we can directly reset HEAD to be the *commuted* POST_COMMIT, in particular, the working tree will now have PRE_COMMIT's changes uncommitted, just like they were before hand.

```git-revs
4e2423b  (Base revision)
2513f81  Implement commutable auto-commit mechanism in run_code_command
5f456d2  Implement error handling for commutable auto-commit mechanism
dbf98a0  Create test file for commutable auto-commit mechanism
47ccb43  Create an improved test for commutable auto-commit mechanism
09bae9a  Auto-commit lint changes
74efb3f  Auto-commit format changes
18348d5  Snapshot before auto-accept
a2a093f  Update format test to handle both commit message formats
9eec6ee  Snapshot before codemcp change
6b0e0c9  Update lint test to handle both commit message formats
HEAD     Auto-commit format changes
```

codemcp-id: 250-feat-implement-commutable-auto-commit-mechanism
ghstack-source-id: 84668821e87633888772e89fa7077540b06f599f
Pull-Request-resolved: #235
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant