Skip to content

Commit 1ff29aa

Browse files
Sinee Paungamnebhale
authored andcommitted
Allow hidden remote git url
This commit avoids displaying the characters | and # during buildpack detect if there is no remote git url value to be displayed. The remote git url isn't displayed when the version.yml is configured to hide the url by setting the hash and remote values to be an empty string [resolves #99]
1 parent 66b29a3 commit 1ff29aa

2 files changed

Lines changed: 34 additions & 5 deletions

File tree

lib/java_buildpack/buildpack_version.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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

spec/java_buildpack/buildpack_version_spec.rb

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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.
@@ -96,6 +96,28 @@
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' } }

0 commit comments

Comments
 (0)