File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# Encoding: utf-8
22# Cloud Foundry Java Buildpack
3- # Copyright 2013 the original author or authors.
3+ # Copyright 2013-2015 the original author or authors.
44#
55# Licensed under the Apache License, Version 2.0 (the "License");
66# you may not use this file except in compliance with the License.
@@ -86,10 +86,13 @@ def to_s(human_readable = true)
8686 s = [ ]
8787 s << @version if @version
8888 s << ( human_readable ? '(offline)' : 'offline' ) if @offline
89- s << '|' if @version && human_readable
90- s << "#{ @remote } ##{ @hash } " if @remote && @hash
91- s << 'unknown' if s . empty?
9289
90+ if remote_string
91+ s << '|' if @version && human_readable
92+ s << remote_string
93+ end
94+
95+ s << 'unknown' if s . empty?
9396 s . join ( human_readable ? ' ' : '-' )
9497 end
9598
@@ -99,6 +102,10 @@ def to_s(human_readable = true)
99102
100103 private_constant :GIT_DIR
101104
105+ def remote_string
106+ "#{ @remote } ##{ @hash } " if @remote && !@remote . empty? && @hash && !@hash . empty?
107+ end
108+
102109 def git ( command )
103110 `git --git-dir=#{ GIT_DIR } #{ command } ` . chomp if git? && git_dir?
104111 end
Original file line number Diff line number Diff line change 11# Encoding: utf-8
22# Cloud Foundry Java Buildpack
3- # Copyright 2013 the original author or authors.
3+ # Copyright 2013-2015 the original author or authors.
44#
55# Licensed under the Apache License, Version 2.0 (the "License");
66# you may not use this file except in compliance with the License.
9696 expect ( buildpack_version . to_hash ) . to eq ( { } )
9797 end
9898
99+ it 'excludes remote string when remote and hash values from config/version.yml are empty' ,
100+ configuration : { 'hash' => '' , 'remote' => '' , 'version' => 'test-version' } do
101+ expect ( buildpack_version . to_s ) . to eq ( 'test-version' )
102+ end
103+
104+ it 'includes remote string when remote and hash values from config/version.yml are missing' ,
105+ configuration : { 'version' => 'test-version' } do
106+
107+ git_dir = Pathname . new ( '.git' ) . expand_path
108+ allow_any_instance_of ( described_class ) . to receive ( :system )
109+ . with ( 'which git > /dev/null' )
110+ . and_return ( true )
111+ allow_any_instance_of ( described_class ) . to receive ( :` )
112+ . with ( "git --git-dir=#{ git_dir } rev-parse --short HEAD" )
113+ . and_return ( 'test-hash' )
114+ allow_any_instance_of ( described_class ) . to receive ( :` )
115+ . with ( "git --git-dir=#{ git_dir } config --get remote.origin.url" )
116+ . and_return ( 'test-remote' )
117+
118+ expect ( buildpack_version . to_s ) . to eq ( 'test-version | test-remote#test-hash' )
119+ end
120+
99121 context do
100122
101123 let ( :environment ) { { 'OFFLINE' => 'true' } }
You can’t perform that action at this time.
0 commit comments