git-process 0.9.1.pre3 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/CHANGELOG.md +0 -0
  2. data/Gemfile +2 -2
  3. data/Gemfile.lock +2 -0
  4. data/README.md +27 -9
  5. data/bin/git-new-fb +42 -13
  6. data/bin/git-pull-request +79 -13
  7. data/bin/git-sync +47 -13
  8. data/bin/git-to-master +56 -13
  9. data/git-process.gemspec +1 -1
  10. data/lib/git-process/{abstract-error-builder.rb → abstract_error_builder.rb} +13 -3
  11. data/lib/git-process/{git-abstract-merge-error-builder.rb → git_abstract_merge_error_builder.rb} +15 -5
  12. data/lib/git-process/{git-branch.rb → git_branch.rb} +13 -1
  13. data/lib/git-process/git_branches.rb +72 -0
  14. data/lib/git-process/{git-lib.rb → git_lib.rb} +82 -70
  15. data/lib/git-process/git_merge_error.rb +38 -0
  16. data/lib/git-process/git_process.rb +124 -0
  17. data/lib/git-process/git_process_error.rb +18 -0
  18. data/lib/git-process/git_process_options.rb +101 -0
  19. data/lib/git-process/git_rebase_error.rb +38 -0
  20. data/lib/git-process/{git-status.rb → git_status.rb} +13 -1
  21. data/lib/git-process/{github-client.rb → github_client.rb} +13 -1
  22. data/lib/git-process/github_pull_request.rb +107 -0
  23. data/lib/git-process/{github-service.rb → github_service.rb} +39 -21
  24. data/lib/git-process/new_fb.rb +40 -0
  25. data/lib/git-process/parked_changes_error.rb +40 -0
  26. data/lib/git-process/pull_request.rb +61 -0
  27. data/lib/git-process/rebase_to_master.rb +110 -0
  28. data/lib/git-process/sync.rb +63 -0
  29. data/lib/git-process/uncommitted_changes_error.rb +23 -0
  30. data/lib/git-process/version.rb +19 -9
  31. data/spec/GitRepoHelper.rb +35 -21
  32. data/spec/{git-abstract-merge-error-builder_spec.rb → git_abstract_merge_error_builder_spec.rb} +3 -3
  33. data/spec/{git-lib_spec.rb → git_lib_spec.rb} +79 -16
  34. data/spec/git_process_spec.rb +36 -0
  35. data/spec/{git-status_spec.rb → git_status_spec.rb} +28 -29
  36. data/spec/github_pull_request_spec.rb +91 -0
  37. data/spec/{github-service_spec.rb → github_service_spec.rb} +1 -1
  38. data/spec/new_fb_spec.rb +80 -0
  39. data/spec/rebase_to_master_spec.rb +314 -0
  40. data/spec/spec_helper.rb +1 -1
  41. data/spec/sync_spec.rb +149 -0
  42. metadata +46 -43
  43. data/lib/git-process/git-branches.rb +0 -53
  44. data/lib/git-process/git-merge-error.rb +0 -31
  45. data/lib/git-process/git-new-fb-options.rb +0 -34
  46. data/lib/git-process/git-process-error.rb +0 -10
  47. data/lib/git-process/git-process-options.rb +0 -82
  48. data/lib/git-process/git-process.rb +0 -194
  49. data/lib/git-process/git-pull-request-options.rb +0 -42
  50. data/lib/git-process/git-rebase-error.rb +0 -31
  51. data/lib/git-process/git-sync-options.rb +0 -34
  52. data/lib/git-process/git-to-master-options.rb +0 -18
  53. data/lib/git-process/parked-changes-error.rb +0 -32
  54. data/lib/git-process/pull-request.rb +0 -38
  55. data/lib/git-process/uncommitted-changes-error.rb +0 -15
  56. data/spec/git-process_spec.rb +0 -328
  57. data/spec/pull-request_spec.rb +0 -57
