-
-
Notifications
You must be signed in to change notification settings - Fork 61
Consider git's core.editor configuration #156
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -751,10 +751,22 @@ def test(*args): | |
|
||
|
||
def find_editor(): | ||
# Try environment variables. Check more specific settings first so | ||
# they can override less specific values. | ||
for var in 'GIT_EDITOR', 'EDITOR': | ||
editor = os.environ.get(var) | ||
if editor is not None: | ||
return editor | ||
|
||
# Try git configuration - this checks both project configuration | ||
# (.git/config) and global configuration (~/.gitconfig). | ||
editor = git_core_editor() | ||
if editor: | ||
return editor | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note, though, that the value from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it has a default value of "vi" anywhere then I really don't want to use it. vi is a fine editor--I've been using it for thirty years--but it's confusing for beginners, and beginners are exactly the population who won't have an explicit editor set. I already put my foot down about explicitly listing "vi" as a default editor in blurb. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it will be useful if we can add some instructions on how people can setup their favorite editor for blurb, or at least some explanation on how blurb choose which editor to use. I'm on Macbook. The first time I used blurb, it opened the default and unfamiliar editor, I almost didn't know how to exit 😓 Because I've been following core-workflow and devguide updates, I knew that the default editor can be changed by setting the EDITOR env variable. New users wouldn't know this and will have to look at the code to find out. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It's configure option, and default value of the configure option is At least, Ubuntu uses But most important fact is it's always same to editor which There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably also be checked for existence, since on Windows it may give something inaccessible (something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem with checking for existence is ignoring bad user configuration, and falling back to something else. If a user have bad configuration, we should fail loudly instead of trying to fix it. Checking git documentation, I see a very clear advice how to configure the editor, and I don't see For example this is how git recommend way to configure notepad++:
And there is a warning about not using this configuration. Since editor may return a string like "command -option ...", we cannot use the value as is, since subprocess.run([editor, tmp_path]) So on windows, both environment variables and git core.editor may not be useful with the current |
||
|
||
# Try to use a user friendly platform specific fallback. We | ||
# intentionally not using 'vi' as a fallback, assuming that fallback | ||
# is needed for new users. | ||
if sys.platform == 'win32': | ||
fallbacks = ['notepad.exe'] | ||
else: | ||
|
@@ -766,9 +778,23 @@ def find_editor(): | |
found_path = shutil.which(fallback) | ||
if found_path and os.path.exists(found_path): | ||
return found_path | ||
|
||
# For simplicity, recommend the old EDITOR environment varibale. Advanced | ||
# users should consult the documention if they want to use more specific | ||
# confguration. | ||
error('Could not find an editor! Set the EDITOR environment variable.') | ||
|
||
|
||
def git_core_editor(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I generally prefer functions be defined earlier in the file than they are used. I'm not sure it's worth factoring this out to its own function anyway, since it's only called in one place. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer the opposite, putting helpers at the bottom, but I can move the function before find_editor if you like. I'm pretty sure about the keeping the logic in a function, the way to get git configuration is not interesting to the editor lookup code. |
||
try: | ||
return run('git config --get core.editor').strip() | ||
except subprocess.CalledProcessError as e: | ||
if e.returncode == 1: | ||
# core.etitor not configured | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/etitor/editor/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, will fix. |
||
return None | ||
raise | ||
|
||
|
||
@subcommand | ||
def add(): | ||
""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we should keep this bit as a way to customize blurb usage apart from git. Particularly since we still have an error message below that says you should set EDITOR (which no longer directly does anything here).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why customize something git is doing fine? blurb is just a git wrapper, let it use git facilities. We can fix the error message to refer to setting up git.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blurb is only partly a git wrapper in that it is nice enough to stage the change for you. Take that out and it has nothing to do with git but is still useful to help create the news entry (which is what
blurb add
is really all about). So leavingEDITOR
in makes sense from a usability perspective since it doesn't add much code complexity.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do Not remove support for EDITOR. That's been a UNIX standard for thirty years.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blurb is not a "git wrapper". If we stopped using git we would continue using blurb.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that git-wrapper was not a good definition, more like blurb is implemented using git.
My reasoning is:
if git commit uses your editor, so will blurb
This patch does not remove support for EDITOR - git var GIT_EDITOR supports it. From git manual:
I don't see a need for customizing git behavior. Delegating the editor choice to git
will make this tool easy to use for new developers, assuming they are already
using git.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The patch removes $EDITOR. $EDITOR should be the first thing checked.
As I've already mentioned, $EDITOR has been a UNIX shell standard in excess of thirty years. It should be the first place a tool looks for the user's preferred text editor. I'm happy to accept a patch that adds uses 'git var GIT_EDITOR' in a sensible way, but blurb must check $EDITOR first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll try to integrate git var in a sensible way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, wait a minute. Does "git var GIT_EDITOR" still use vi as a default value? Because I won't allow blurb to run "vi" unless the user has explicitly configured something to use it.