git_pretty_accept 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1bb08233347e08a6009b258782b3bb44798f530f
4
- data.tar.gz: 224d416caa7722a452245b09fd3bd684addd3a84
3
+ metadata.gz: baed368a4681ba4cdc080936905f4ec5afdeac40
4
+ data.tar.gz: 9c0199114740ec78a142dd764b76fd140a29518d
5
5
  SHA512:
6
- metadata.gz: 309b1c8978ec26fecb968dfce874f7cac64fd33ef3fb2662c125659f2b97a5ed558886692866c621c2ab430d3fa50c930231213bb570c190f367247cfc9a1bc5
7
- data.tar.gz: e51b2679cd21202663a487eb937657b20f8db223a1e4d04f8bce32fb949fd7a505de5e1b09cad4b374b76d945e7923af73b5aa8bfb5484abce2833f6937ae7a0
6
+ metadata.gz: 3de4384cd754693b1d5d2c35db4d7560a1ebd9acf180fc02d9d80c95454597db3aa3ff7a461ff2f1e45f7f92dfba8278217cf1036739e99ecb394b55152bf9c2
7
+ data.tar.gz: a2f42af113a5733054f9bbc9f77ecf9f0961e3955856db40ba8d3b1a94b414c701c2b0a79dcf086502fc9b3848b988f7eeff7f8c621af6b9995c06495ec9f70a
data/CHANGELOG.markdown CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.2.0 - 2013-12-03
2
+
3
+ * Fix: do not force-delete local PR branch.
4
+ * Fix: fetch origin and rebase master instead of git pull.
5
+ * Feature: be able to set merge message template.
6
+
1
7
  ## 0.1.3 - 2013-11-23
2
8
 
3
9
  * Specify branches when pulling and pushing to origin.
data/Guardfile ADDED
@@ -0,0 +1,5 @@
1
+ guard :rspec do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
@@ -28,6 +28,8 @@ Gem::Specification.new do |spec|
28
28
  spec.add_dependency 'methadone', '~> 1.3.1'
29
29
 
30
30
  spec.add_development_dependency 'bundler', '~> 1.3'
31
+ spec.add_development_dependency 'guard'
32
+ spec.add_development_dependency 'guard-rspec'
31
33
  spec.add_development_dependency 'pry'
32
34
  spec.add_development_dependency 'rdoc'
33
35
  spec.add_development_dependency 'rake'
@@ -4,6 +4,8 @@ require 'methadone'
4
4
 
5
5
  require "git_pretty_accept/version"
6
6
  require "git_pretty_accept/app"
7
+ require "git_pretty_accept/merge_command"
8
+ require "git_pretty_accept/transaction"
7
9
 
8
10
  module GitPrettyAccept
9
11
  # Your code goes here...
@@ -11,31 +11,7 @@ module GitPrettyAccept
11
11
  exit!
12
12
  else
13
13
  options[:edit] = true if options[:edit].nil?
14
-
15
- our = Git.open('.')
16
- source_branch = our.branches.find(&:current).to_s
17
-
18
- commands = [
19
- "git pull origin #{source_branch}",
20
- "git checkout #{branch}",
21
- "git rebase origin/#{source_branch}",
22
- "git push --force origin #{branch}",
23
- "git checkout #{source_branch}",
24
- "git merge --no-ff #{options[:edit] ? '--edit' : '--no-edit'} #{branch}",
25
- "git push origin #{source_branch}",
26
- "git branch -D #{branch}",
27
- "git push origin :#{branch}"
28
- ]
29
-
30
- commands.each_with_index do |command, i|
31
- info "\n#{command}"
32
- unless system(command)
33
- error "\nDue to the error above, " +
34
- "the following commands were not executed: " +
35
- commands[i + 1, commands.size].join("\n")
36
- exit!
37
- end
38
- end
14
+ Transaction.new(branch, options[:edit]).call
39
15
  end
40
16
  end
41
17
 
