Skip to content

Commit

Permalink
Escape paths in Git using Shellwords
Browse files Browse the repository at this point in the history
If the working directory path contained spaces, Git (the class) would choke on these. Escaping the paths with Shellwords prevents this choking.

Fixes #16
  • Loading branch information
radar committed Mar 28, 2017
1 parent 178fc6a commit d1065a1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
12 changes: 11 additions & 1 deletion lib/git.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'shellwords'

class Git
attr_accessor :user, :repo

Expand Down Expand Up @@ -29,7 +31,15 @@ def exists?
end

def clone
`git clone -q #{self.class.host}#{user}/#{repo} #{path}`
`git clone -q #{origin} #{destination}`
end

def origin
Shellwords.escape("#{self.class.host}#{user}/#{repo}")
end

def destination
Shellwords.escape(path.to_s)
end

def pull
Expand Down
5 changes: 4 additions & 1 deletion spec/lib/git_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'rails_helper'
require 'shellwords'

describe Git do
let(:args) { ["radar", "markdown_book_test"] }
Expand All @@ -18,7 +19,9 @@

it "initializes a new repository" do
git = Git.new(*args)
expect(git).to receive(:`).with("git clone -q #{Git.host}#{args.join("/")} #{test_repo}")
origin = Shellwords.escape("#{Git.host}#{args.join("/")}")
destination = Shellwords.escape(test_repo)
expect(git).to receive(:`).with("git clone -q #{origin} #{destination}")
git.update!
end

Expand Down

0 comments on commit d1065a1

Please sign in to comment.