@@ -1,34 +0,0 @@
1
- require 'git-process-options'
2
-
3
- module Git
4
-
5
- class Process
6
-
7
- class NewFeatureBranchOptions
8
- include GitProcessOptions
9
-
10
- attr_reader :branch_name
11
-
12
- def initialize(filename, argv)
13
- @filename = filename
14
- argv << "-h" if argv.empty?
15
- parse(filename, argv)
16
- end
17
-
18
-
19
- def extend_opts(opts)
20
- opts.banner = "Usage: #{@filename} [ options ] branch_name"
21
- end
22
-
23
-
24
- def extend_args(argv)
25
- raise OptionParser::ParseError.new("Must have exactly one branch name.") if argv.length != 1
26
-
27
- @branch_name = argv.pop
28
- end
29
-
30
- end
31
-
32
- end
33
-
34
- end
@@ -1,10 +0,0 @@
1
- module Git
2
-
3
- class Process
4
-
5
- class GitProcessError < RuntimeError
6
- end
7
-
8
- end
9
-
10
- end
@@ -1,82 +0,0 @@
1
- require 'optparse'
2
-
3
- module Git
4
-
5
- class Process
6
-
7
- module GitProcessOptions
8
-
9
- attr_reader :quiet, :verbose
10
-
11
-
12
- def quiet
13
- @quiet
14
- end
15
-
16
-
17
- def verbose
18
- @verbose
19
- end
20
-
21
-
22
- def log_level
23
- if quiet
24
- Logger::ERROR
25
- elsif verbose
26
- Logger::DEBUG
27
- else
28
- Logger::INFO
29
- end
30
- end
31
-
32
-
33
- def parse(filename, argv)
34
- OptionParser.new do |opts|
35
- opts.banner = "Usage: #{filename} [ options ]"
36
-
37
- opts.on("-q", "--quiet", "Quiet") do
38
- @quiet = true
39
- end
40
-
41
- opts.on("-v", "--verbose", "Verbose") do
42
- @verbose = true
43
- @quiet = false
44
- end
45
-
46
- opts.on("-h", "--help", "Show this message") do
47
- puts opts
48
- exit(-1)
49
- end
50
-
51
- extend_opts(opts)
52
-
53
- begin
54
- begin
55
- opts.parse!(argv)
56
-
57
- extend_args(argv)
58
- rescue OptionParser::ParseError => e
59
- raise "#{e.message}\n#{opts}"
60
- end
61
- rescue RuntimeError => e
62
- STDERR.puts e.message
63
- exit(-1)
64
- end
65
- end
66
- end
67
-
68
-
69
- def extend_opts(opts)
70
- # extension point - does nothing by default
71
- end
72
-
73
-
74
- def extend_args(argv)
75
- # extension point - does nothing by default
76
- end
77
-
78
- end
79
-
80
- end
81
-
82
- end
@@ -1,194 +0,0 @@
1
- require 'git-lib'
2
- require 'uncommitted-changes-error'
3
- require 'git-rebase-error'
4
- require 'git-merge-error'
5
- require 'parked-changes-error'
6
- require 'pull-request'
7
- require 'shellwords'
8
- require 'highline/import'
9
-
10
-
11
- module Git
12
-
13
- class Process
14
- attr_reader :lib
15
-
16
- @@server_name = 'origin'
17
- @@master_branch = 'master'
18
-
19
- def initialize(dir = nil, gitlib = nil, options = {})
20
- @lib = gitlib || Git::GitLib.new(dir, options)
21
- end
22
-
23
-
24
- def Process.remote_master_branch
25
- "#{@@server_name}/#{@@master_branch}"
26
- end
27
-
28
-
29
- def Process.server_name
30
- @@server_name
31
- end
32
-
33
-
34
- def Process.master_branch
35
- @@master_branch
36
- end
37
-
38
-
39
- def rebase_to_master
40
- raise UncommittedChangesError.new unless lib.status.clean?
41
- raise ParkedChangesError.new(lib) if is_parked?
42
-
43
- if lib.has_a_remote?
44
- lib.fetch
45
- rebase(Process::remote_master_branch)
46
- lib.push(Process::server_name, lib.branches.current, Process::master_branch)
47
- remove_feature_branch
48
- else
49
- rebase("master")
50
- end
51
- end
52
-
53
-
54
- def sync_with_server(rebase, force)
55
- raise UncommittedChangesError.new unless lib.status.clean?
56
- raise ParkedChangesError.new(lib) if is_parked?
57
-
58
- current_branch = lib.branches.current
59
- remote_branch = "#{Process::server_name}/#{current_branch}"
60
-
61
- lib.fetch
62
-
63
- if rebase
64
- rebase(Process::remote_master_branch)
65
- else
66
- merge(Process::remote_master_branch)
67
- end
68
-
69
- old_sha = lib.command('rev-parse', remote_branch) rescue ''
70
-
71
- unless current_branch == Process::master_branch
72
- lib.fetch
73
- new_sha = lib.command('rev-parse', remote_branch) rescue ''
74
- unless old_sha == new_sha
75
- logger.warn("'#{current_branch}' changed on '#{Process::server_name}'"+
76
- " [#{old_sha[0..5]}->#{new_sha[0..5]}]; trying sync again.")
77
- sync_with_server(rebase, force)
78
- end
79
- lib.push(Process::server_name, current_branch, current_branch, :force => rebase || force)
80
- else
81
- logger.warn("Not pushing to the server because the current branch is the master branch.")
82
- end
83
- end
84
-
85
-
86
- def new_feature_branch(branch_name)
87
- branches = lib.branches
88
- on_parking = (branches.parking == branches.current)
89
-
90
- if on_parking
91
- new_branch = lib.checkout(branch_name, :new_branch => '_parking_')
92
- branches.parking.delete
93
- new_branch
94
- else
95
- lib.checkout(branch_name, :new_branch => 'origin/master')
96
- end
97
- end
98
-
99
-
100
- def bad_parking_branch_msg
101
- hl = HighLine.new
102
- hl.color("\n***********************************************************************************************\n\n"+
103
- "There is an old '_parking_' branch with unacounted changes in it.\n"+
104
- "It has been renamed to '_parking_OLD_'.\n"+
105
- "Please rename the branch to what the changes are about (`git branch -m _parking_OLD_ my_fb_name`),\n"+
106
- " or remove it altogher (`git branch -D _parking_OLD_`).\n\n"+
107
- "***********************************************************************************************\n", :red, :bold)
108
- end
109
-
110
-
111
- def remove_feature_branch
112
- branches = lib.branches
113
-
114
- remote_master = branches[Process::remote_master_branch]
115
- current_branch = branches.current
116
-
117
- unless remote_master.contains_all_of(current_branch.name)
118
- raise GitProcessError.new("Branch '#{current_branch.name}' has not been merged into '#{Process::remote_master_branch}'")
119
- end
120
-
121
- parking_branch = branches['_parking_']
122
- if parking_branch
123
- if (parking_branch.is_ahead_of(remote_master.name) and
124
- !current_branch.contains_all_of(parking_branch.name))
125
-
126
- parking_branch.rename('_parking_OLD_')
127
-
128
- logger.warn {bad_parking_branch_msg}
129
- else
130
- parking_branch.delete
131
- end
132
- end
133
- remote_master.checkout_to_new('_parking_', :no_track => true)
134
-
135
- current_branch.delete(true)
136
- if branches["#{Process.server_name}/#{current_branch.name}"]
137
- lib.push(Process.server_name, nil, nil, :delete => current_branch.name)
138
- end
139
- end
140
-
141
-
142
- def is_parked?
143
- branches = lib.branches
144
- branches.parking == branches.current
145
- end
146
-
147
-
148
- def rebase(base)
149
- begin
150
- lib.rebase(base)
151
- rescue Git::GitExecuteError => rebase_error
152
- raise RebaseError.new(rebase_error.message, lib)
153
- end
154
- end
155
-
156
-
157
- def merge(base)
158
- begin
159
- lib.merge(base)
160
- rescue Git::GitExecuteError => merge_error
161
- raise MergeError.new(merge_error.message, lib)
162
- end
163
- end
164
-
165
-
166
- def pull_request(repo_name, base, head, title, body, opts = {})
167
- repo_name ||= lib.repo_name
168
- base ||= @@master_branch
169
- head ||= lib.branches.current
170
- title ||= ask_for_pull_title
171
- body ||= ask_for_pull_body
172
- GitHub::PullRequest.new(lib, repo_name, opts).pull_request(base, head, title, body)
173
- end
174
-
175
-
176
- def ask_for_pull_title
177
- ask("What <%= color('title', [:bold]) %> do you want to give the pull request? ") do |q|
178
- q.validate = /^\w+.*/
179
- end
180
- end
181
-
182
-
183
- def ask_for_pull_body
184
- ask("What <%= color('description', [:bold]) %> do you want to give the pull request? ")
185
- end
186
-
187
-
188
- def logger
189
- @lib.logger
190
- end
191
-
192
- end
193
-
194
- end
@@ -1,42 +0,0 @@
1
- require 'git-process-options'
2
-
3
- module Git
4
-
5
- class Process
6
-
7
- class PullRequestOptions
8
- include GitProcessOptions
9
-
10
- attr_reader :user, :password, :description, :title, :filename
11
-
12
- def initialize(filename, argv)
13
- @filename = filename
14
- parse(filename, argv)
15
- end
16
-
17
- def extend_opts(opts)
18
- opts.banner = "Usage: #{filename} [ options ] [pull_request_title]"
19
-
20
- opts.on("-u", "--user name", String, "GitHub account username") do |user|
21
- @user = user
22
- end
23
-
24
- opts.on("-p", "--password pw", String, "GitHub account password") do |password|
25
- @password = password
26
- end
27
-
28
- opts.on(nil, "--desc description", String, "Description of the changes.") do |desc|
29
- @description = desc
30
- end
31
- end
32
-
33
-
34
- def extend_args(argv)
35
- @title = argv.pop unless argv.empty?
36
- end
37
-
38
- end
39
-
40
- end
41
-
42
- end
@@ -1,31 +0,0 @@
1
- require 'git-process-error'
2
- require 'git-abstract-merge-error-builder'
3
-
4
- module Git
5
-
6
- class Process
7
-
8
- class RebaseError < GitProcessError
9
- include Git::AbstractMergeErrorBuilder
10
-
11
- attr_reader :error_message, :lib
12
-
13
- def initialize(rebase_error_message, lib)
14
- @lib = lib
15
- @error_message = rebase_error_message
16
-
17
- msg = build_message
18
-
19
- super(msg)
20
- end
21
-
22
-
23
- def continue_command
24
- 'git rebase --continue'
25
- end
26
-
27
- end
28
-
29
- end
30
-
31
- end
@@ -1,34 +0,0 @@
1
- require 'optparse'
2
- require 'git-process-options'
3
-
4
- module Git
5
-
6
- class Process
7
-
8
- class SyncOptions
9
- include GitProcessOptions
10
-
11
- attr_reader :rebase, :force
12
-
13
-
14
- def initialize(filename, argv)
15
- @rebase = false
16
- @force = false
17
- parse(filename, argv)
18
- end
19
-
20
-
21
- def extend_opts(opts)
22
- opts.on("-r", "--rebase", "Rebase instead of merge") do |v|
23
- @rebase = true
24
- end
25
-
26
- opts.on("-f", "--force", "Force the push") do |v|
27
- @force = true
28
- end
29
- end
30
- end
31
-
32
- end
33
-
34
- end
@@ -1,18 +0,0 @@
1
- require 'optparse'
2
- require 'git-process-options'
3
-
4
- module Git
5
-
6
- class Process
7
-
8
- class ToMasterOptions
9
- include GitProcessOptions
10
-
11
- def initialize(filename, argv)
12
- parse(filename, argv)
13
- end
14
- end
15
-
16
- end
17
-
18
- end
@@ -1,32 +0,0 @@
1
- require 'git-process-error'
2
-
3
- module Git
4
-
5
- class Process
6
-
7
- class ParkedChangesError < GitProcessError
8
- include Git::AbstractErrorBuilder
9
-
10
- attr_reader :error_message, :lib
11
-
12
- def initialize(lib)
13
- @lib = lib
14
- msg = build_message
15
- super(msg)
16
- end
17
-
18
-
19
- def human_message
20
- "You made your changes on the the '_parking_' branch instead of a feature branch.\n"+"Please rename the branch to be a feature branch."
21
- end
22
-
23
-
24
- def build_commands
25
- ['git branch -m _parking_ my_feature_branch']
26
- end
27
-
28
- end
29
-
30
- end
31
-
32
- end
@@ -1,38 +0,0 @@
1
- require 'github-service'
2
- require 'octokit'
3
-
4
-
5
- module GitHub
6
-
7
- class PullRequest
8
- include GitHubService
9
-
10
- attr_reader :lib, :repo
11
-
12
- def initialize(lib, repo, opts = {})
13
- @lib = lib
14
- @repo = repo
15
- @user = opts[:user]
16
- @password = opts[:password]
17
- end
18
-
19
-
20
- def pull_requests
21
- @pull_requests ||= client.pull_requests(repo)
22
- end
23
-
24
-
25
- def create(base, head, title, body)
26
- logger.info { "Creating a pull request asking for '#{head}' to be merged into '#{base}' on #{repo}." }
27
- begin
28
- client.create_pull_request(repo, base, head, title, body)
29
- rescue Octokit::UnprocessableEntity => exp
30
- pull = pull_requests.find {|p| p[:head][:ref] == head and p[:base][:ref] == base}
31
- logger.warn { "Pull request already exists. See #{pull[:html_url]}" }
32
- pull
33
- end
34
- end
35
-
36
- end
37
-
38
- end
@@ -1,15 +0,0 @@
1
- require 'git-process-error'
2
-
3
- module Git
4
-
5
- class Process
6
-
7
- class UncommittedChangesError < GitProcessError
8
- def initialize()
9
- super("There are uncommitted changes.\nPlease either commit your changes, or use 'git stash' to set them aside.")
10
- end
11
- end
12
-
13
- end
14
-
15
- end