@@ -0,0 +1,33 @@
1
+ module GitPrettyAccept
2
+ class MergeCommand
3
+ MESSAGE_TEMPLATE_FILENAME = '.git-pretty-accept-template.txt'
4
+
5
+ attr_reader :branch, :let_user_edit_message
6
+
7
+ def initialize(branch, let_user_edit_message)
8
+ @branch = branch
9
+ @let_user_edit_message = let_user_edit_message
10
+ end
11
+
12
+ def merge_message
13
+ if File.exists?(MESSAGE_TEMPLATE_FILENAME)
14
+ File.read(MESSAGE_TEMPLATE_FILENAME)
15
+ end
16
+ end
17
+
18
+ # http://www.seejohncode.com/2012/10/16/proper-escaping-of-single-quotes/
19
+ def merge_message_with_escaped_single_quote
20
+ merge_message.gsub("'") { %q{'\''} }
21
+ end
22
+
23
+ def to_s
24
+ [
25
+ "git merge",
26
+ "--no-ff",
27
+ let_user_edit_message ? '--edit' : '--no-edit',
28
+ branch,
29
+ merge_message && "--message '#{merge_message_with_escaped_single_quote}'"
30
+ ].join(' ')
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,45 @@
1
+ module GitPrettyAccept
2
+ class Transaction
3
+ include Methadone::CLILogging
4
+
5
+ attr_reader :branch, :let_user_edit_message
6
+
7
+ def initialize(branch, let_user_edit_message = true)
8
+ @branch = branch
9
+ @let_user_edit_message = let_user_edit_message
10
+ end
11
+
12
+ def commands
13
+ [
14
+ "git fetch origin",
15
+ "git rebase origin/#{source_branch}",
16
+ "git checkout #{branch}",
17
+ "git rebase origin/#{source_branch}",
18
+ "git push --force origin #{branch}",
19
+ "git checkout #{source_branch}",
20
+ MergeCommand.new(branch, let_user_edit_message).to_s,
21
+ "git push origin #{source_branch}",
22
+ "git branch -d #{branch}",
23
+ "git push origin :#{branch}"
24
+ ]
25
+ end
26
+
27
+ def call
28
+ commands.each_with_index do |command, i|
29
+ info "\n#{command}"
30
+ unless system(command)
31
+ error "\nDue to the error above, " +
32
+ "the following commands were not executed: " +
33
+ commands[i + 1, commands.size].join("\n")
34
+ exit!
35
+ end
36
+ end
37
+ end
38
+
39
+ def source_branch
40
+ return @source_branch if @source_branch
41
+ our = Git.open('.')
42
+ @source_branch = our.branches.find(&:current).to_s
43
+ end
44
+ end
45
+ end
@@ -1,3 +1,3 @@
1
1
  module GitPrettyAccept
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -67,10 +67,11 @@ describe GitPrettyAccept::App do
67
67
  expect(our.log[0].message).to eq("Merge branch 'pr_branch'")
68
68
  expect(our.log[0].parents.size).to eq(2)
69
69
 
70
- expect(our.log[1].message).to eq('Update readme')
71
- expect(our.log[1].parents.size).to eq(1)
70
+ # For some reason, the order of the logs 1 and 2 is indeterminate.
71
+ expect(our.log[1 .. 2].map(&:message).sort)
72
+ .to eq(['Add changelog', 'Update readme'])
72
73
 
73
- expect(our.log[2].message).to eq('Add changelog')
74
+ expect(our.log[1].parents.size).to eq(1)
74
75
  expect(our.log[2].parents.size).to eq(1)
75
76
 
76
77
  expect(our.log[3].message).to eq('Add readme')
@@ -109,4 +110,64 @@ describe GitPrettyAccept::App do
109
110
  'trying to accept master as a pull request branch')
110
111
  end
111
112
  end
