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

[Git] Only shorten refs if they are SHAs #5622

Merged
merged 2 commits into from
Apr 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/bundler/source/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions spec/install/git_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
3 changes: 2 additions & 1 deletion spec/support/builders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down