Skip to content

Adding a file with single quote throws error #129

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

Closed
mreaston opened this issue Feb 4, 2014 · 1 comment
Closed

Adding a file with single quote throws error #129

mreaston opened this issue Feb 4, 2014 · 1 comment
Assignees
Milestone

Comments

@mreaston
Copy link

mreaston commented Feb 4, 2014

Unable to add a file with a single quote in it, I have an example that throws an error even though the file is being created correctly.

require 'rubygems'
require 'git'
require 'logger'

DIRECTORY = "/data2/git/test3"
FILE = "README's FILE.md"


# clean directory
`rm -rf #{DIRECTORY}`

git = Git.init(DIRECTORY,:log => Logger.new(STDOUT))

# create file
File.open(DIRECTORY+"/#{FILE}", "w+") {|f| f.write("Hello World") }

git.add(FILE)

git.commit_all("First commit")

# modify file
File.open(DIRECTORY+"/#{FILE}", "w+") {|f| f.write("Changes") }


# new commit for modified files
status = git.status

status.changed.each do |change|
  git.add(change[0])
end

git.commit_all("Second commit")

The output of which is:

ruby GitTestDir.rb 
I, [2014-02-03T18:47:59.791143 #18386]  INFO -- : Starting Git
I, [2014-02-03T18:47:59.794504 #18386]  INFO -- : git add "--" "README's FILE.md's FILE.md"  2>&1
D, [2014-02-03T18:47:59.794670 #18386] DEBUG -- : fatal: pathspec 'README's FILE.md's FILE.md' did not match any files
/usr/local/lib/ruby/gems/2.0.0/gems/git-1.2.6/lib/git/lib.rb:718:in `command': git add "--" "README's FILE.md's FILE.md"  2>&1:fatal: pathspec 'README's FILE.md's FILE.md' did not match any files (Git::GitExecuteError)
        from /usr/local/lib/ruby/gems/2.0.0/gems/git-1.2.6/lib/git/lib.rb:393:in `add'
        from /usr/local/lib/ruby/gems/2.0.0/gems/git-1.2.6/lib/git/base.rb:261:in `add'
        from GitTestDir.rb:19:in `<main>'

My setup is:
git: v1.8.1.1
ruby: v2.0.0p353
gem: 2.0.14
ruby-git: 1.2.6

@robertodecurnex
Copy link
Contributor

This has been fixed recently (the fix is on the master branch waiting for the 1.2.7 to be released)

You can try it by making your Gemfile point to the repo

gem 'git', git: git@github.com:schacon/ruby-git.git

References: #5 #112 #95 #39

I'm uploading one more change to catch some edge cases.

@mreaston let me know if that makes the trick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants