Skip to content
This repository was archived by the owner on Mar 31, 2022. It is now read-only.

Commit 972f43f

Browse files
committed
Include the $HOME directory if it's not in the list of pwd ancestors.
This fixes the actual behavior to match the documentation, which states that the `.pairs` file may be in the user's home directory.
1 parent 3d0a936 commit 972f43f

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

lib/pivotal_git_scripts/git_pair.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ def read_pairs_config
135135
directory = File.absolute_path(File.join(directory, ".."))
136136
candidate_directories << directory
137137
end
138+
home = File.absolute_path(ENV["HOME"])
139+
candidate_directories << home unless candidate_directories.include? home
138140

139141
pairs_file_path = candidate_directories.
140142
map { |d| File.join(d, ".pairs") }.

spec/cli_spec.rb

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def write(file, content)
2727

2828
# use fake home for .ssh hacks
2929
run "mkdir #{dir}/home"
30-
ENV["HOME"] = File.expand_path("#{dir}/home")
30+
ENV["HOME"] = File.absolute_path("#{dir}/home")
3131

3232
Dir.chdir dir do
3333
run "touch a"
@@ -269,13 +269,40 @@ def git_config_value(name, global = false)
269269
end
270270
end
271271

272-
it "fails if it cannot find a pairs file" do
273-
run "git pair ab", :fail => true
272+
context "and without a .pairs file in the home directory" do
273+
it "fails if it cannot find a pairs file" do
274+
run "git pair ab", :fail => true
275+
end
276+
277+
it "prints instructions" do
278+
result = run "git pair ab", :fail => true
279+
result.should include("Could not find a .pairs file. Create a YAML file in your project or home directory.")
280+
end
274281
end
275282

276-
it "prints instructions" do
277-
result = run "git pair ab", :fail => true
278-
result.should include("Could not find a .pairs file. Create a YAML file in your project or home directory.")
283+
context "but a .pairs file in the home directory" do
284+
around do |example|
285+
file = File.join(ENV["HOME"], ".pairs")
286+
write file, <<-YAML.unindent
287+
pairs:
288+
ab: Aa Bb
289+
bc: Bb Cc
290+
cd: Cc Dd
291+
292+
email:
293+
prefix: the-pair
294+
domain: the-host.com
295+
YAML
296+
297+
example.run
298+
299+
FileUtils.rm file
300+
end
301+
302+
it "loads the file" do
303+
result = run "git pair ab"
304+
expect_config result, "Aa Bb", "ab", "the-pair+aa@the-host.com"
305+
end
279306
end
280307
end
281308
end

0 commit comments

Comments
 (0)