From 3df81bc12f81a6b4f2c625ac16edfa4ad6b88049 Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Fri, 28 Apr 2017 11:56:05 +0200 Subject: [Git] Only shorten refs if they are SHAs --- lib/bundler/source/git.rb | 8 ++++++-- spec/install/git_spec.rb | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/bundler/source/git.rb b/lib/bundler/source/git.rb index da48d64439..b3e218e390 100644 --- a/lib/bundler/source/git.rb +++ b/lib/bundler/source/git.rb @@ -61,8 +61,12 @@ module Bundler 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 a555822012..04f2380b45 100644 --- a/spec/install/git_spec.rb +++ b/spec/install/git_spec.rb @@ -15,6 +15,28 @@ RSpec.describe "bundle install" do 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" -- cgit v1.2.1