Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Auto merge of #5297 - bundler:seg-git-branch-hash, r=indirect
Browse files Browse the repository at this point in the history
[GitProxy] Support branches containing shell metacharacters

Closes #5295

(cherry picked from commit 084cbc7)
  • Loading branch information
bundlerbot authored and segiddins committed Jan 11, 2017
1 parent 438c2b1 commit b89e374
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/bundler/source/git/git_proxy.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true
require "shellwords"
require "tempfile"
module Bundler
class Source
Expand Down Expand Up @@ -180,7 +181,7 @@ def remove_cache

def find_local_revision
allowed_in_path do
git("rev-parse --verify #{ref}", true).strip
git("rev-parse --verify #{Shellwords.shellescape(ref)}", true).strip
end
end

Expand Down
88 changes: 88 additions & 0 deletions spec/install/gemfile/git_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,94 @@
end
end

describe "when specifying a branch" do
let(:branch) { "branch" }
let(:repo) { build_git("foo").path }
before(:each) do
update_git("foo", :path => repo, :branch => branch)
end

it "works" do
install_gemfile <<-G
git "#{repo}", :branch => #{branch.dump} do
gem "foo"
end
G

expect(the_bundle).to include_gems("foo 1.0")
end

context "when the branch starts with a `#`" do
let(:branch) { "#149/redirect-url-fragment" }
it "works" do
install_gemfile <<-G
git "#{repo}", :branch => #{branch.dump} do
gem "foo"
end
G

expect(the_bundle).to include_gems("foo 1.0")
end
end

context "when the branch includes quotes" do
let(:branch) { %('") }
it "works" do
install_gemfile <<-G
git "#{repo}", :branch => #{branch.dump} do
gem "foo"
end
G

expect(the_bundle).to include_gems("foo 1.0")
end
end
end

describe "when specifying a tag" do
let(:tag) { "tag" }
let(:repo) { build_git("foo").path }
before(:each) do
update_git("foo", :path => repo, :tag => tag)
end

it "works" do
install_gemfile <<-G
git "#{repo}", :tag => #{tag.dump} do
gem "foo"
end
G

expect(the_bundle).to include_gems("foo 1.0")
end

context "when the tag starts with a `#`" do
let(:tag) { "#149/redirect-url-fragment" }
it "works" do
install_gemfile <<-G
git "#{repo}", :tag => #{tag.dump} do
gem "foo"
end
G

expect(the_bundle).to include_gems("foo 1.0")
end
end

context "when the tag includes quotes" do
let(:tag) { %('") }
it "works" do
install_gemfile <<-G
git "#{repo}", :tag => #{tag.dump} do
gem "foo"
end
G

expect(the_bundle).to include_gems("foo 1.0")
end
end
end

describe "when specifying local override" do
it "uses the local repository instead of checking a new one out" do
# We don't generate it because we actually don't need it
Expand Down
10 changes: 6 additions & 4 deletions spec/support/builders.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true
require "bundler/shared_helpers"
require "shellwords"

module Spec
module Builders
Expand Down Expand Up @@ -664,14 +665,15 @@ def _build(options)

if branch = options[:branch]
raise "You can't specify `master` as the branch" if branch == "master"
escaped_branch = Shellwords.shellescape(branch)

if `git branch | grep #{branch}`.empty?
silently("git branch #{branch}")
if `git branch | grep #{escaped_branch}`.empty?
silently("git branch #{escaped_branch}")
end

silently("git checkout #{branch}")
silently("git checkout #{escaped_branch}")
elsif tag = options[:tag]
`git tag #{tag}`
`git tag #{Shellwords.shellescape(tag)}`
elsif options[:remote]
silently("git remote add origin file://#{options[:remote]}")
elsif options[:push]
Expand Down

0 comments on commit b89e374

Please sign in to comment.