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

Notepad2 as editor gives logs and errors #517

Closed
GerjanOnline opened this issue Nov 4, 2015 · 10 comments
Closed

Notepad2 as editor gives logs and errors #517

GerjanOnline opened this issue Nov 4, 2015 · 10 comments

Comments

@GerjanOnline
Copy link

I am using:
Windows 10 x64
Git version 2.6.2.windows.1
Notepad2 x64 (this one overrides notepad)

.gitconfig

[core]
    editor = notepad
    autocrlf = true (also tried false)
  ...

When I do git config -e --global:

git config --global -e
unix2dos: C:/Users/user/.gitconfig MODE 0100644  (regular file)
unix2dos: using C:/Users/user/d2utmphK5NvM as temporary file
unix2dos: converting file C:/Users/user/.gitconfig to DOS format...
dos2unix: C:/Users/user/.gitconfig MODE 0100644  (regular file)
dos2unix: using C:/Users/user/d2utmpW2rV1K as temporary file
dos2unix: converting file C:/Users/user/.gitconfig to Unix format...

When i do git commit --amend (just to do a commit):

git commit --amend
unix2dos: path/public/.git/COMMIT_EDITMSG MODE 0100644  (regular file)
unix2dos: using path/public/.git/d2utmpX1LaLG as temporary file
unix2dos: converting file path/public/.git/COMMIT_EDITMSG to DOS format...
dos2unix: path/public/.git/COMMIT_EDITMSG MODE 0100644  (regular file)
dos2unix: using path/public/.git/d2utmpn8txZW as temporary file
dos2unix: converting file path/public/.git/COMMIT_EDITMSG to Unix format...
error: There was a problem with the editor 'notepad'.
Please supply the message using either -m or -F option.

Why do I get these messages? When I have atom as my editor it doesn't give me these messages...

@GerjanOnline
Copy link
Author

Related to #430 and #381?

@GerjanOnline
Copy link
Author

After some digging it seems that:

C:\Program Files\Git\usr\bin\notepad

is the problem.

#!/bin/sh
die () {
    echo "$*" >&2
    exit 1
}
test $# = 1 ||
die "Usage: $0 "
if test -f "$1"
then
    unix2dos.exe "$1"
fi &&
notepad.exe "$1" &&
dos2unix.exe "$1" &&
case "$1" in
*/COMMIT_EDITMSG|*\\COMMIT_EDITMSG)
    columns="$(git config format.commitmessagecolumns)" &&
    if test -z "$columns"
    then
        msg="$(fmt.exe -s -w "$columns" "$1")" &&
        printf "%s" "$msg" >"$1"
    fi
    ;;
esac

This is new? Some kind of helper?

@shiftkey
Copy link

shiftkey commented Nov 4, 2015

@kgybels
Copy link

kgybels commented Nov 4, 2015

@GerjanOnline Yes, it is a helper for using plain notepad.

Since you are using Notepad2 instead, maybe setup your editor like this:
git config --global core.editor "'C:/Program Files/Notepad2/Notepad2.exe'"

@GerjanOnline
Copy link
Author

git-for-windows/build-extra@69b301b makes sense.

Thanks @shiftkey and @kgybels

@domenic
Copy link

domenic commented Nov 5, 2015

Can I turn this off somehow? I am used to being able to just type notepad foo.txt and edit my files in Notepad2. But now it converts all their line feeds when it does so, which is pretty strange...

I can just delete the /usr/bin/notepad script for now, I guess, but it will presumably come back in an upgrade. Can we add an option to remove it entirely?

@kgybels
Copy link

kgybels commented Nov 5, 2015

@domenic Maybe you can create an alias to work around your issue:
$ alias notepad='/c/Program\ Files/Notepad2/Notepad2.exe'

You could even use n instead of notepad, then you don't have to type as much :)

@dscho
Copy link
Member

dscho commented Nov 9, 2015

unix2dos: path/public/.git/COMMIT_EDITMSG MODE 0100644 (regular file)
unix2dos: using path/public/.git/d2utmpX1LaLG as temporary file
unix2dos: converting file path/public/.git/COMMIT_EDITMSG to DOS format...
dos2unix: path/public/.git/COMMIT_EDITMSG MODE 0100644 (regular file)
dos2unix: using path/public/.git/d2utmpn8txZW as temporary file
dos2unix: converting file path/public/.git/COMMIT_EDITMSG to Unix format...
error: There was a problem with the editor 'notepad'.
Please supply the message using either -m or -F option.

From this output, together with the original lines:

if test -f "$1"
then
    unix2dos.exe "$1"
fi &&
notepad.exe "$1" &&
dos2unix.exe "$1" &&
case "$1" in
*/COMMIT_EDITMSG|*\\COMMIT_EDITMSG)
    columns="$(git config format.commitmessagecolumns)" &&
    if test -z "$columns"
    then
        msg="$(fmt.exe -s -w "$columns" "$1")" &&
        printf "%s" "$msg" >"$1"
    fi
    ;;
esac

it appears that notepad.exe is run correctly, as is dos2unix.exe, but then a problem occurs because the exit status is not zero.

The really interesting part would be to investigate which command fails (is it dos2unix.exe, without an error message? Or fmt.exe? Or printf? Or is it impossible to write to "$1"?

These questions need to be answered instead of papering over the problem by deleting the /usr/bin/notepad file (which would reappear with the next upgrade, as has been suspected correctly).

@kgybels
Copy link

kgybels commented Nov 9, 2015

@dscho git config format.commitmessagecolumns will exit with code 1 if the section or key is invalid. The way the notepad script is written that will cause the whole script to also exit with code 1.

Also, if test -z "$columns" shouldn't this be if test -n "$columns"?

@dscho
Copy link
Member

dscho commented Nov 9, 2015

git config format.commitmessagecolumns will exit with code 1 if the section or key is invalid. The way the notepad script is written that will cause the whole script to also exit with code 1.

Also, if test -z "$columns" shouldn't this be if test -n "$columns"?

Yep, those are both bugs.

dscho added a commit to dscho/build-extra that referenced this issue Nov 9, 2015
Uh oh. It seems that the patch that got merged into `master` somehow
was not the patch that was tested, but instead a faulty one.

The problem was that `git config <key>` returns an error if the
key was not found and it made the code fail when no column wrapping
was configured (and besides, the test for the column wrapping was
inverted).

To prove that *this* commit is good, it was made using

	git -c core.editor=notepad -c format.commitmessagecolumns=72
	commit -s

This fixes git-for-windows/git#517

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants