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

'Undo Last commit' does not work if there is no commit message #71258

Closed
shubhra-agrawal opened this issue Mar 27, 2019 · 9 comments
Closed

'Undo Last commit' does not work if there is no commit message #71258

shubhra-agrawal opened this issue Mar 27, 2019 · 9 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug git GIT issues good first issue Issues identified as good for first-time contributors help wanted Issues identified as good community contribution opportunities verified Verification succeeded
Milestone

Comments

@shubhra-agrawal
Copy link

Issue Type: Bug

  • Made some changes to my branch, staged them, added a commit message and clicked on the commit button
  • The app was slow so I clicked on the commit button again
  • Got a prompt along the lines of "Can't fetch head.." but I dismissed it accidentally. The status bar at the bottom showed that the commit was sucessful so I pushed to remote
  • Checked the commit on remote. Somehow there was no commit message
  • Tried to 'Undo last commit' in VS code but it fails with a 'Bad commit' error

VS Code version: Code 1.32.1 (05f146c, 2019-03-08T00:46:10.898Z)
OS version: Linux x64 4.15.0-46-generic

System Info
Item Value
CPUs Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz (4 x 799)
GPU Status 2d_canvas: enabled
checker_imaging: disabled_off
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: disabled_software
rasterization: disabled_software
surface_synchronization: enabled_on
video_decode: unavailable_off
webgl: enabled
webgl2: enabled
Load (avg) 2, 2, 2
Memory (System) 7.66GB (1.63GB free)
Process Argv .
Screen Reader no
VM 0%
Extensions (3)
Extension Author (truncated) Version
gitlens eam 9.5.1
vscode-pull-request-github Git 0.5.1
cpptools ms- 0.22.1
@vscodebot vscodebot bot added the git GIT issues label Mar 27, 2019
@joaomoreno joaomoreno added the bug Issue identified by VS Code Team member as probable bug label Mar 27, 2019
@joaomoreno joaomoreno added this to the Backlog milestone Mar 27, 2019
@joaomoreno joaomoreno added help wanted Issues identified as good community contribution opportunities good first issue Issues identified as good for first-time contributors labels Mar 27, 2019
@engrravijain
Copy link

@joaomoreno is this issue resolved? if not i would like to work on this.

@ngrygiel
Copy link

ngrygiel commented Apr 8, 2019

I have the same question, would like to work on this if it still isn't resolved. @joaomoreno

@marmikc
Copy link
Contributor

marmikc commented Apr 21, 2019

Hi all, I've also been looking into this issue. While I have not been able to recreate the error as stated what I have noticed is that VS Code cannot undo commits where the commit is only whitespace.

For example, if a commit is made by pressing the tick where it says Source Control: Git, and then pressing space and then Enter, the commit goes through fine, however, when undoing, the same error described in the original post occurs.

I have not localized the error to a specific file yet, I just wanted to let people know what I've found out.

Press the tick when there are staged changes.
whitespace_commit_part1

Then type in some whitespace and press enter, the commit goes through.
whitespace_commit_part2

@marmikc
Copy link
Contributor

marmikc commented Apr 21, 2019

Hi again everyone, I've noticed that in this bug there are essentially two parts to it. If VS Code tries to undo a commit where there was an empty commit message, or a commit message with only whitespace, the "Bad Commit" error occurs.

Furthermore, there is a way to make a commit with just whitespace through VS Code. As I described it in the last comment, if you press the tick by Source Control: Git, enter some whitespace, and then press enter, the commit goes through with the message being whitespace. If you try to undo this, the same error will occur.

  • Fix: Cannot undo git commits with only whitespace
  • FIx: Can make commits with only whitespace
    • I have put this as an error because when filling out a message for a commit in the side bar if there is only whitespace, it will refuse commits. Hence going by that, I am extrapolating that to mean that any commit messages drafted in the top bar should refuse whitespace too.

@ngrygiel
Copy link

I think I've located where the error with whitespace commits is happening.

In commands.ts, the function undoCommit() calls getCommit() on 'HEAD' and leads to the getCommit() function in git.ts, which is where the 'bad commit format' error originates.

getCommit() in git.ts returns the 'bad commit' error if the function parseGitCommit() (which takes an inputted string) returns null. parseGitCommit() runs a regex check on the inputted string after calling trim() on it and returns null if it doesn't find any matches.

It appears to me that the error eventually corresponds to that regex match/calling trim() on the inputted string, as that should be causing any pure whitespace commit message passed in to become an empty string. I'm hesitant to simply remove the trim() function call, however, as I believe that could cause a lot of new issues.

@marmikc
Copy link
Contributor

marmikc commented Apr 22, 2019

I have found a potential fix for this error, I will submit a pull request for it soon.

@marmikc
Copy link
Contributor

marmikc commented Apr 22, 2019

I think I've located where the error with whitespace commits is happening.

In commands.ts, the function undoCommit() calls getCommit() on 'HEAD' and leads to the getCommit() function in git.ts, which is where the 'bad commit format' error originates.

getCommit() in git.ts returns the 'bad commit' error if the function parseGitCommit() (which takes an inputted string) returns null. parseGitCommit() runs a regex check on the inputted string after calling trim() on it and returns null if it doesn't find any matches.

It appears to me that the error eventually corresponds to that regex match/calling trim() on the inputted string, as that should be causing any pure whitespace commit message passed in to become an empty string. I'm hesitant to simply remove the trim() function call, however, as I believe that could cause a lot of new issues.

I have found this error to be in the same location as well. By testing with different commits it seems the regex matching expression is at fault, not the trimming function call.

The string that goes into the regex match is as follows:

[hash of previous git commit]
emailaddress@domain.com
[hash of this git commit]
[name of this commit]

The last part, the name of this commit, is optional, and is not present when there is an empty git commit, but the regex expression looks for it, and hence sees the expression as invalid.

@marmikc
Copy link
Contributor

marmikc commented Apr 22, 2019

The build on my pull requests is failing and I am unsure why. I would appreciate help if someone could provide it for me. It seems an integration test for macOS is failing.

@joaomoreno joaomoreno modified the milestones: Backlog, August 2019 Aug 8, 2019
@aeschli aeschli added the verified Verification succeeded label Aug 28, 2019
@vscodebot vscodebot bot locked and limited conversation to collaborators Sep 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug git GIT issues good first issue Issues identified as good for first-time contributors help wanted Issues identified as good community contribution opportunities verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

6 participants