Skip to content

Commit

Permalink
Properly change into directories with spaces
Browse files Browse the repository at this point in the history
brandoncc committed Nov 17, 2016
1 parent a410906 commit 417042e
Showing 3 changed files with 33 additions and 33 deletions.
10 changes: 5 additions & 5 deletions lib/clone_git_file.rb
Original file line number Diff line number Diff line change
@@ -40,9 +40,9 @@ def launch_editor

# change into the directory so that relative file loads will work
if File.directory?(file_path)
commands << "cd #{file_path}"
commands << %(cd "#{file_path}")
else
commands << "cd #{File.dirname(file_path)}"
commands << %(cd "#{File.dirname(file_path)}")
end
commands << %(\n#{ENV["EDITOR"]} "#{file_path}")

@@ -62,11 +62,11 @@ def print_clone_location

def clone_repo
commands = ""
commands << "git clone #{parsed_data.repo_url} #{local_repo_path}"
commands << %(git clone #{parsed_data.repo_url} "#{local_repo_path}")

branch_name = parsed_data.branch_name
if branch_name && branch_name != ""
commands << "\ncd #{local_repo_path}"
commands << %(\ncd "#{local_repo_path}")
commands << "\ngit checkout #{parsed_data.branch_name}"
end

@@ -78,7 +78,7 @@ def clone_repo
def update_repo
commands = ""

commands << "cd #{local_repo_path}"
commands << %(cd "#{local_repo_path}")
commands << "\ngit reset HEAD --hard"
commands << "\ngit pull"
commands << "\ngit checkout #{parsed_data.branch_name}" if parsed_data.branch_name
2 changes: 1 addition & 1 deletion lib/clone_git_file/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module CloneGitFile
VERSION = "0.1.6"
VERSION = "0.1.7"
end
54 changes: 27 additions & 27 deletions spec/clone_git_file_spec.rb
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@
let(:cloner) { ::CloneGitFile::Cloner.new(url) }

it "clones new repos" do
expected_clone_command = "git clone https://github.com/author/repo /target/author/repo"
expected_clone_command = %(git clone https://github.com/author/repo "/target/author/repo")
expected_output = "Cloned to: /target/author/repo/some/file.rb"
allow(Dir).to receive(:exists?).and_return(false)
expect(cloner).to receive(:system).with(expected_clone_command)
@@ -37,7 +37,7 @@
end

it "updates repos which exist in target directory" do
expected_update_command = "cd /target/author/repo\ngit reset HEAD --hard\ngit pull"
expected_update_command = %(cd "/target/author/repo"\ngit reset HEAD --hard\ngit pull)
expected_output = "Cloned to: /target/author/repo/some/file.rb"
allow(Dir).to receive(:exists?).and_return(true)
expect(cloner).to receive(:system).with(expected_update_command)
@@ -55,8 +55,8 @@
let(:url) { "https://github.com/author/repo/some/file.rb" }

it "outputs the commands to the terminal instead of executing them" do
expected_update_command = "cd /target/author/repo\ngit reset HEAD --hard\ngit pull"
expected_output = %(cd /target/author/repo/some\nmyeditor "/target/author/repo/some/file.rb")
expected_update_command = %(cd "/target/author/repo"\ngit reset HEAD --hard\ngit pull)
expected_output = %(cd "/target/author/repo/some"\nmyeditor "/target/author/repo/some/file.rb")
allow(Dir).to receive(:exists?).and_return(true)
expect(cloner).to receive(:system).with(expected_update_command)
expect(cloner).to receive(:puts).with(expected_output)
@@ -68,8 +68,8 @@
let(:url) { "https://github.com/author/repo/some" }

it "outputs the commands to the terminal instead of executing them" do
expected_update_command = "cd /target/author/repo\ngit reset HEAD --hard\ngit pull"
expected_output = %(cd /target/author/repo/some\nmyeditor "/target/author/repo/some")
expected_update_command = %(cd "/target/author/repo"\ngit reset HEAD --hard\ngit pull)
expected_output = %(cd "/target/author/repo/some"\nmyeditor "/target/author/repo/some")
allow(Dir).to receive(:exists?).and_return(true)
expect(cloner).to receive(:system).with(expected_update_command)
expect(cloner).to receive(:puts).with(expected_output)
@@ -81,8 +81,8 @@
let(:url) { "https://github.com/author/repo" }

it "outputs the commands to the terminal instead of executing them" do
expected_update_command = "cd /target/author/repo\ngit reset HEAD --hard\ngit pull"
expected_output = %(cd /target/author/repo\nmyeditor "/target/author/repo")
expected_update_command = %(cd "/target/author/repo"\ngit reset HEAD --hard\ngit pull)
expected_output = %(cd "/target/author/repo"\nmyeditor "/target/author/repo")
allow(Dir).to receive(:exists?).and_return(true)
expect(cloner).to receive(:system).with(expected_update_command)
expect(cloner).to receive(:puts).with(expected_output)
@@ -94,8 +94,8 @@
let(:url) { "https://github.com/author/repo/" }

it "outputs the commands to the terminal instead of executing them" do
expected_update_command = "cd /target/author/repo\ngit reset HEAD --hard\ngit pull"
expected_output = %(cd /target/author/repo\nmyeditor "/target/author/repo")
expected_update_command = %(cd "/target/author/repo"\ngit reset HEAD --hard\ngit pull)
expected_output = %(cd "/target/author/repo"\nmyeditor "/target/author/repo")
allow(Dir).to receive(:exists?).and_return(true)
expect(cloner).to receive(:system).with(expected_update_command)
expect(cloner).to receive(:puts).with(expected_output)
@@ -113,8 +113,8 @@
let(:url) { "https://github.com/author/repo/some/file.rb" }

it "outputs the commands to the terminal instead of executing them" do
expected_update_command = "cd /target/author/repo\ngit reset HEAD --hard\ngit pull"
expected_output = %(cd /target/author/repo/some\nmyeditor "/target/author/repo/some/file.rb")
expected_update_command = %(cd "/target/author/repo"\ngit reset HEAD --hard\ngit pull)
expected_output = %(cd "/target/author/repo/some"\nmyeditor "/target/author/repo/some/file.rb")
allow(Dir).to receive(:exists?).and_return(true)
expect(cloner).to receive(:system).with(expected_update_command)
expect(cloner).to receive(:puts).with(expected_output)
@@ -126,8 +126,8 @@
let(:url) { "https://github.com/author/repo/some" }

it "outputs the commands to the terminal instead of executing them" do
expected_update_command = "cd /target/author/repo\ngit reset HEAD --hard\ngit pull"
expected_output = %(cd /target/author/repo/some\nmyeditor "/target/author/repo/some")
expected_update_command = %(cd "/target/author/repo"\ngit reset HEAD --hard\ngit pull)
expected_output = %(cd "/target/author/repo/some"\nmyeditor "/target/author/repo/some")
allow(Dir).to receive(:exists?).and_return(true)
expect(cloner).to receive(:system).with(expected_update_command)
expect(cloner).to receive(:puts).with(expected_output)
@@ -139,8 +139,8 @@
let(:url) { "https://github.com/author/repo" }

it "outputs the commands to the terminal instead of executing them" do
expected_update_command = "cd /target/author/repo\ngit reset HEAD --hard\ngit pull"
expected_output = %(cd /target/author/repo\nmyeditor "/target/author/repo")
expected_update_command = %(cd "/target/author/repo"\ngit reset HEAD --hard\ngit pull)
expected_output = %(cd "/target/author/repo"\nmyeditor "/target/author/repo")
allow(Dir).to receive(:exists?).and_return(true)
expect(cloner).to receive(:system).with(expected_update_command)
expect(cloner).to receive(:puts).with(expected_output)
@@ -152,8 +152,8 @@
let(:url) { "https://github.com/author/repo/" }

it "outputs the commands to the terminal instead of executing them" do
expected_update_command = "cd /target/author/repo\ngit reset HEAD --hard\ngit pull"
expected_output = %(cd /target/author/repo\nmyeditor "/target/author/repo")
expected_update_command = %(cd "/target/author/repo"\ngit reset HEAD --hard\ngit pull)
expected_output = %(cd "/target/author/repo"\nmyeditor "/target/author/repo")
allow(Dir).to receive(:exists?).and_return(true)
expect(cloner).to receive(:system).with(expected_update_command)
expect(cloner).to receive(:puts).with(expected_output)
@@ -168,7 +168,7 @@
let(:cloner) { ::CloneGitFile::Cloner.new(url, silent: true) }

it "redirects output" do
expected_update_command = "cd /target/author/repo &> /dev/null\ngit reset HEAD --hard &> /dev/null\ngit pull &> /dev/null"
expected_update_command = %(cd "/target/author/repo" &> /dev/null\ngit reset HEAD --hard &> /dev/null\ngit pull &> /dev/null)
expected_output = "Cloned to: /target/author/repo/some/file.rb"
allow(Dir).to receive(:exists?).and_return(true)
expect(cloner).to receive(:system).with(expected_update_command)
@@ -183,8 +183,8 @@
let(:cloner) { ::CloneGitFile::Cloner.new(url, open_in_editor: true) }

it "clones new repos" do
expected_clone_command = "git clone https://github.com/author/repo /target/author/repo"
expected_launch_command = %(cd /target/author/repo/some\nmyeditor "/target/author/repo/some/file.rb")
expected_clone_command = %(git clone https://github.com/author/repo "/target/author/repo")
expected_launch_command = %(cd "/target/author/repo/some"\nmyeditor "/target/author/repo/some/file.rb")
allow(Dir).to receive(:exists?).and_return(false)
expect(cloner).to receive(:system).with(expected_clone_command)
expect(cloner).to receive(:system).with(expected_launch_command)
@@ -197,8 +197,8 @@
let(:cloner) { ::CloneGitFile::Cloner.new(url, open_in_editor: true) }

it "clones new repos" do
expected_clone_command = "git clone https://github.com/author/repo /target/author/repo"
expected_launch_command = %(cd /target/author/repo\nmyeditor "/target/author/repo")
expected_clone_command = %(git clone https://github.com/author/repo "/target/author/repo")
expected_launch_command = %(cd "/target/author/repo"\nmyeditor "/target/author/repo")
allow(Dir).to receive(:exists?).and_return(false)
expect(cloner).to receive(:system).with(expected_clone_command)
expect(cloner).to receive(:system).with(expected_launch_command)
@@ -211,8 +211,8 @@
let(:cloner) { ::CloneGitFile::Cloner.new(url, open_in_editor: true) }

it "clones new repos" do
expected_clone_command = "git clone https://github.com/author/repo /target/author/repo"
expected_launch_command = %(cd /target/author/repo/some\nmyeditor "/target/author/repo/some")
expected_clone_command = %(git clone https://github.com/author/repo "/target/author/repo")
expected_launch_command = %(cd "/target/author/repo/some"\nmyeditor "/target/author/repo/some")
allow(Dir).to receive(:exists?).and_return(false)
expect(cloner).to receive(:system).with(expected_clone_command)
expect(cloner).to receive(:system).with(expected_launch_command)
@@ -225,8 +225,8 @@
let(:cloner) { ::CloneGitFile::Cloner.new(url, open_in_editor: true) }

it "clones new repos" do
expected_clone_command = "git clone https://github.com/author/repo /target/author/repo"
expected_launch_command = %(cd /target/author/repo\nmyeditor "/target/author/repo")
expected_clone_command = %(git clone https://github.com/author/repo "/target/author/repo")
expected_launch_command = %(cd "/target/author/repo"\nmyeditor "/target/author/repo")
allow(Dir).to receive(:exists?).and_return(false)
expect(cloner).to receive(:system).with(expected_clone_command)
expect(cloner).to receive(:system).with(expected_launch_command)

0 comments on commit 417042e

Please sign in to comment.