Skip to content

Commit message escaping issues under Windows #495

Closed
@sergio-bobillier

Description

@sergio-bobillier

Subject of the issue

The current escape method for Windows is basically not doing anything:

def escape_for_windows(s)

    def escape_for_windows(s)
      # Windows does not need single quote escaping inside double quotes
      %Q{"#{s}"}
    end

This works fine for single quotation marks but if the message contains a double quote the commit method breaks:

I, [2020-12-01T13:47:55.042634 #5488]  INFO -- : git "--git-dir=Z:/Trash/repo/.git" "--work-tree=Z:/Trash/repo" "-c" "color.ui=false" commit "--message="Hello World""  2>&1
D, [2020-12-01T13:47:55.042873 #5488] DEBUG -- : error: pathspec 'World' did not match any file(s) known to git
Git::GitExecuteError: git "--git-dir=Z:/Trash/repo/.git" "--work-tree=Z:/Trash/repo" "-c" "color.ui=false" commit "--message="Hello World""  2>&1:error: pathspec 'World' did not match any file(s) known to git
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/git-1.7.0/lib/git/lib.rb:989:in `command'

Your environment

  • ruby-git: 1.7.0
  • Ruby: 2.6.4
  • Windows 10

Steps to reproduce

Create a repository, open with with Git and then create a commit with a newline on the message:

mkdir repo
cd repo
git init
echo "Hello World" > hello.txt
git add hello.txt
pry
require 'git'
git = Git.open('.')
git.commit('"Hello World"')

Expected behaviour

I would expect this to work like it does on Unix-like systems. I.e. the commit is performed and the message includes the quotation marks.

Actual behaviour

A Git::GitExecuteError is raised and the origin of the problem is the incorrectly escaped commit message.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions