|
3 | 3 | RSpec.describe Bundler::Source::Git::GitProxy do |
4 | 4 | let(:path) { Pathname("path") } |
5 | 5 | let(:uri) { "https://github.com/rubygems/rubygems.git" } |
6 | | - let(:ref) { "HEAD" } |
| 6 | + let(:ref) { nil } |
| 7 | + let(:branch) { nil } |
| 8 | + let(:tag) { nil } |
| 9 | + let(:options) { { "ref" => ref, "branch" => branch, "tag" => tag }.compact } |
7 | 10 | let(:revision) { nil } |
8 | 11 | let(:git_source) { nil } |
9 | 12 | let(:clone_result) { double(Process::Status, :success? => true) } |
10 | 13 | let(:base_clone_args) { ["clone", "--bare", "--no-hardlinks", "--quiet", "--no-tags", "--depth", "1", "--single-branch"] } |
11 | | - subject { described_class.new(path, uri, ref, revision, git_source) } |
| 14 | + subject(:git_proxy) { described_class.new(path, uri, options, revision, git_source) } |
| 15 | + |
| 16 | + context "with explicit ref" do |
| 17 | + context "with branch only" do |
| 18 | + let(:branch) { "main" } |
| 19 | + it "sets explicit ref to branch" do |
| 20 | + expect(git_proxy.explicit_ref).to eq(branch) |
| 21 | + end |
| 22 | + end |
| 23 | + |
| 24 | + context "with ref only" do |
| 25 | + let(:ref) { "HEAD" } |
| 26 | + it "sets explicit ref to ref" do |
| 27 | + expect(git_proxy.explicit_ref).to eq(ref) |
| 28 | + end |
| 29 | + end |
| 30 | + |
| 31 | + context "with tag only" do |
| 32 | + let(:tag) { "v1.0" } |
| 33 | + it "sets explicit ref to ref" do |
| 34 | + expect(git_proxy.explicit_ref).to eq(tag) |
| 35 | + end |
| 36 | + end |
| 37 | + |
| 38 | + context "with tag and branch" do |
| 39 | + let(:tag) { "v1.0" } |
| 40 | + let(:branch) { "main" } |
| 41 | + it "raises error" do |
| 42 | + expect { git_proxy }.to raise_error(Bundler::Source::Git::AmbiguousGitReference) |
| 43 | + end |
| 44 | + end |
| 45 | + |
| 46 | + context "with tag and ref" do |
| 47 | + let(:tag) { "v1.0" } |
| 48 | + let(:ref) { "HEAD" } |
| 49 | + it "raises error" do |
| 50 | + expect { git_proxy }.to raise_error(Bundler::Source::Git::AmbiguousGitReference) |
| 51 | + end |
| 52 | + end |
| 53 | + |
| 54 | + context "with branch and ref" do |
| 55 | + let(:branch) { "main" } |
| 56 | + let(:ref) { "HEAD" } |
| 57 | + it "honors ref over branch" do |
| 58 | + expect(git_proxy.explicit_ref).to eq(ref) |
| 59 | + end |
| 60 | + end |
| 61 | + end |
12 | 62 |
|
13 | 63 | context "with configured credentials" do |
14 | 64 | it "adds username and password to URI" do |
15 | 65 | Bundler.settings.temporary(uri => "u:p") do |
16 | | - allow(subject).to receive(:git_local).with("--version").and_return("git version 2.14.0") |
17 | | - expect(subject).to receive(:capture).with([* base_clone_args, "--", "https://u:[email protected]/rubygems/rubygems.git", path.to_s], nil).and_return(["", "", clone_result]) |
| 66 | + allow(git_proxy).to receive(:git_local).with("--version").and_return("git version 2.14.0") |
| 67 | + expect(git_proxy).to receive(:capture).with([* base_clone_args, "--", "https://u:[email protected]/rubygems/rubygems.git", path.to_s], nil).and_return(["", "", clone_result]) |
18 | 68 | subject.checkout |
19 | 69 | end |
20 | 70 | end |
21 | 71 |
|
22 | 72 | it "adds username and password to URI for host" do |
23 | 73 | Bundler.settings.temporary("github.com" => "u:p") do |
24 | | - allow(subject).to receive(:git_local).with("--version").and_return("git version 2.14.0") |
25 | | - expect(subject).to receive(:capture).with([* base_clone_args, "--", "https://u:[email protected]/rubygems/rubygems.git", path.to_s], nil).and_return(["", "", clone_result]) |
| 74 | + allow(git_proxy).to receive(:git_local).with("--version").and_return("git version 2.14.0") |
| 75 | + expect(git_proxy).to receive(:capture).with([* base_clone_args, "--", "https://u:[email protected]/rubygems/rubygems.git", path.to_s], nil).and_return(["", "", clone_result]) |
26 | 76 | subject.checkout |
27 | 77 | end |
28 | 78 | end |
29 | 79 |
|
30 | 80 | it "does not add username and password to mismatched URI" do |
31 | 81 | Bundler.settings.temporary("https://u:[email protected]/rubygems/rubygems-mismatch.git" => "u:p") do |
32 | | - allow(subject).to receive(:git_local).with("--version").and_return("git version 2.14.0") |
33 | | - expect(subject).to receive(:capture).with([*base_clone_args, "--", uri, path.to_s], nil).and_return(["", "", clone_result]) |
| 82 | + allow(git_proxy).to receive(:git_local).with("--version").and_return("git version 2.14.0") |
| 83 | + expect(git_proxy).to receive(:capture).with([*base_clone_args, "--", uri, path.to_s], nil).and_return(["", "", clone_result]) |
34 | 84 | subject.checkout |
35 | 85 | end |
36 | 86 | end |
37 | 87 |
|
38 | 88 | it "keeps original userinfo" do |
39 | 89 | Bundler.settings.temporary("github.com" => "u:p") do |
40 | 90 | original = "https://orig:[email protected]/rubygems/rubygems.git" |
41 | | - subject = described_class.new(Pathname("path"), original, "HEAD") |
42 | | - allow(subject).to receive(:git_local).with("--version").and_return("git version 2.14.0") |
43 | | - expect(subject).to receive(:capture).with([*base_clone_args, "--", original, path.to_s], nil).and_return(["", "", clone_result]) |
44 | | - subject.checkout |
| 91 | + git_proxy = described_class.new(Pathname("path"), original, options) |
| 92 | + allow(git_proxy).to receive(:git_local).with("--version").and_return("git version 2.14.0") |
| 93 | + expect(git_proxy).to receive(:capture).with([*base_clone_args, "--", original, path.to_s], nil).and_return(["", "", clone_result]) |
| 94 | + git_proxy.checkout |
45 | 95 | end |
46 | 96 | end |
47 | 97 | end |
48 | 98 |
|
49 | 99 | describe "#version" do |
50 | 100 | context "with a normal version number" do |
51 | 101 | before do |
52 | | - expect(subject).to receive(:git_local).with("--version"). |
| 102 | + expect(git_proxy).to receive(:git_local).with("--version"). |
53 | 103 | and_return("git version 1.2.3") |
54 | 104 | end |
55 | 105 |
|
56 | 106 | it "returns the git version number" do |
57 | | - expect(subject.version).to eq("1.2.3") |
| 107 | + expect(git_proxy.version).to eq("1.2.3") |
58 | 108 | end |
59 | 109 |
|
60 | 110 | it "does not raise an error when passed into Gem::Version.create" do |
61 | | - expect { Gem::Version.create subject.version }.not_to raise_error |
| 111 | + expect { Gem::Version.create git_proxy.version }.not_to raise_error |
62 | 112 | end |
63 | 113 | end |
64 | 114 |
|
65 | 115 | context "with a OSX version number" do |
66 | 116 | before do |
67 | | - expect(subject).to receive(:git_local).with("--version"). |
| 117 | + expect(git_proxy).to receive(:git_local).with("--version"). |
68 | 118 | and_return("git version 1.2.3 (Apple Git-BS)") |
69 | 119 | end |
70 | 120 |
|
71 | 121 | it "strips out OSX specific additions in the version string" do |
72 | | - expect(subject.version).to eq("1.2.3") |
| 122 | + expect(git_proxy.version).to eq("1.2.3") |
73 | 123 | end |
74 | 124 |
|
75 | 125 | it "does not raise an error when passed into Gem::Version.create" do |
76 | | - expect { Gem::Version.create subject.version }.not_to raise_error |
| 126 | + expect { Gem::Version.create git_proxy.version }.not_to raise_error |
77 | 127 | end |
78 | 128 | end |
79 | 129 |
|
80 | 130 | context "with a msysgit version number" do |
81 | 131 | before do |
82 | | - expect(subject).to receive(:git_local).with("--version"). |
| 132 | + expect(git_proxy).to receive(:git_local).with("--version"). |
83 | 133 | and_return("git version 1.2.3.msysgit.0") |
84 | 134 | end |
85 | 135 |
|
86 | 136 | it "strips out msysgit specific additions in the version string" do |
87 | | - expect(subject.version).to eq("1.2.3") |
| 137 | + expect(git_proxy.version).to eq("1.2.3") |
88 | 138 | end |
89 | 139 |
|
90 | 140 | it "does not raise an error when passed into Gem::Version.create" do |
91 | | - expect { Gem::Version.create subject.version }.not_to raise_error |
| 141 | + expect { Gem::Version.create git_proxy.version }.not_to raise_error |
92 | 142 | end |
93 | 143 | end |
94 | 144 | end |
95 | 145 |
|
96 | 146 | describe "#full_version" do |
97 | 147 | context "with a normal version number" do |
98 | 148 | before do |
99 | | - expect(subject).to receive(:git_local).with("--version"). |
| 149 | + expect(git_proxy).to receive(:git_local).with("--version"). |
100 | 150 | and_return("git version 1.2.3") |
101 | 151 | end |
102 | 152 |
|
103 | 153 | it "returns the git version number" do |
104 | | - expect(subject.full_version).to eq("1.2.3") |
| 154 | + expect(git_proxy.full_version).to eq("1.2.3") |
105 | 155 | end |
106 | 156 | end |
107 | 157 |
|
108 | 158 | context "with a OSX version number" do |
109 | 159 | before do |
110 | | - expect(subject).to receive(:git_local).with("--version"). |
| 160 | + expect(git_proxy).to receive(:git_local).with("--version"). |
111 | 161 | and_return("git version 1.2.3 (Apple Git-BS)") |
112 | 162 | end |
113 | 163 |
|
114 | 164 | it "does not strip out OSX specific additions in the version string" do |
115 | | - expect(subject.full_version).to eq("1.2.3 (Apple Git-BS)") |
| 165 | + expect(git_proxy.full_version).to eq("1.2.3 (Apple Git-BS)") |
116 | 166 | end |
117 | 167 | end |
118 | 168 |
|
119 | 169 | context "with a msysgit version number" do |
120 | 170 | before do |
121 | | - expect(subject).to receive(:git_local).with("--version"). |
| 171 | + expect(git_proxy).to receive(:git_local).with("--version"). |
122 | 172 | and_return("git version 1.2.3.msysgit.0") |
123 | 173 | end |
124 | 174 |
|
125 | 175 | it "does not strip out msysgit specific additions in the version string" do |
126 | | - expect(subject.full_version).to eq("1.2.3.msysgit.0") |
| 176 | + expect(git_proxy.full_version).to eq("1.2.3.msysgit.0") |
127 | 177 | end |
128 | 178 | end |
129 | 179 | end |
|
0 commit comments