Skip to content
This repository was archived by the owner on Nov 8, 2018. It is now read-only.

Commit 58a637a

Browse files
authored
Merge pull request #100 from mazubieta/feature/supply_pr_metadata
supply metadata files in .git directory
2 parents f2c206a + ad37d2e commit 58a637a

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,17 @@ git config --get pullrequest.id # returns the ID number of the PR
114114
git config --get pullrequest.basebranch # returns the base branch used for the pull request
115115
```
116116

117+
118+
#### Additional files populated
119+
120+
* `.git/id`: the pull request id
121+
122+
* `.git/url`: the URL for the pull request
123+
124+
* `.git/branch`: the branch associated with the pull request
125+
126+
* `.git/base_branch`: the base branch of the pull request
127+
117128
#### Parameters
118129

119130
* `git.depth`: *Optional.* If a positive integer is given, *shallow* clone the

assets/lib/commands/in.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ def output
2424

2525
raise 'git clone failed' unless $CHILD_STATUS.exitstatus.zero?
2626

27+
Dir.chdir(File.join(destination,'.git')) do
28+
system <<-BASH
29+
echo "#{pr['html_url']}" > url
30+
echo "#{pr['number']}" > id
31+
echo "#{pr['head']['ref']}" > branch
32+
echo "#{pr['base']['ref']}" > base_branch
33+
BASH
34+
end
35+
2736
Dir.chdir(destination) do
2837
raise 'git clone failed' unless system("git fetch -q origin pull/#{id}/#{remote_ref}:#{branch_ref} 1>&2")
2938

spec/commands/in_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,27 @@ def dest_dir
8787
value = git('config pullrequest.basebranch', dest_dir)
8888
expect(value).to eq 'master'
8989
end
90+
91+
it 'creates a file that icludes the id in the .git folder' do
92+
value = File.read(File.join(dest_dir,'.git','id')).strip()
93+
expect(value).to eq '1'
94+
end
95+
96+
it 'creates a file that icludes the url in the .git folder' do
97+
value = File.read(File.join(dest_dir,'.git','url')).strip()
98+
expect(value).to eq 'http://example.com'
99+
end
100+
101+
it 'creates a file that icludes ahe branch in the .git folder' do
102+
value = File.read(File.join(dest_dir,'.git','branch')).strip()
103+
expect(value).to eq 'foo'
104+
end
105+
106+
it 'creates a file that icludes the base_branch in the .git folder' do
107+
value = File.read(File.join(dest_dir,'.git','base_branch')).strip()
108+
expect(value).to eq 'master'
109+
end
110+
90111
end
91112

92113
context 'when the git clone fails' do

0 commit comments

Comments
 (0)