git_pretty_accept 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +7 -0
- data/README.md +40 -0
- data/Rakefile +1 -0
- data/bin/git-pretty-accept +5 -0
- data/git_pretty_accept.gemspec +36 -0
- data/lib/git_pretty_accept/app.rb +43 -0
- data/lib/git_pretty_accept/version.rb +3 -0
- data/lib/git_pretty_accept.rb +11 -0
- data/spec/git_pretty_accept/app_spec.rb +93 -0
- data/spec/spec_helper.rb +19 -0
- metadata +197 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2013 YOUR NAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# git-pretty-accept
|
2
|
+
|
3
|
+
`git-pretty-accept` is a script that rebases a pull request before merging
|
4
|
+
to master. Pull requests are _always_ merged recursively. The result is a
|
5
|
+
linear history with merge bubbles indicating pull requests. In short, pretty.
|
6
|
+
|
7
|
+
For more information, check out
|
8
|
+
|
9
|
+
* [A simple git branching model](https://gist.github.com/jbenet/ee6c9ac48068889b0912)
|
10
|
+
* [Best Way To Merge A (GitHub) Pull Request](http://differential.io/blog/best-way-to-merge-a-github-pull-request)
|
11
|
+
|
12
|
+
`git-pretty-accept` also automatically deletes the local and remote branch
|
13
|
+
of the pull request once it's merged to master. I may add an option later on
|
14
|
+
to disable this by default.
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Add this line to your application's Gemfile:
|
19
|
+
|
20
|
+
gem 'git_pretty_accept'
|
21
|
+
|
22
|
+
And then execute:
|
23
|
+
|
24
|
+
$ bundle
|
25
|
+
|
26
|
+
Or install it yourself as:
|
27
|
+
|
28
|
+
$ gem install git_pretty_accept
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
$ git pretty-accept BRANCH
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
1. Fork it
|
37
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
38
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
39
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
40
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'git_pretty_accept/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "git_pretty_accept"
|
8
|
+
spec.version = GitPrettyAccept::VERSION
|
9
|
+
spec.authors = ["George Mendoza"]
|
10
|
+
spec.email = ["gsmendoza@gmail.com"]
|
11
|
+
spec.description = %q{
|
12
|
+
`git-pretty-accept` is a script that rebases a pull request before
|
13
|
+
merging to master. Pull requests are _always_ merged recursively. The
|
14
|
+
result is a linear history with merge bubbles indicating pull requests.
|
15
|
+
In short, pretty.
|
16
|
+
}.gsub(/\s+/, ' ')
|
17
|
+
|
18
|
+
spec.summary = %q{Accept pull requests, the pretty way}
|
19
|
+
spec.homepage = "https://github.com/gsmendoza/git_pretty_accept"
|
20
|
+
spec.license = "MIT"
|
21
|
+
|
22
|
+
spec.files = `git ls-files`.split($/)
|
23
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
24
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_dependency 'git'
|
28
|
+
spec.add_dependency('methadone', '~> 1.3.1')
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
31
|
+
spec.add_development_dependency('rdoc')
|
32
|
+
spec.add_development_dependency('debugger')
|
33
|
+
spec.add_development_dependency('rake', '~> 0.9.2')
|
34
|
+
spec.add_development_dependency('rspec')
|
35
|
+
spec.add_development_dependency('rspec-example_steps')
|
36
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module GitPrettyAccept
|
2
|
+
class App
|
3
|
+
include Methadone::Main
|
4
|
+
include Methadone::CLILogging
|
5
|
+
|
6
|
+
main do |branch|
|
7
|
+
options[:edit] = true if options[:edit].nil?
|
8
|
+
|
9
|
+
our = Git.open('.')
|
10
|
+
source_branch = our.branches.find(&:current).to_s
|
11
|
+
|
12
|
+
commands = [
|
13
|
+
"git pull",
|
14
|
+
"git checkout #{branch}",
|
15
|
+
"git rebase #{source_branch}",
|
16
|
+
"git checkout #{source_branch}",
|
17
|
+
"git merge --no-ff #{options[:edit] ? '--edit' : '--no-edit'} #{branch}",
|
18
|
+
"git push",
|
19
|
+
"git branch -d #{branch}",
|
20
|
+
"git push origin :#{branch}"
|
21
|
+
]
|
22
|
+
|
23
|
+
commands.each_with_index do |command, i|
|
24
|
+
puts "\n#{command}"
|
25
|
+
unless system(command)
|
26
|
+
puts "\nDue to the error above, the following commands were not executed: "
|
27
|
+
puts commands[i + 1, commands.size].join("\n")
|
28
|
+
exit!
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
description "Accept pull requests, the pretty way"
|
34
|
+
|
35
|
+
on "--[no-]edit", "Edit merge message before committing. (Default: --edit)"
|
36
|
+
|
37
|
+
arg :branch
|
38
|
+
|
39
|
+
version GitPrettyAccept::VERSION
|
40
|
+
|
41
|
+
use_log_level_option
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'English'
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'rspec/example_steps'
|
4
|
+
|
5
|
+
describe GitPrettyAccept::App do
|
6
|
+
let!(:project_path) { FileUtils.pwd }
|
7
|
+
let(:tmp_path) { "tmp/git_pretty_accept" }
|
8
|
+
|
9
|
+
let(:remote_path) { "#{tmp_path}/remote" }
|
10
|
+
let(:our_path) { "#{tmp_path}/our" }
|
11
|
+
let(:their_path) { "#{tmp_path}/their" }
|
12
|
+
|
13
|
+
let(:pr_branch) { 'pr_branch' }
|
14
|
+
|
15
|
+
before do
|
16
|
+
FileUtils.rm_rf tmp_path
|
17
|
+
end
|
18
|
+
|
19
|
+
Steps "I can accept a pull request... prettily" do
|
20
|
+
our = nil
|
21
|
+
|
22
|
+
Given 'I have a local repo tracking a remote repo' do
|
23
|
+
Git.init remote_path, bare: true
|
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
|
35
|
+
end
|
36
|
+
|
37
|
+
And 'I have a PR_BRANCH that is not up-to-date with master' do
|
38
|
+
Git.clone remote_path, their_path
|
39
|
+
their = Git.open(their_path)
|
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
|
45
|
+
|
46
|
+
our.branch(pr_branch).checkout
|
47
|
+
File.open("#{our_path}/changelog.txt", 'w') { |f| f.write('changelog') }
|
48
|
+
our.add all: true
|
49
|
+
our.commit 'Add changelog'
|
50
|
+
our.push our.remote('origin'), pr_branch
|
51
|
+
end
|
52
|
+
|
53
|
+
And 'the current branch is master' do
|
54
|
+
our.branch('master').checkout
|
55
|
+
end
|
56
|
+
|
57
|
+
When 'I run `git pretty-accept PR_BRANCH`' do
|
58
|
+
FileUtils.cd(our_path) do
|
59
|
+
`#{project_path}/bin/git-pretty-accept --no-edit #{pr_branch}`
|
60
|
+
expect($CHILD_STATUS.exitstatus).to eq(0)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
Then 'it should rebase the PR_BRANCH before merging to master' do
|
65
|
+
expect(our.log.size).to eq(4)
|
66
|
+
|
67
|
+
expect(our.log[0].message).to eq("Merge branch 'pr_branch'")
|
68
|
+
expect(our.log[0].parents.size).to eq(2)
|
69
|
+
|
70
|
+
expect(our.log[1].message).to eq('Add changelog')
|
71
|
+
expect(our.log[1].parents.size).to eq(1)
|
72
|
+
|
73
|
+
expect(our.log[2].message).to eq('Update readme')
|
74
|
+
expect(our.log[2].parents.size).to eq(1)
|
75
|
+
|
76
|
+
expect(our.log[3].message).to eq('Add readme')
|
77
|
+
expect(our.log[3].parents.size).to eq(0)
|
78
|
+
end
|
79
|
+
|
80
|
+
And 'it should push the PR_BRANCH commits' do
|
81
|
+
expect(our.branches['origin/master'].gcommit.message)
|
82
|
+
.to eq("Merge branch 'pr_branch'")
|
83
|
+
end
|
84
|
+
|
85
|
+
And 'it should delete the local PR_BRANCH' do
|
86
|
+
expect(our.branches[pr_branch]).to be_nil
|
87
|
+
end
|
88
|
+
|
89
|
+
And 'it should delete the remote PR_BRANCH' do
|
90
|
+
expect(our.branches["origin/#{pr_branch}"]).to be_nil
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'debugger'
|
2
|
+
require 'git_pretty_accept'
|
3
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
4
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
5
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
6
|
+
# loaded once.
|
7
|
+
#
|
8
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
11
|
+
config.run_all_when_everything_filtered = true
|
12
|
+
config.filter_run :focus
|
13
|
+
|
14
|
+
# Run specs in random order to surface order dependencies. If you find an
|
15
|
+
# order dependency and want to debug it, you can fix the order by providing
|
16
|
+
# the seed, which is printed after each run.
|
17
|
+
# --seed 1234
|
18
|
+
config.order = 'random'
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: git_pretty_accept
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- George Mendoza
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-11-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
none: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ! '>='
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '0'
|
26
|
+
none: false
|
27
|
+
prerelease: false
|
28
|
+
name: git
|
29
|
+
type: :runtime
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ~>
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 1.3.1
|
36
|
+
none: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 1.3.1
|
42
|
+
none: false
|
43
|
+
prerelease: false
|
44
|
+
name: methadone
|
45
|
+
type: :runtime
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
requirement: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ~>
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '1.3'
|
52
|
+
none: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '1.3'
|
58
|
+
none: false
|
59
|
+
prerelease: false
|
60
|
+
name: bundler
|
61
|
+
type: :development
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
none: false
|
69
|
+
version_requirements: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
none: false
|
75
|
+
prerelease: false
|
76
|
+
name: rdoc
|
77
|
+
type: :development
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
requirement: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
none: false
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
none: false
|
91
|
+
prerelease: false
|
92
|
+
name: debugger
|
93
|
+
type: :development
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
requirement: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ~>
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: 0.9.2
|
100
|
+
none: false
|
101
|
+
version_requirements: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ~>
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: 0.9.2
|
106
|
+
none: false
|
107
|
+
prerelease: false
|
108
|
+
name: rake
|
109
|
+
type: :development
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
requirement: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
none: false
|
117
|
+
version_requirements: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ! '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
none: false
|
123
|
+
prerelease: false
|
124
|
+
name: rspec
|
125
|
+
type: :development
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
none: false
|
133
|
+
version_requirements: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ! '>='
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
none: false
|
139
|
+
prerelease: false
|
140
|
+
name: rspec-example_steps
|
141
|
+
type: :development
|
142
|
+
description: ! ' `git-pretty-accept` is a script that rebases a pull request before
|
143
|
+
merging to master. Pull requests are _always_ merged recursively. The result is
|
144
|
+
a linear history with merge bubbles indicating pull requests. In short, pretty. '
|
145
|
+
email:
|
146
|
+
- gsmendoza@gmail.com
|
147
|
+
executables:
|
148
|
+
- git-pretty-accept
|
149
|
+
extensions: []
|
150
|
+
extra_rdoc_files: []
|
151
|
+
files:
|
152
|
+
- .gitignore
|
153
|
+
- Gemfile
|
154
|
+
- LICENSE.txt
|
155
|
+
- README.md
|
156
|
+
- Rakefile
|
157
|
+
- bin/git-pretty-accept
|
158
|
+
- git_pretty_accept.gemspec
|
159
|
+
- lib/git_pretty_accept.rb
|
160
|
+
- lib/git_pretty_accept/app.rb
|
161
|
+
- lib/git_pretty_accept/version.rb
|
162
|
+
- spec/git_pretty_accept/app_spec.rb
|
163
|
+
- spec/spec_helper.rb
|
164
|
+
homepage: https://github.com/gsmendoza/git_pretty_accept
|
165
|
+
licenses:
|
166
|
+
- MIT
|
167
|
+
post_install_message:
|
168
|
+
rdoc_options: []
|
169
|
+
require_paths:
|
170
|
+
- lib
|
171
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
172
|
+
requirements:
|
173
|
+
- - ! '>='
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
hash: -399594131
|
176
|
+
version: '0'
|
177
|
+
segments:
|
178
|
+
- 0
|
179
|
+
none: false
|
180
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
181
|
+
requirements:
|
182
|
+
- - ! '>='
|
183
|
+
- !ruby/object:Gem::Version
|
184
|
+
hash: -399594131
|
185
|
+
version: '0'
|
186
|
+
segments:
|
187
|
+
- 0
|
188
|
+
none: false
|
189
|
+
requirements: []
|
190
|
+
rubyforge_project:
|
191
|
+
rubygems_version: 1.8.24
|
192
|
+
signing_key:
|
193
|
+
specification_version: 3
|
194
|
+
summary: Accept pull requests, the pretty way
|
195
|
+
test_files:
|
196
|
+
- spec/git_pretty_accept/app_spec.rb
|
197
|
+
- spec/spec_helper.rb
|