git-gui patch staging errors
Hey all,
I ran into an interesting problem this week where git gui was erroring out on staging partial patches in a particular file I was working on.
I worked around it with "git add -i," which worked like a champ.
I later realized the source file has some special characters (Unicode, probably) in it to print emojis (or colors or whatever fun animations the kids want on their terminals these days).
Interestingly, lines/hunks before the first Unicode character will partial-stage appropriately, but attempting to stage any hunks/lines after the characters produces a "Failed to stage selected line. error: patch failed ... error: ... patch does not apply" error dialog.
This can be reproduced by cloning
https://github.com/debek/aws-glacier-multipart-upload.git and editing glacierupload.sh; the special characters are in echo statements on lines 60, 74, and 97.
Removing these control characters seems to calm git gui's indigestion on this file.
[preed@underworld ~]$ git --version
git version 2.26.2
[preed@underworld ~]$ git gui --version
git-gui version 0.21.0.66.ga5728
best,
preed
Signature · 3 lines
J. Paul Reed https://jpaulreed.com PGP: 0xDF8708F8
Hi,
Quoted 17 lines · J. Paul Reed
Hey all,
I ran into an interesting problem this week where git gui was erroring out on staging partial patches in a particular file I was working on.
I worked around it with "git add -i," which worked like a champ.
I later realized the source file has some special characters (Unicode, probably) in it to print emojis (or colors or whatever fun animations the kids want on their terminals these days).
Interestingly, lines/hunks before the first Unicode character will partial-stage appropriately, but attempting to stage any hunks/lines after the characters produces a "Failed to stage selected line. error: patch failed ... error: ... patch does not apply" error dialog.
Quoted 4 lines
This can be reproduced by cloning
https://github.com/debek/aws-glacier-multipart-upload.git and editingglacierupload.sh; the special characters are in echo statements on lines 60, 74, and 97.
I can't reproduce it. I cloned the repo and then edited the file at line 60 with a diff that looks something like:
diff --git a/glacierupload.sh b/glacierupload.sh index 3b956c7..265349b 100755 --- a/glacierupload.sh +++ b/glacierupload.sh @@ -57,7 +57,9 @@ fi
# count the number of files that begin with "$prefix" fileCount=$(ls -1 | grep "^$prefix" | wc -l) -echo "📦 Glacier Upload with $AWS_PROFILE" +bar +echo "📦 Glacier s Upload with $AWS_PROFILE" +foo echo "Total parts to upload: " $fileCount
# get the list of part files to upload. Edit this if you chose a different prefix in the split command
I tried a bunch of combinations if partially staging parts of this diff, but everything worked fine without any error message. The emoji didn't render properly (though that might be my font's problem), but there were no problems in partial staging or unstaging.
Does this example work fine on your system or does it error out? Could you give an example diff where git-gui has problems while staging? Maybe something in your config is different?
Quoted 10 lines
Removing these control characters seems to calm git gui's indigestion on this file.
[preed@underworld ~]$ git --version
git version 2.26.2
[preed@underworld ~]$ git gui --version
git-gui version 0.21.0.66.ga5728best,
preed
Signature · 2 lines
Regards, Pratyush Yadav
-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Pratyush Yadav
Sent: 12 May 2020 13:15
To: J. Paul Reed <[email protected]>
Cc: [email protected]
Subject: Re: git-gui patch staging errors
Hi,
Quoted 12 lines · J. Paul Reed
Hey all,
I ran into an interesting problem this week where git gui was erroring out on staging partial patches in a particular file I was working on.
I worked around it with "git add -i," which worked like a champ.
I later realized the source file has some special characters (Unicode, probably) in it to print emojis (or colors or whatever fun animations the kids want on their terminals these days).
Quoted 6 lines
Interestingly, lines/hunks before the first Unicode character will partial-stage appropriately, but attempting to stage any hunks/lines after the characters produces a "Failed to stage selected line. error:
patch failed ... error: ... patch does not apply" error dialog.This can be reproduced by cloning
I can't reproduce it. I cloned the repo and then edited the file at line 60 with a diff that looks something like:
diff --git a/glacierupload.sh b/glacierupload.sh index 3b956c7..265349b 100755 --- a/glacierupload.sh +++ b/glacierupload.sh @@ -57,7 +57,9 @@ fi
# count the number of files that begin with "$prefix" fileCount=$(ls -1 | grep "^$prefix" | wc -l) -echo "📦 Glacier Upload with $AWS_PROFILE" +bar +echo "📦 Glacier s Upload with $AWS_PROFILE" +foo echo "Total parts to upload: " $fileCount
# get the list of part files to upload. Edit this if you chose a different prefix in the split command
I tried a bunch of combinations if partially staging parts of this diff, but everything worked fine without any error message. The emoji didn't render properly (though that might be my font's problem), but there were no problems in partial staging or unstaging.
Does this example work fine on your system or does it error out? Could you give an example diff where git-gui has problems while staging? Maybe something in your config is different?
Quoted 10 lines
Removing these control characters seems to calm git gui's indigestion on this file.
[preed@underworld ~]$ git --version
git version 2.26.2
[preed@underworld ~]$ git gui --version git-gui version 0.21.0.66.ga5728best,
preed
-----------------------
I've recently found something very similar to this using the Fork Gui. I am tempted to report it to that project, but on seeing something similar here perhaps both Fork and Gut-Gui have a similar issue relating to Gui applications for Git?
If the chunk I want to stage includes characters in some category [1], then an attempt to Stage that chunk will fail with a similar fault to what is described here. (I don't have one available to me at the moment to check whether it is exactly this failure)
I have recently found myself cutting and pasting some chunks of text from a PDF into my C++ source, and in particular that includes "handed" quotes, rather than the usual use of the usual single quote character (ie the apostrophe). If I then use Fork's ability to Stage chunks of text containing these (or possibly not containing, but close after) I get this failure reported. The work-around is to do it from the command line using "git add --patch", which works fine.
Regards,
Richard.
[1]
I can't be entirely sure of the category as I haven't looked for the codes yet, but it is presumably some group of characters outside the basic ASCII page.
PS Sorry about posting style, I'm using Outlook and I've yet to find a way of getting it to help out by indenting everything using ">".
Quoted 63 lines · Richard
-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Pratyush Yadav
Sent: 12 May 2020 13:15
To: J. Paul Reed <[email protected]>
Cc: [email protected]
Subject: Re: git-gui patch staging errorsHi,
Quoted 12 lines · J. Paul Reed
Hey all,
I ran into an interesting problem this week where git gui was erroring out on staging partial patches in a particular file I was working on.
I worked around it with "git add -i," which worked like a champ.
I later realized the source file has some special characters (Unicode, probably) in it to print emojis (or colors or whatever fun animations the kids want on their terminals these days).
Quoted 6 lines
Interestingly, lines/hunks before the first Unicode character will partial-stage appropriately, but attempting to stage any hunks/lines after the characters produces a "Failed to stage selected line. error:
patch failed ... error: ... patch does not apply" error dialog.This can be reproduced by cloning
I can't reproduce it. I cloned the repo and then edited the file at line 60 with a diff that looks something like:
diff --git a/glacierupload.sh b/glacierupload.sh index 3b956c7..265349b 100755 --- a/glacierupload.sh +++ b/glacierupload.sh @@ -57,7 +57,9 @@ fi# count the number of files that begin with "$prefix" fileCount=$(ls -1 | grep "^$prefix" | wc -l) -echo "📦 Glacier Upload with $AWS_PROFILE" +bar +echo "📦 Glacier s Upload with $AWS_PROFILE" +foo echo "Total parts to upload: " $fileCount# get the list of part files to upload. Edit this if you chose a different prefix in the split commandI tried a bunch of combinations if partially staging parts of this diff, but everything worked fine without any error message. The emoji didn't render properly (though that might be my font's problem), but there were no problems in partial staging or unstaging.
Does this example work fine on your system or does it error out? Could you give an example diff where git-gui has problems while staging? Maybe something in your config is different?
Quoted 10 lines
Removing these control characters seems to calm git gui's indigestion on this file.
[preed@underworld ~]$ git --version
git version 2.26.2
[preed@underworld ~]$ git gui --version git-gui version 0.21.0.66.ga5728best,
preed
Quoted 6 lines
-----------------------
I've recently found something very similar to this using the Fork Gui. I am tempted to report it to that project, but on seeing something similar here perhaps both Fork and Gut-Gui have a similar issue relating to Gui applications for Git?
If the chunk I want to stage includes characters in some category [1], then an attempt to Stage that chunk will fail with a similar fault to what is described here. (I don't have one available to me at the moment to check whether it is exactly this failure)
I have recently found myself cutting and pasting some chunks of text from a PDF into my C++ source, and in particular that includes "handed" quotes, rather than the usual use of the usual single quote character (ie the apostrophe). If I then use Fork's ability to Stage chunks of text containing these (or possibly not containing, but close after) I get this failure reported. The work-around is to do it from the command line using "git add --patch", which works fine.
I suspect this is an encoding mismatch, but I wonder why it doesn't show up on my system but does on Paul's. Anyway, I would be surprised if the two bugs in Git Gui and Fork Gui are related in any way other than two programmers making the same mistake by chance.
Quoted 7 lines
Regards,
Richard.[1]
I can't be entirely sure of the category as I haven't looked for the codes yet, but it is presumably some group of characters outside the basic ASCII page.PS Sorry about posting style, I'm using Outlook and I've yet to find a way of getting it to help out by indenting everything using ">".
I use Outlook 2010 for reading HTML emails at $DAYJOB. I went and checked, and there is an option to use "> " in Options -> Mail -> Replies and Forwards.
Signature · 2 lines
Regards, Pratyush Yadav
Hey Richard,
Using your test case, I still get the error (which is, specifically an error dialog saying:
Failed to stage selected line.
error: patch failed: glacierupload.sh:55
error:glacierupload.sh: patch does not apply
Note that I'm highlighting the change in the source code, then right-clicking it and selecting "Stage lines for commit." ("Stage hunk for commit" also results in the error.)
If I stage the entire file by clicking on it in the upper-lefthand pane, things work fine.
This is a Gentoo box, so I wonder I happened to build Tcl without the appropriate unicode support (that one would find in most package-based distros)?
In briefly digging a bit more, it would seem that git gui is foisting the work onto "git apply" to create a patch and stage it? (If I'm reading the source correctly, It looks like the error dialog title is from
https://github.com/prati0100/git-gui/blob/master/lib/diff.tcl#L700
and then the error strings that populate the dialog are bubbled up from git apply.
Any ideas on what would make "git apply" potentially choke? I wonder if it has to do with a mixed file encoding?
I tried setting both:
core.checkRoundTripEncoding true
gui.encoding utf-8
on that repo; git gui still errored out in the same way.
I also tried changing gui.encoding to utf-16; no dice...
To reiterate, git add -i worked fine...
best,
preed
Signature · 5 lines
J. Paul Reed https://jpaulreed.com PGP: 0xDF8708F8 On 12 May 2020 at 14:27:22, Kerry, Richard arranged the bits on my disk to say:
Quoted 79 lines
-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Pratyush Yadav
Sent: 12 May 2020 13:15
To: J. Paul Reed <[email protected]>
Cc: [email protected]
Subject: Re: git-gui patch staging errorsHi,
Quoted 12 lines · J. Paul Reed
Hey all,
I ran into an interesting problem this week where git gui was erroring out on staging partial patches in a particular file I was working on.
I worked around it with "git add -i," which worked like a champ.
I later realized the source file has some special characters (Unicode, probably) in it to print emojis (or colors or whatever fun animations the kids want on their terminals these days).
Quoted 6 lines
Interestingly, lines/hunks before the first Unicode character will partial-stage appropriately, but attempting to stage any hunks/lines after the characters produces a "Failed to stage selected line. error:
patch failed ... error: ... patch does not apply" error dialog.This can be reproduced by cloning
I can't reproduce it. I cloned the repo and then edited the file at line 60 with a diff that looks something like:
diff --git a/glacierupload.sh b/glacierupload.sh index 3b956c7..265349b 100755 --- a/glacierupload.sh +++ b/glacierupload.sh @@ -57,7 +57,9 @@ fi# count the number of files that begin with "$prefix" fileCount=$(ls -1 | grep "^$prefix" | wc -l) -echo "📦 Glacier Upload with $AWS_PROFILE" +bar +echo "📦 Glacier s Upload with $AWS_PROFILE" +foo echo "Total parts to upload: " $fileCount# get the list of part files to upload. Edit this if you chose a different prefix in the split commandI tried a bunch of combinations if partially staging parts of this diff, but everything worked fine without any error message. The emoji didn't render properly (though that might be my font's problem), but there were no problems in partial staging or unstaging.
Does this example work fine on your system or does it error out? Could you give an example diff where git-gui has problems while staging? Maybe something in your config is different?
Quoted 10 lines
Removing these control characters seems to calm git gui's indigestion on this file.
[preed@underworld ~]$ git --version
git version 2.26.2
[preed@underworld ~]$ git gui --version git-gui version 0.21.0.66.ga5728best,
preed-----------------------
I've recently found something very similar to this using the Fork Gui. I am tempted to report it to that project, but on seeing something similar here perhaps both Fork and Gut-Gui have a similar issue relating to Gui applications for Git?
If the chunk I want to stage includes characters in some category [1], then an attempt to Stage that chunk will fail with a similar fault to what is described here. (I don't have one available to me at the moment to check whether it is exactly this failure)
I have recently found myself cutting and pasting some chunks of text from a PDF into my C++ source, and in particular that includes "handed" quotes, rather than the usual use of the usual single quote character (ie the apostrophe). If I then use Fork's ability to Stage chunks of text containing these (or possibly not containing, but close after) I get this failure reported. The work-around is to do it from the command line using "git add --patch", which works fine.Regards,
Richard.[1]
I can't be entirely sure of the category as I haven't looked for the codes yet, but it is presumably some group of characters outside the basic ASCII page.PS Sorry about posting style, I'm using Outlook and I've yet to find a way of getting it to help out by indenting everything using ">".
Hi,
Sorry for the late reply.
Quoted 2 lines · J. Paul Reed
Hey Richard,
You replied to the wrong person ;-)
Quoted 15 lines
Using your test case, I still get the error (which is, specifically an error dialog saying:
Failed to stage selected line.
error: patch failed: glacierupload.sh:55
error:glacierupload.sh: patch does not applyNote that I'm highlighting the change in the source code, then right-clicking it and selecting "Stage lines for commit." ("Stage hunk for commit" also results in the error.)
If I stage the entire file by clicking on it in the upper-lefthand pane, things work fine.
Quoted 8 lines
This is a Gentoo box, so I wonder I happened to build Tcl without the appropriate unicode support (that one would find in most package-based distros)?
In briefly digging a bit more, it would seem that git gui is foisting the work onto "git apply" to create a patch and stage it? (If I'm reading the source correctly, It looks like the error dialog title is from
https://github.com/prati0100/git-gui/blob/master/lib/diff.tcl#L700
You are close, but not quite there. We don't use "git apply" to _create_ a patch. We create the patch ourselves, and then pass it to git apply to stage/unstage the lines selected.
I suspect it is some encoding mismatch. Can you apply this patch below and send what the output is?
-- 8< --
lib/diff.tcl +5 -0
@@ -851,8 +851,13 @@ proc apply_or_revert_range_or_line {x y revert} { set first_l [$ui_diff index "$next_l + 1 lines"] } + puts "Diff we will send to git-apply:" + puts -nonewline "$current_diff_header" + puts -nonewline "$wholepatch" + if {[catch { set enc [get_path_encoding $current_diff_path] + puts "\nEncoding: $enc" set p [eval git_write $apply_cmd] fconfigure $p -translation binary -encoding $enc puts -nonewline $p $current_diff_header
-- >8 --
Quoted 5 lines
and then the error strings that populate the dialog are bubbled up from git apply.
Any ideas on what would make "git apply" potentially choke? I wonder if it has to do with a mixed file encoding?
git-gui not preparing the patch text properly would be a prime candidate.
Quoted 10 lines
I tried setting both:
core.checkRoundTripEncoding true
gui.encoding utf-8on that repo; git gui still errored out in the same way.
I also tried changing gui.encoding to utf-16; no dice...
To reiterate, git add -i worked fine...
Signature · 2 lines
Regards, Pratyush Yadav
Hey Pratyush,
Apologies for the late reply myself! Oof... been a long couple of months.
See further responses inline:
later,
preed
Signature · 5 lines
J. Paul Reed https://jpaulreed.com PGP: 0xDF8708F8 On 25 May 2020 at 18:38:07, Pratyush Yadav arranged the bits on my disk to say:
Quoted 9 lines
Hi,
Sorry for the late reply.
Quoted 2 lines · J. Paul Reed
Hey Richard,
You replied to the wrong person ;-)
Sorry about that!
Quoted 13 lines
I suspect it is some encoding mismatch. Can you apply this patch below and send what the output is?
-- 8< --
lib/diff.tcl +1
-0@@ -851,8 +851,13 @@ proc apply_or_revert_range_or_line {x y revert} { set first_l [$ui_diff index "$next_l + 1 lines"] } + puts "Diff we will send to git-apply:"
lib/diff.tcl proc apply_or_revert_range_or_line {x y revert} {
Quoted 10 lines
lib/diff.tcl +4
-1+ puts -nonewline "$current_diff_header" + puts -nonewline "$wholepatch" + if {[catch { set enc [get_path_encoding $current_diff_path] + puts "\nEncoding: $enc" set p [eval git_write $apply_cmd] fconfigure $p -translation binary -encoding $enc puts -nonewline $p $current_diff_header -- >8 --
Here ya go:
[preed@underworld aws-glacier-multipart-upload]$ ~/checkouts/git-gui/git-gui.sh Diff we will send to git-apply:
glacierupload.sh +0 -4
@@ -58,15 +58,14 @@ # count the number of files that begin with "$prefix" fileCount=$(ls -1 | grep "^$prefix" | wc -l) echo "ð¦ Glacier Upload with $AWS_PROFILE" echo "Total parts to upload: " $fileCount # get the list of part files to upload. Edit this if you chose a # different prefix in the split command files=$(ls | grep "^$prefix") # initiate multipart upload connection to glacier -echo aws glacier initiate-multipart-upload --profile $AWS_PROFILE --account-id - --part-size $byteSize --vault-name $vaultName --archive-description "$description" init=$(aws glacier initiate-multipart-upload --profile $AWS_PROFILE --account-id - --part-size $byteSize --vault-name $vaultName
--archive-description "$description")
echo "---------------------------------------"
# xargs trims off the quotes # jq pulls out the json element titled uploadId
Encoding: utf-8
This is probably expected, but to be clear: with this patch, I do still get the error popup in the gui ("Failed to stage selected line; error: patch
failed: glacierupload:58 error: glacierupload.sh patch does not apply"