113
+
114
+ Steps "should use the .git-pretty-accept-template.txt if available" do
115
+ merge_message = "hello\nworld!"
116
+ repo = TestRepo.new(project_path, tmp_path)
117
+
118
+ Given 'I have a local repo tracking a remote repo' do
119
+ repo.build
120
+ end
121
+
122
+ And 'the local repo has a .git-pretty-accept-template.txt' do
123
+ repo.our.add_merge_message_template_file merge_message
124
+ end
125
+
126
+ And 'I have a PR branch' do
127
+ repo.our.add_branch pr_branch
128
+ end
129
+
130
+ And 'the current branch is master' do
131
+ repo.our.branch('master').checkout
132
+ end
133
+
134
+ When 'I run `git pretty-accept PR_BRANCH`' do
135
+ repo.git_pretty_accept pr_branch
136
+ end
137
+
138
+ Then 'I should see that the .git-pretty-accept-template.txt is the content of
139
+ the merge message' do
140
+ expect(repo.our.log[0].message).to eq(merge_message)
141
+ end
142
+ end
143
+
144
+ Steps "should be able to use a .git-pretty-accept-template.txt with an apostrophe" do
145
+ merge_message = "hello apostrophe (')"
146
+ repo = TestRepo.new(project_path, tmp_path)
147
+
148
+ Given 'I have a local repo tracking a remote repo' do
149
+ repo.build
150
+ end
151
+
152
+ And 'the local repo has a .git-pretty-accept-template.txt' do
153
+ repo.our.add_merge_message_template_file merge_message
154
+ end
155
+
156
+ And 'I have a PR branch' do
157
+ repo.our.add_branch pr_branch
158
+ end
159
+
160
+ And 'the current branch is master' do
161
+ repo.our.branch('master').checkout
162
+ end
163
+
164
+ When 'I run `git pretty-accept PR_BRANCH`' do
165
+ repo.git_pretty_accept pr_branch
166
+ end
167
+
168
+ Then 'I should see that the .git-pretty-accept-template.txt is the content of
169
+ the merge message' do
170
+ expect(repo.our.log[0].message).to eq(merge_message)
171
+ end
172
+ end
112
173
  end
data/spec/spec_helper.rb CHANGED
@@ -6,6 +6,10 @@ require 'git_pretty_accept'
6
6
  # loaded once.
7
7
  #
8
8
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
9
+
10
+ require 'support/test_repo'
11
+ require 'support/test_repo/local_repo'
12
+
9
13
  RSpec.configure do |config|
10
14
  config.treat_symbols_as_metadata_keys_with_true_values = true
11
15
  config.run_all_when_everything_filtered = true
@@ -0,0 +1,38 @@
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
@@ -0,0 +1,32 @@
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
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.1.3
4
+ version: 0.2.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-11-23 00:00:00.000000000 Z
11
+ date: 2013-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: pry
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -135,6 +163,7 @@ files:
135
163
  - .gitignore
136
164
  - CHANGELOG.markdown
137
165
  - Gemfile
166
+ - Guardfile
138
167
  - LICENSE.txt
139
168
  - README.md
140
169
  - Rakefile
@@ -142,9 +171,13 @@ files:
142
171
  - git_pretty_accept.gemspec
143
172
  - lib/git_pretty_accept.rb
144
173
  - lib/git_pretty_accept/app.rb
174
+ - lib/git_pretty_accept/merge_command.rb
175
+ - lib/git_pretty_accept/transaction.rb
145
176
  - lib/git_pretty_accept/version.rb
146
177
  - spec/git_pretty_accept/app_spec.rb
147
178
  - spec/spec_helper.rb
179
+ - spec/support/test_repo.rb
180
+ - spec/support/test_repo/local_repo.rb
148
181
  homepage: https://github.com/gsmendoza/git_pretty_accept
149
182
  licenses:
150
183
  - MIT
@@ -172,3 +205,5 @@ summary: Accept pull requests, the pretty way
172
205
  test_files:
173
206
  - spec/git_pretty_accept/app_spec.rb
174
207
  - spec/spec_helper.rb
208
+ - spec/support/test_repo.rb
209
+ - spec/support/test_repo/local_repo.rb