Skip to content

Commit 0556c78

Browse files
authored
edit: Run editor from cwd, not parent of file (#118)
* edit: Run editor from cwd, not parent of file This is how git-rebase does it, and doing so makes it easier to refer to local files/notes when composing edit messages, rather than being plopped into a random tmpdir. * edit+merge: show relative paths, not anchored at / This is more consistent with how git-rebase does it. Anchoring at `/` is misleading because it displays an absolute path that usually does not exist!
1 parent 60a2f4a commit 0556c78

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

gitrevise/merge.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def get_tree(cmt: Optional[Commit]) -> Tree:
4545
return cmt.tree() if cmt is not None else Tree(repo, b"")
4646

4747
tree = merge_trees(
48-
Path("/"),
48+
Path(),
4949
(get_summary(new_parent), get_summary(orig_parent), get_summary(commit)),
5050
get_tree(new_parent),
5151
get_tree(orig_parent),
@@ -237,7 +237,7 @@ def merge_blobs(
237237

238238
# Open the editor on the conflicted file. We ensure the relative path
239239
# matches the path of the original file for a better editor experience.
240-
conflicts = tmpdir / "conflict" / path.relative_to("/")
240+
conflicts = tmpdir / "conflict" / path
241241
conflicts.parent.mkdir(parents=True, exist_ok=True)
242242
conflicts.write_bytes(preimage)
243243
merged = edit_file(repo, conflicts)

gitrevise/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ def local_commits(repo: Repository, tip: Commit) -> Tuple[Commit, List[Commit]]:
6666

6767
def edit_file_with_editor(editor: str, path: Path) -> bytes:
6868
try:
69-
cmd = [sh_path(), "-ec", f'{editor} "$@"', editor, path.name]
70-
run(cmd, check=True, cwd=path.parent)
69+
cmd = [sh_path(), "-ec", f'{editor} "$@"', editor, str(path)]
70+
run(cmd, check=True)
7171
except CalledProcessError as err:
7272
raise EditorError(f"Editor exited with status {err}") from err
7373
return path.read_bytes()

tests/test_fixup.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
from contextlib import contextmanager
32
from typing import (
43
Generator,
@@ -137,27 +136,27 @@ def test_fixup_nonhead_conflict(basic_repo: Repository) -> None:
137136
with editor_main(["HEAD~"], input=b"y\ny\ny\ny\n") as ed:
138137
with ed.next_file() as f:
139138
assert f.equals_dedent(
140-
f"""\
141-
<<<<<<< {os.sep}file1 (new parent): commit1
139+
"""\
140+
<<<<<<< file1 (new parent): commit1
142141
Hello, World!
143142
How are things?
144143
=======
145144
conflict
146-
>>>>>>> {os.sep}file1 (current): <git index>
145+
>>>>>>> file1 (current): <git index>
147146
"""
148147
)
149148
f.replace_dedent("conflict1\n")
150149

151150
with ed.next_file() as f:
152151
assert f.equals_dedent(
153-
f"""\
154-
<<<<<<< {os.sep}file1 (new parent): commit1
152+
"""\
153+
<<<<<<< file1 (new parent): commit1
155154
conflict1
156155
=======
157156
Hello, World!
158157
Oops, gotta add a new line!
159158
How are things?
160-
>>>>>>> {os.sep}file1 (current): commit2
159+
>>>>>>> file1 (current): commit2
161160
"""
162161
)
163162
f.replace_dedent("conflict2\n")

0 commit comments

Comments
 (0)