diff --git a/lib/bundler/source/git.rb b/lib/bundler/source/git.rb index da48d644391..b3e218e3903 100644 --- a/lib/bundler/source/git.rb +++ b/lib/bundler/source/git.rb @@ -61,8 +61,12 @@ def eql?(other) def to_s at = if local? path - elsif options["ref"] - shortref_for_display(options["ref"]) + elsif user_ref = options["ref"] + if ref =~ /\A[a-z0-9]{4,}\z/i + shortref_for_display(user_ref) + else + user_ref + end else ref end diff --git a/spec/install/git_spec.rb b/spec/install/git_spec.rb index a555822012e..04f2380b45e 100644 --- a/spec/install/git_spec.rb +++ b/spec/install/git_spec.rb @@ -15,6 +15,28 @@ expect(the_bundle).to include_gems "foo 1.0", :source => "git@#{lib_path("foo")}" end + it "displays the ref of the gem repository when using branch~num as a ref" do + build_git "foo", "1.0", :path => lib_path("foo") + rev = revision_for(lib_path("foo"))[0..6] + update_git "foo", "2.0", :path => lib_path("foo"), :gemspec => true + rev2 = revision_for(lib_path("foo"))[0..6] + update_git "foo", "3.0", :path => lib_path("foo"), :gemspec => true + + install_gemfile! <<-G + gem "foo", :git => "#{lib_path("foo")}", :ref => "master~2" + G + + bundle! :install + expect(out).to include("Using foo 1.0 from #{lib_path("foo")} (at master~2@#{rev})") + expect(the_bundle).to include_gems "foo 1.0", :source => "git@#{lib_path("foo")}" + + update_git "foo", "4.0", :path => lib_path("foo"), :gemspec => true + + bundle! :update + expect(out).to include("Using foo 2.0 (was 1.0) from #{lib_path("foo")} (at master~2@#{rev2})") + expect(the_bundle).to include_gems "foo 2.0", :source => "git@#{lib_path("foo")}" + end + it "should check out git repos that are missing but not being installed" do build_git "foo" diff --git a/spec/support/builders.rb b/spec/support/builders.rb index 75aed0e7ee9..28a271998ea 100644 --- a/spec/support/builders.rb +++ b/spec/support/builders.rb @@ -659,6 +659,7 @@ def silently(str) def _build(options) libpath = options[:path] || _default_path update_gemspec = options[:gemspec] || false + source = options[:source] || "git@#{libpath}" Dir.chdir(libpath) do silently "git checkout master" @@ -684,7 +685,7 @@ def _build(options) _default_files.keys.each do |path| _default_files[path] += "\n#{Builders.constantize(name)}_PREV_REF = '#{current_ref}'" end - super(options.merge(:path => libpath, :gemspec => update_gemspec)) + super(options.merge(:path => libpath, :gemspec => update_gemspec, :source => source)) `git add *` `git commit -m "BUMP"` end