mystor / git-revise

A handy tool for doing efficient in-memory commit rebases & fixups

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fails to open editor

zmitchell opened this issue · comments

I just tried to invoke git revise -i and I get the following error:

foo$ git revise -i
bash: line 0: exec: 'nvim': not found
editor error: Editor exited with status Command '['bash', '-c', 'exec $(git var GIT_EDITOR) git-revise-todo']' returned non-zero exit status 127.

I'm using zsh, but I get the same error even if I try this command in a bash shell. Any ideas?

What is your current $PATH variable? Can you run nvim yourself from the command line? If not does which nvim resolve to something in your path? Have you tried setting $GIT_EDITOR to a full path? Are you able to run git rebase -i and have nvim open properly?

Here's my PATH:

/usr/local/opt/llvm/bin:/Users/zmitchell/.pyenv/shims:/Users/zmitchell/.local/bin:/Users/zmitchell/.cargo/bin:/Users/zmitchell/.cargo/bin:/Users/zmitchell/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/opt/fzf/bin

I can open nvim normally at the command line, and I can do git rebase -i and have nvim open properly. When I set git config core.editor to the full path to nvim, it works properly (though there's no highlighting, which I guess is a separate issue).

Interesting - that's odd. It might be due to how I'm running the subcommand. It seems like there are some issues with the way I'm invoking the editor right now :-/

@zmitchell Could you try this with the changes from a6909fe and 162ce95? I'm curious if those changes are sufficient to fix this issue.

Just to make sure I had a good baseline before checking those changes, I set my core.editor back to just nvim, and it worked. I exited my shell and tried again just to make sure there wasn't an issue with a stale git configuration. Now I'm wondering whether the repository needs to be in a particular state to trigger that bug? This sequence of events doesn't really make sense:

  • core.editor = nvim: doesn't work
  • core.editor = /usr/local/bin/nvim: works
  • core.editor = nvim: works

Edit: just to be clear, I haven't tried those changes because I don't know that it would be useful to apply the potential fix if I can't reproduce the bug with the "broken" code

Interesting! How do you have core.editor configured? I wonder if I'm running the git var GIT_EDITOR command in a different directory than would be expected, causing git to not respect repository-local configuration?

As far as I'm aware, just through my global .git_config.

~/.gitconfig:

[user]
	email = zmitchell@fastmail.com
	name = Zach Mitchell
[core]
	excludesfile = /Users/zmitchell/.gitignore_global
	editor = nvim

The core section from my local config:

[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
	ignorecase = true
	precomposeunicode = true
	editor = nvim

hi, i got a similar issue but on win10 with git bash:

my findings

this works: core.editor=t:/bin/pad

these dont:

  • core.editor=pad
  • core.editor=~/bin/pad

despite the fact that ~/bin is on my path

Note

  • pad is the notepad2.exe renamed to pad
  • $HOME and their windows equivalents are all pointing to T:\ wrt to windows and ~ wrt to bash
  • all git coomands using the editor (eg config -e --global) work with any of the above configs quite well just not with git revise.

better error message

it took me a little while to pinpoint the problem b/c the stack trace is not very telling:

...
    response = run_editor(
  File "t:\bin\python38\lib\site-packages\gitrevise\utils.py", line 127, in run_editor
    data = edit_file(repo, path)
  File "t:\bin\python38\lib\site-packages\gitrevise\utils.py", line 71, in edit_file
    run(cmd, check=True, cwd=path.parent)
  File "t:\bin\python38\lib\subprocess.py", line 489, in run
    with Popen(*popenargs, **kwargs) as process:
  File "t:\bin\python38\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "t:\bin\python38\lib\subprocess.py", line 1307, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

i only figured this out by looking at gitrevise\utils.py", line 71, and having seen this issue by chance some time before it

my setup

now, my setup is a bit special b/c i separate my different dev envs via a complete set of environment vars, so

  • all programs that i use are started from a controlz process that defines my ENV vars which are inherited to all child processes
  • all my dev software is installed and run from within that, e.g also the full python install which is under t:\bin\python38
  • I do most of my work under git bash so the env vars count here

Unfortunately git revise doesn't handle paths for editor on win32 consistently with other git subcommands. This is due to the python executable running the revise command being a native win32 application, rather than a git-bash msys program.

The current behaviour is a bit weird, and handled using a trick suggested to me in #19 (comment), as I couldn't find a good way to reliably return to the git-bash environment from within git-revise.

FYI:

What: The config that i had, stopped working

  • not sure which changes on my system since it worked last but these might be among them
    • installed new git version
    • became local admin (it's a company laptop)
    • installed WSL
    • ...

among errors that i got was this:

Traceback (most recent call last):
  File "w:\tools\python36\lib\site-packages\gitrevise\utils.py", line 64, in edit_file
    cwd=path.parent,
  File "w:\tools\python36\lib\subprocess.py", line 418, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['bash', '-c', 'exec $(git var GIT_EDITOR) git-revise-todo']' returned non-zero exit status 127.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "w:\tools\python36\lib\site-packages\gitrevise\tui.py", line 191, in main
    inner_main(args, repo)
  File "w:\tools\python36\lib\site-packages\gitrevise\tui.py", line 182, in inner_main
    interactive(args, repo, staged, head)
  File "w:\tools\python36\lib\site-packages\gitrevise\tui.py", line 99, in interactive
    todos = edit_todos(repo, todos, msgedit=args.edit)
  File "w:\tools\python36\lib\site-packages\gitrevise\todo.py", line 213, in edit_todos
    """,
  File "w:\tools\python36\lib\site-packages\gitrevise\utils.py", line 102, in run_editor
    data = edit_file(path)
  File "w:\tools\python36\lib\site-packages\gitrevise\utils.py", line 67, in edit_file
    raise EditorError(f"Editor exited with status {err}")
gitrevise.utils.EditorError: Editor exited with status Command '['bash', '-c', 'exec $(git var GIT_EDITOR) git-revise-todo']' returned non-zero exit status 127.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "w:\tools\python36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "w:\tools\python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "W:\TOOLS\Python36\scripts\git-revise.exe\__main__.py", line 9, in <module>
  File "w:\tools\python36\lib\site-packages\gitrevise\tui.py", line 191, in main
    inner_main(args, repo)
  File "w:\tools\python36\lib\site-packages\gitrevise\odb.py", line 218, in __exit__
    self._tempdir.__exit__(exc_type, exc_val, exc_tb)
  File "w:\tools\python36\lib\tempfile.py", line 807, in __exit__
    self.cleanup()
  File "w:\tools\python36\lib\tempfile.py", line 811, in cleanup
    _shutil.rmtree(self.name)
  File "w:\tools\python36\lib\shutil.py", line 494, in rmtree
    return _rmtree_unsafe(path, onerror)
  File "w:\tools\python36\lib\shutil.py", line 393, in _rmtree_unsafe
    onerror(os.rmdir, path, sys.exc_info())
  File "w:\tools\python36\lib\shutil.py", line 391, in _rmtree_unsafe
    os.rmdir(path)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'w:\\CODE\\mdm\\.git\\revise.uvt_6o25'

when i removed the core.editor setting and aslo in some other case that i cant remember it just would start nano (being the default) but it would be always empty !?

my guess the root cause PermissionError: [WinError 32] The process cannot access the file because it is being used by another hits here too but isn't shown.

Anyhow, after re-installing the newest version (0.5.1) of git-revise i got it working again, but only if i set GIT_EDITOR or core.editor to a globally available editor on the PATH.
In my case this is notepad2.exe which lives in the tortoise folder. However, i must not spec a spath just the executable, ie: editor = notepad2.exe