git_pretty_accept 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.markdown +5 -0
- data/lib/git_pretty_accept/transaction.rb +1 -0
- data/lib/git_pretty_accept/version.rb +1 -1
- data/spec/git_pretty_accept/app_spec.rb +88 -58
- data/spec/spec_helper.rb +2 -2
- data/spec/support/local_repo.rb +59 -0
- data/spec/support/remote_repo.rb +10 -0
- metadata +6 -6
- data/spec/support/test_repo.rb +0 -38
- data/spec/support/test_repo/local_repo.rb +0 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f87f9416e6f2fa9ffab67ff78e28c62052f40584
|
4
|
+
data.tar.gz: f7d1cd58d438f24d312236f6bf1d845c3660f6b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 050fc7845fa9e5d1998662fa1b9ec13111c6c9c804a5b5ed3ad65c366c652257b220ec3ff7b806daa9c0a659628e6d97c24ab5ad0ae88ecf97055015572001b9
|
7
|
+
data.tar.gz: 9aae68dd5f32c4e303415e777b89fa94f8a6a29da8b497938ea1833c8aa8da0146b2ef677e3c8c129c79ca500ce10021e2039551f035067c9c32b35bda95168d
|
data/CHANGELOG.markdown
CHANGED
@@ -14,6 +14,7 @@ module GitPrettyAccept
|
|
14
14
|
"git fetch origin",
|
15
15
|
"git rebase origin/#{source_branch}",
|
16
16
|
"git checkout #{branch}",
|
17
|
+
"git rebase origin/#{branch}",
|
17
18
|
"git rebase origin/#{source_branch}",
|
18
19
|
"git push --force origin #{branch}",
|
19
20
|
"git checkout #{source_branch}",
|
@@ -12,89 +12,76 @@ describe GitPrettyAccept::App do
|
|
12
12
|
|
13
13
|
let(:pr_branch) { 'pr_branch' }
|
14
14
|
|
15
|
+
let(:remote_repo) { RemoteRepo.new(project_path, remote_path) }
|
16
|
+
let(:local_repo) do
|
17
|
+
LocalRepo.new(project_path, our_path, remote_repo).tap do |result|
|
18
|
+
result.add_initial_commit
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:other_repo) { LocalRepo.new(project_path, their_path, remote_repo) }
|
23
|
+
|
15
24
|
before do
|
16
25
|
FileUtils.rm_rf tmp_path
|
17
26
|
end
|
18
27
|
|
19
28
|
Steps "I can accept a pull request... prettily" do
|
20
|
-
|
29
|
+
their_change_in_master = 'their_change_in_master'
|
30
|
+
our_change_in_pr_branch = 'our_change_in_pr_branch'
|
21
31
|
|
22
32
|
Given 'I have a local repo tracking a remote repo' do
|
23
|
-
|
24
|
-
|
25
|
-
# Add initial commit. Otherwise, `our.branch(pr_branch)`
|
26
|
-
# below won't be able to create a new branch.
|
27
|
-
|
28
|
-
Git.clone remote_path, our_path
|
29
|
-
our = Git.open(our_path)
|
30
|
-
|
31
|
-
File.open("#{our_path}/readme.txt", 'w') { |f| f.write('readme') }
|
32
|
-
our.add all: true
|
33
|
-
our.commit 'Add readme'
|
34
|
-
our.push
|
33
|
+
local_repo
|
35
34
|
end
|
36
35
|
|
37
36
|
And 'I have a PR_BRANCH that is not up-to-date with master' do
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
File.open("#{their_path}/readme.txt", 'w') { |f| f.write('updated readme') }
|
42
|
-
their.add all: true
|
43
|
-
their.commit 'Update readme'
|
44
|
-
their.push
|
37
|
+
other_repo.checkout 'master'
|
38
|
+
other_repo.push_some_change their_change_in_master
|
45
39
|
|
46
|
-
|
47
|
-
|
48
|
-
our.add all: true
|
49
|
-
our.commit 'Add changelog'
|
50
|
-
our.push our.remote('origin'), pr_branch
|
40
|
+
local_repo.checkout pr_branch
|
41
|
+
local_repo.push_some_change our_change_in_pr_branch
|
51
42
|
end
|
52
43
|
|
53
44
|
And 'the current branch is master' do
|
54
|
-
|
45
|
+
local_repo.checkout 'master'
|
55
46
|
end
|
56
47
|
|
57
48
|
When 'I run `git pretty-accept PR_BRANCH`' do
|
58
|
-
|
59
|
-
`bundle exec #{project_path}/bin/git-pretty-accept --no-edit #{pr_branch}`
|
60
|
-
expect($CHILD_STATUS.exitstatus).to eq(0)
|
61
|
-
end
|
49
|
+
local_repo.git_pretty_accept pr_branch
|
62
50
|
end
|
63
51
|
|
64
52
|
Then 'it should rebase the PR_BRANCH before merging to master' do
|
65
|
-
expect(
|
53
|
+
expect(local_repo.git.log.size).to eq(4)
|
66
54
|
|
67
|
-
expect(
|
68
|
-
expect(
|
55
|
+
expect(local_repo.git.log[0].message).to eq("Merge branch '#{pr_branch}'")
|
56
|
+
expect(local_repo.git.log[0].parents.size).to eq(2)
|
69
57
|
|
70
58
|
# For some reason, the order of the logs 1 and 2 is indeterminate.
|
71
|
-
expect(
|
72
|
-
.to eq([
|
59
|
+
expect(local_repo.git.log[1 .. 2].map(&:message).sort)
|
60
|
+
.to eq([our_change_in_pr_branch, their_change_in_master])
|
73
61
|
|
74
|
-
expect(
|
75
|
-
expect(
|
62
|
+
expect(local_repo.git.log[1].parents.size).to eq(1)
|
63
|
+
expect(local_repo.git.log[2].parents.size).to eq(1)
|
76
64
|
|
77
|
-
expect(
|
78
|
-
expect(our.log[3].parents.size).to eq(0)
|
65
|
+
expect(local_repo.git.log[3].parents.size).to eq(0)
|
79
66
|
end
|
80
67
|
|
81
68
|
And 'it should push the PR_BRANCH commits' do
|
82
|
-
expect(
|
83
|
-
.to eq("Merge branch 'pr_branch'")
|
69
|
+
expect(local_repo.git.branches['origin/master'].gcommit.message)
|
70
|
+
.to eq("Merge branch '#{pr_branch}'")
|
84
71
|
end
|
85
72
|
|
86
73
|
And 'it should delete the local PR_BRANCH' do
|
87
|
-
expect(
|
74
|
+
expect(local_repo.git.branches[pr_branch]).to be_nil
|
88
75
|
end
|
89
76
|
|
90
77
|
And 'it should delete the remote PR_BRANCH' do
|
91
|
-
expect(
|
78
|
+
expect(local_repo.git.branches["origin/#{pr_branch}"]).to be_nil
|
92
79
|
end
|
93
80
|
end
|
94
81
|
|
95
82
|
Steps "should not allow master to be accepted as a PR branch" do
|
96
83
|
Given 'I have a local repo' do
|
97
|
-
|
84
|
+
local_repo
|
98
85
|
end
|
99
86
|
|
100
87
|
When 'I run `git pretty-accept master`' do
|
@@ -113,61 +100,104 @@ describe GitPrettyAccept::App do
|
|
113
100
|
|
114
101
|
Steps "should use the .git-pretty-accept-template.txt if available" do
|
115
102
|
merge_message = "hello\nworld!"
|
116
|
-
repo = TestRepo.new(project_path, tmp_path)
|
117
103
|
|
118
104
|
Given 'I have a local repo tracking a remote repo' do
|
119
|
-
|
105
|
+
local_repo
|
120
106
|
end
|
121
107
|
|
122
108
|
And 'the local repo has a .git-pretty-accept-template.txt' do
|
123
|
-
|
109
|
+
local_repo.add_merge_message_template_file merge_message
|
124
110
|
end
|
125
111
|
|
126
112
|
And 'I have a PR branch' do
|
127
|
-
|
113
|
+
local_repo.create_branch pr_branch
|
114
|
+
local_repo.commit_some_change 'some-change'
|
128
115
|
end
|
129
116
|
|
130
117
|
And 'the current branch is master' do
|
131
|
-
|
118
|
+
local_repo.checkout 'master'
|
132
119
|
end
|
133
120
|
|
134
121
|
When 'I run `git pretty-accept PR_BRANCH`' do
|
135
|
-
|
122
|
+
local_repo.git_pretty_accept pr_branch
|
136
123
|
end
|
137
124
|
|
138
125
|
Then 'I should see that the .git-pretty-accept-template.txt is the content of
|
139
126
|
the merge message' do
|
140
|
-
expect(
|
127
|
+
expect(local_repo.git.log[0].message).to eq(merge_message)
|
141
128
|
end
|
142
129
|
end
|
143
130
|
|
144
131
|
Steps "should be able to use a .git-pretty-accept-template.txt with an apostrophe" do
|
145
132
|
merge_message = "hello apostrophe (')"
|
146
|
-
repo = TestRepo.new(project_path, tmp_path)
|
147
133
|
|
148
134
|
Given 'I have a local repo tracking a remote repo' do
|
149
|
-
|
135
|
+
local_repo
|
150
136
|
end
|
151
137
|
|
152
138
|
And 'the local repo has a .git-pretty-accept-template.txt' do
|
153
|
-
|
139
|
+
local_repo.add_merge_message_template_file merge_message
|
154
140
|
end
|
155
141
|
|
156
142
|
And 'I have a PR branch' do
|
157
|
-
|
143
|
+
local_repo.create_branch pr_branch
|
144
|
+
local_repo.commit_some_change 'some-change'
|
158
145
|
end
|
159
146
|
|
160
147
|
And 'the current branch is master' do
|
161
|
-
|
148
|
+
local_repo.checkout 'master'
|
162
149
|
end
|
163
150
|
|
164
151
|
When 'I run `git pretty-accept PR_BRANCH`' do
|
165
|
-
|
152
|
+
local_repo.git_pretty_accept pr_branch
|
166
153
|
end
|
167
154
|
|
168
155
|
Then 'I should see that the .git-pretty-accept-template.txt is the content of
|
169
156
|
the merge message' do
|
170
|
-
expect(
|
157
|
+
expect(local_repo.git.log[0].message).to eq(merge_message)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
Steps 'should rebase the branch from its remote branch' do
|
162
|
+
local_pr_message = 'local-pr-branch-change.txt'
|
163
|
+
remote_pr_message = 'remote-pr-branch-change.txt'
|
164
|
+
|
165
|
+
Given 'I have a local repo tracking a remote repo' do
|
166
|
+
local_repo
|
167
|
+
end
|
168
|
+
|
169
|
+
And 'I have a PR branch tracking a remote PR branch' do
|
170
|
+
other_repo.create_branch pr_branch
|
171
|
+
local_repo.track pr_branch
|
172
|
+
end
|
173
|
+
|
174
|
+
And 'both local and remote PR branch have been updated' do
|
175
|
+
local_repo.commit_some_change local_pr_message
|
176
|
+
|
177
|
+
other_repo.checkout pr_branch
|
178
|
+
other_repo.push_some_change remote_pr_message
|
179
|
+
end
|
180
|
+
|
181
|
+
And 'the current branch is master' do
|
182
|
+
local_repo.checkout 'master'
|
183
|
+
end
|
184
|
+
|
185
|
+
When 'I run `git pretty-accept PR_BRANCH`' do
|
186
|
+
local_repo.git_pretty_accept pr_branch
|
187
|
+
end
|
188
|
+
|
189
|
+
Then 'I should see the commit in the remote PR branch incorporated to master' do
|
190
|
+
expect(local_repo.git.log.size).to eq(4)
|
191
|
+
|
192
|
+
expect(local_repo.git.log[0].message).to eq("Merge branch '#{pr_branch}'")
|
193
|
+
expect(local_repo.git.log[0].parents.size).to eq(2)
|
194
|
+
|
195
|
+
expect(local_repo.git.log[1].message).to eq(local_pr_message)
|
196
|
+
expect(local_repo.git.log[1].parents.size).to eq(1)
|
197
|
+
|
198
|
+
# For some reason, the order of the logs 2 and 3 is indeterminate.
|
199
|
+
expect(local_repo.git.log[2 .. 3].map(&:message).sort)
|
200
|
+
.to include(remote_pr_message)
|
171
201
|
end
|
172
202
|
end
|
173
203
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -7,8 +7,8 @@ require 'git_pretty_accept'
|
|
7
7
|
#
|
8
8
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
9
9
|
|
10
|
-
require 'support/
|
11
|
-
require 'support/
|
10
|
+
require 'support/local_repo'
|
11
|
+
require 'support/remote_repo'
|
12
12
|
|
13
13
|
RSpec.configure do |config|
|
14
14
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
@@ -0,0 +1,59 @@
|
|
1
|
+
class LocalRepo
|
2
|
+
attr_reader :git, :project_path, :path
|
3
|
+
|
4
|
+
def initialize(project_path, path, remote_repo)
|
5
|
+
@project_path = project_path
|
6
|
+
@path = path
|
7
|
+
@remote_repo = remote_repo
|
8
|
+
|
9
|
+
Git.clone remote_repo.path, path
|
10
|
+
@git = Git.open(path)
|
11
|
+
end
|
12
|
+
|
13
|
+
def add_initial_commit
|
14
|
+
File.open("#{path}/readme.txt", 'w') { |f| f.write('readme') }
|
15
|
+
File.open("#{path}/.gitignore", 'w') do |f|
|
16
|
+
f.write('.git-pretty-accept-template.txt')
|
17
|
+
end
|
18
|
+
|
19
|
+
git.add all: true
|
20
|
+
git.commit 'Initial commit.'
|
21
|
+
git.push
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_merge_message_template_file(message)
|
25
|
+
File.open("#{path}/.git-pretty-accept-template.txt", 'w') do |file|
|
26
|
+
file.write message
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def checkout(branch)
|
31
|
+
git.branch(branch).checkout
|
32
|
+
end
|
33
|
+
|
34
|
+
def commit_some_change(message)
|
35
|
+
File.open("#{path}/#{message}.txt", 'w') { |f| f.write(message) }
|
36
|
+
git.add all: true
|
37
|
+
git.commit message
|
38
|
+
end
|
39
|
+
|
40
|
+
def create_branch(branch)
|
41
|
+
git.branch(branch).checkout
|
42
|
+
git.push git.remote('origin'), branch
|
43
|
+
end
|
44
|
+
|
45
|
+
def git_pretty_accept(branch)
|
46
|
+
FileUtils.cd(path) do
|
47
|
+
puts `bundle exec #{project_path}/bin/git-pretty-accept --no-edit #{branch}`
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def push_some_change(message)
|
52
|
+
commit_some_change message
|
53
|
+
git.push git.remote('origin'), git.branches.local.find(&:current)
|
54
|
+
end
|
55
|
+
|
56
|
+
def track(branch)
|
57
|
+
git.branch(branch).checkout
|
58
|
+
end
|
59
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git_pretty_accept
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- George Mendoza
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: git
|
@@ -176,8 +176,8 @@ files:
|
|
176
176
|
- lib/git_pretty_accept/version.rb
|
177
177
|
- spec/git_pretty_accept/app_spec.rb
|
178
178
|
- spec/spec_helper.rb
|
179
|
-
- spec/support/
|
180
|
-
- spec/support/
|
179
|
+
- spec/support/local_repo.rb
|
180
|
+
- spec/support/remote_repo.rb
|
181
181
|
homepage: https://github.com/gsmendoza/git_pretty_accept
|
182
182
|
licenses:
|
183
183
|
- MIT
|
@@ -205,5 +205,5 @@ summary: Accept pull requests, the pretty way
|
|
205
205
|
test_files:
|
206
206
|
- spec/git_pretty_accept/app_spec.rb
|
207
207
|
- spec/spec_helper.rb
|
208
|
-
- spec/support/
|
209
|
-
- spec/support/
|
208
|
+
- spec/support/local_repo.rb
|
209
|
+
- spec/support/remote_repo.rb
|
data/spec/support/test_repo.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
class TestRepo
|
2
|
-
attr_reader :project_path, :tmp_path
|
3
|
-
|
4
|
-
def initialize(project_path, tmp_path)
|
5
|
-
@project_path = project_path
|
6
|
-
@tmp_path = tmp_path
|
7
|
-
end
|
8
|
-
|
9
|
-
def build
|
10
|
-
Git.init remote_path, bare: true
|
11
|
-
|
12
|
-
# Add initial commit. Otherwise, `our.branch(pr_branch)`
|
13
|
-
# below won't be able to create a new branch.
|
14
|
-
|
15
|
-
our.add_initial_commit
|
16
|
-
end
|
17
|
-
|
18
|
-
def our
|
19
|
-
return @our if @our
|
20
|
-
|
21
|
-
Git.clone remote_path, our_path
|
22
|
-
@our = LocalRepo.new(Git.open(our_path))
|
23
|
-
end
|
24
|
-
|
25
|
-
def our_path
|
26
|
-
"#{tmp_path}/our"
|
27
|
-
end
|
28
|
-
|
29
|
-
def remote_path
|
30
|
-
"#{tmp_path}/remote"
|
31
|
-
end
|
32
|
-
|
33
|
-
def git_pretty_accept(branch)
|
34
|
-
FileUtils.cd(our_path) do
|
35
|
-
puts `bundle exec #{project_path}/bin/git-pretty-accept --no-edit #{branch}`
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
class TestRepo
|
2
|
-
class LocalRepo < SimpleDelegator
|
3
|
-
def add_initial_commit
|
4
|
-
File.open("#{path}/readme.txt", 'w') { |f| f.write('readme') }
|
5
|
-
File.open("#{path}/.gitignore", 'w') do |f|
|
6
|
-
f.write('.git-pretty-accept-template.txt')
|
7
|
-
end
|
8
|
-
|
9
|
-
add all: true
|
10
|
-
commit 'Initial commit.'
|
11
|
-
push
|
12
|
-
end
|
13
|
-
|
14
|
-
def add_branch(branch)
|
15
|
-
branch(branch).checkout
|
16
|
-
File.open("#{path}/changelog.txt", 'w') { |f| f.write('changelog') }
|
17
|
-
add all: true
|
18
|
-
commit 'Add changelog'
|
19
|
-
push remote('origin'), branch
|
20
|
-
end
|
21
|
-
|
22
|
-
def add_merge_message_template_file(message)
|
23
|
-
File.open("#{path}/.git-pretty-accept-template.txt", 'w') do |file|
|
24
|
-
file.write message
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def path
|
29
|
-
@path ||= dir.path
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|