Skip to content

Commit

Permalink
Fix hunk delete operation.
Browse files Browse the repository at this point in the history
  • Loading branch information
manateelazycat committed Oct 6, 2024
1 parent cb6c3b2 commit c9634a7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
__pycache__
node_modules/
dist/
tags
tags
.aider*
21 changes: 12 additions & 9 deletions buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1012,10 +1012,12 @@ def status_delete_hunk(self, type, patch_index, hunk_index):

def handle_discard_unstage_hunk(self):
patch = copy(self.raw_patch_set[self.patch_index])
for index, hunk in enumerate(patch):
if index != self.hunk_index:
patch.remove(hunk)
result = get_command_result("cd {}; git apply --reverse".format(self.repo_root), str(patch))
hunk = patch[self.hunk_index]
hunk_str = str(hunk)

# Add diff header
hunk_str = f"diff --git a/{patch.path} b/{patch.path}\nindex 1234567..89abcdef 100644\n--- a/{patch.path}\n+++ b/{patch.path}\n{hunk_str}"
result = get_command_result("cd {}; git apply --reverse".format(self.repo_root), hunk_str)

if result == "":
message_to_emacs("Discard unstage hunk successfully!")
Expand All @@ -1026,14 +1028,15 @@ def handle_discard_unstage_hunk(self):

def handle_discard_stage_hunk(self):
patch = copy(self.raw_patch_set[self.patch_index])
for index, hunk in enumerate(patch):
if index != self.hunk_index:
patch.remove(hunk)
hunk = patch[self.hunk_index]
hunk_str = str(hunk)

result = get_command_result("cd {}; git apply --reverse --cached".format(self.repo_root), str(patch))
# Add diff header
hunk_str = f"diff --git a/{patch.path} b/{patch.path}\nindex 1234567..89abcdef 100644\n--- a/{patch.path}\n+++ b/{patch.path}\n{hunk_str}"
result = get_command_result("cd {}; git apply --reverse --cached".format(self.repo_root), hunk_str)
if result == "":
get_command_result("cd {}; git update-index --refresh")
result = get_command_result("cd {}; git apply --reverse".format(self.repo_root), str(patch))
result = get_command_result("cd {}; git apply --reverse".format(self.repo_root), hunk_str)

if result == "":
message_to_emacs("Discard this stage hunk successfully!")
Expand Down

0 comments on commit c9634a7

Please sign in to comment.