git-process 1.0.4 → 1.0.5

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.
Files changed (36) hide show
  1. data/CHANGELOG.md +11 -1
  2. data/README.md +2 -8
  3. data/lib/git-process/abstract_error_builder.rb +2 -2
  4. data/lib/git-process/changed_file_helper.rb +1 -1
  5. data/lib/git-process/git_abstract_merge_error_builder.rb +2 -1
  6. data/lib/git-process/git_branch.rb +3 -2
  7. data/lib/git-process/git_branches.rb +9 -8
  8. data/lib/git-process/git_lib.rb +18 -19
  9. data/lib/git-process/git_merge_error.rb +2 -1
  10. data/lib/git-process/git_process.rb +8 -6
  11. data/lib/git-process/git_process_error.rb +1 -1
  12. data/lib/git-process/git_process_options.rb +6 -8
  13. data/lib/git-process/git_rebase_error.rb +2 -1
  14. data/lib/git-process/git_status.rb +37 -36
  15. data/lib/git-process/github_client.rb +8 -10
  16. data/lib/git-process/github_pull_request.rb +9 -7
  17. data/lib/git-process/github_service.rb +7 -7
  18. data/lib/git-process/new_fb.rb +1 -1
  19. data/lib/git-process/parked_changes_error.rb +2 -1
  20. data/lib/git-process/pull_request.rb +1 -1
  21. data/lib/git-process/rebase_to_master.rb +10 -9
  22. data/lib/git-process/sync.rb +17 -5
  23. data/lib/git-process/uncommitted_changes_error.rb +1 -1
  24. data/lib/git-process/version.rb +2 -2
  25. data/spec/FileHelpers.rb +1 -0
  26. data/spec/GitRepoHelper.rb +3 -3
  27. data/spec/changed_file_helper_spec.rb +2 -2
  28. data/spec/git_abstract_merge_error_builder_spec.rb +32 -28
  29. data/spec/git_lib_spec.rb +16 -13
  30. data/spec/git_process_spec.rb +2 -1
  31. data/spec/git_status_spec.rb +5 -4
  32. data/spec/github_pull_request_spec.rb +9 -8
  33. data/spec/github_service_spec.rb +10 -8
  34. data/spec/rebase_to_master_spec.rb +7 -6
  35. data/spec/sync_spec.rb +56 -22
  36. metadata +30 -17
@@ -8,7 +8,7 @@
8
8
  # distributed under the License is distributed on an "AS IS" BASIS,
9
9
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
10
  # See the License for the specific language governing permissions and
11
- # limitations under the License.require 'shellwords'
11
+ # limitations under the License.
12
12
 
13
13
  require 'octokit'
14
14
 
@@ -23,19 +23,16 @@ module Octokit
23
23
  def connection(authenticate=true, raw=false, version=3, force_urlencoded=false)
24
24
  if site
25
25
  url = site
26
+ elsif version == 2
27
+ url = "https://github.com"
26
28
  else
27
- case version
28
- when 2
29
- url = "https://github.com"
30
- when 3
31
- url = "https://api.github.com"
32
- end
29
+ url = "https://api.github.com"
33
30
  end
34
31
 
35
32
  options = {
36
- :proxy => proxy,
37
- :ssl => { :verify => false },
38
- :url => url,
33
+ :proxy => proxy,
34
+ :ssl => {:verify => false},
35
+ :url => url,
39
36
  }
40
37
 
41
38
  options.merge!(:params => {:access_token => oauth_token}) if oauthed? && !authenticated?
@@ -75,6 +72,7 @@ class GitHubClient < Octokit::Client
75
72
 
76
73
  alias :old_request :request
77
74
 
75
+
78
76
  def request(method, path, options, version, authenticate, raw, force_urlencoded)
79
77
  if /api.github.com/ !~ site
80
78
  path = "/api/v3/#{path}"
@@ -8,7 +8,7 @@
8
8
  # distributed under the License is distributed on an "AS IS" BASIS,
9
9
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
10
  # See the License for the specific language governing permissions and
11
- # limitations under the License.require 'shellwords'
11
+ # limitations under the License.
12
12
 
13
13
  require 'git-process/github_service'
14
14
  require 'octokit'
@@ -22,6 +22,7 @@ module GitHub
22
22
 
23
23
  attr_reader :lib, :repo
24
24
 
25
+
25
26
  def initialize(lib, repo, opts = {})
26
27
  @lib = lib
27
28
  @repo = repo
@@ -39,8 +40,8 @@ module GitHub
39
40
  logger.info { "Creating a pull request asking for '#{head}' to be merged into '#{base}' on #{repo}." }
40
41
  begin
41
42
  client.create_pull_request(repo, base, head, title, body)
42
- rescue Octokit::UnprocessableEntity => exp
43
- pull = pull_requests.find {|p| p[:head][:ref] == head and p[:base][:ref] == base}
43
+ rescue Octokit::UnprocessableEntity
44
+ pull = pull_requests.find { |p| p[:head][:ref] == head and p[:base][:ref] == base }
44
45
  logger.warn { "Pull request already exists. See #{pull[:html_url]}" }
45
46
  pull
46
47
  end
@@ -49,7 +50,7 @@ module GitHub
49
50
 
50
51
  def find_pull_request(base, head)
51
52
  json = pull_requests
52
- json.find {|p| p[:head][:ref] == head and p[:base][:ref] == base}
53
+ json.find { |p| p[:head][:ref] == head and p[:base][:ref] == base }
53
54
  end
54
55
 
55
56
 
@@ -62,7 +63,7 @@ module GitHub
62
63
  logger.info { "Closing a pull request asking for '#{head}' to be merged into '#{base}' on #{repo}." }
63
64
 
64
65
  json = pull_requests
65
- pull = json.find {|p| p[:head][:ref] == head and p[:base][:ref] == base}
66
+ pull = json.find { |p| p[:head][:ref] == head and p[:base][:ref] == base }
66
67
 
67
68
  raise NotFoundError.new(base, head, repo, json) if pull.nil?
68
69
 
@@ -72,13 +73,14 @@ module GitHub
72
73
  logger.info { "Closing a pull request \##{pull_number} on #{repo}." }
73
74
  end
74
75
 
75
- client.patch("repos/#{Octokit::Repository.new(repo)}/pulls/#{pull_number}", {:state => 'closed'})
76
+ client.patch("repos/#{Octokit::Repository.new(repo)}/pulls/#{pull_number}", {:state => 'closed'})
76
77
  end
77
78
 
78
79
 
79
80
  class NotFoundError < StandardError
80
81
  attr_reader :base, :head, :repo
81
82
 
83
+
82
84
  def initialize(base, head, repo, pull_requests_json)
83
85
  @base = base
84
86
  @head = head
@@ -90,7 +92,7 @@ module GitHub
90
92
 
91
93
  msg = "Could not find a pull request for '#{head}' to be merged with '#{base}' on #{repo}."
92
94
  msg += "\n\nExisting Pull Requests:"
93
- msg = pull_requests.inject(msg) {|a,v| "#{a}\n #{v[:head]} -> #{v[:base]}" }
95
+ msg = pull_requests.inject(msg) { |a, v| "#{a}\n #{v[:head]} -> #{v[:base]}" }
94
96
 
95
97
  super(msg)
96
98
  end
@@ -8,7 +8,7 @@
8
8
  # distributed under the License is distributed on an "AS IS" BASIS,
9
9
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
10
  # See the License for the specific language governing permissions and
11
- # limitations under the License.require 'shellwords'
11
+ # limitations under the License.
12
12
 
13
13
  require 'highline/import'
14
14
  require 'git-process/github_client'
@@ -21,7 +21,7 @@ module GitHubService
21
21
  if @client.nil?
22
22
  auth_token
23
23
  logger.debug { "Creating GitHub client for user #{user} using token '#{auth_token}'" }
24
- @client = GitHubClient.new(:login => user, :oauth_token=> auth_token)
24
+ @client = GitHubClient.new(:login => user, :oauth_token => auth_token)
25
25
  @client.site = site
26
26
  end
27
27
  @client
@@ -38,8 +38,8 @@ module GitHubService
38
38
 
39
39
  raise GitHubService::NoRemoteRepository.new("There is no value set for 'remote.origin.url'") if origin_url.empty?
40
40
 
41
- if /^git\@/ =~ origin_url
42
- host = origin_url.sub(/^git\@(.*?):.*$/, '\1')
41
+ if /^git@/ =~ origin_url
42
+ host = origin_url.sub(/^git@(.*?):.*$/, '\1')
43
43
  site = host_to_site(host, false)
44
44
  else
45
45
  uri = URI.parse(origin_url)
@@ -68,10 +68,10 @@ module GitHubService
68
68
  in_host_section = false
69
69
  host_name = nil
70
70
 
71
- sections = config_lines.each do |line|
71
+ config_lines.each do |line|
72
72
  line.chop!
73
73
  if /^\s*Host\s+#{host_alias}\s*$/ =~ line
74
- in_host_section = true
74
+ in_host_section = true
75
75
  next
76
76
  end
77
77
  if in_host_section and (/^\s*HostName\s+\S+\s*$/ =~ line)
@@ -141,7 +141,7 @@ module GitHubService
141
141
 
142
142
  def create_authorization
143
143
  logger.info("Authorizing #{user} to work with #{site}.")
144
- auth = pw_client.create_authorization(:scopes => ['repo', 'user', 'gist'],
144
+ auth = pw_client.create_authorization(:scopes => %w(repo user gist),
145
145
  :note => 'Git-Process',
146
146
  :note_url => 'http://jdigger.github.com/git-process')
147
147
  config_auth_token = auth['token']
@@ -8,7 +8,7 @@
8
8
  # distributed under the License is distributed on an "AS IS" BASIS,
9
9
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
10
  # See the License for the specific language governing permissions and
11
- # limitations under the License.require 'shellwords'
11
+ # limitations under the License.
12
12
 
13
13
  require 'git-process/git_process'
14
14
 
@@ -8,7 +8,7 @@
8
8
  # distributed under the License is distributed on an "AS IS" BASIS,
9
9
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
10
  # See the License for the specific language governing permissions and
11
- # limitations under the License.require 'shellwords'
11
+ # limitations under the License.
12
12
 
13
13
  require 'git-process/git_process_error'
14
14
 
@@ -19,6 +19,7 @@ module GitProc
19
19
 
20
20
  attr_reader :error_message, :lib
21
21
 
22
+
22
23
  def initialize(lib)
23
24
  @lib = lib
24
25
  msg = build_message
@@ -8,7 +8,7 @@
8
8
  # distributed under the License is distributed on an "AS IS" BASIS,
9
9
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
10
  # See the License for the specific language governing permissions and
11
- # limitations under the License.require 'shellwords'
11
+ # limitations under the License.
12
12
 
13
13
  require 'git-process/git_process'
14
14
  require 'git-process/github_pull_request'
@@ -8,7 +8,7 @@
8
8
  # distributed under the License is distributed on an "AS IS" BASIS,
9
9
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
10
  # See the License for the specific language governing permissions and
11
- # limitations under the License.require 'shellwords'
11
+ # limitations under the License.
12
12
 
13
13
  require 'git-process/git_process'
14
14
  require 'git-process/git_rebase_error'
@@ -36,6 +36,7 @@ module GitProc
36
36
  end
37
37
 
38
38
 
39
+ #noinspection RubyControlFlowConversionInspection
39
40
  def runner
40
41
  if has_a_remote?
41
42
  fetch(server_name)
@@ -65,12 +66,12 @@ module GitProc
65
66
 
66
67
  parking_branch = mybranches['_parking_']
67
68
  if parking_branch
68
- if (parking_branch.is_ahead_of(remote_master.name) and
69
- !current_branch.contains_all_of(parking_branch.name))
69
+ if parking_branch.is_ahead_of(remote_master.name) and
70
+ !current_branch.contains_all_of(parking_branch.name)
70
71
 
71
72
  parking_branch.rename('_parking_OLD_')
72
73
 
73
- logger.warn {bad_parking_branch_msg}
74
+ logger.warn { bad_parking_branch_msg }
74
75
  else
75
76
  parking_branch.delete!
76
77
  end
@@ -114,11 +115,11 @@ module GitProc
114
115
  def bad_parking_branch_msg
115
116
  hl = HighLine.new
116
117
  hl.color("\n***********************************************************************************************\n\n"+
117
- "There is an old '_parking_' branch with unacounted changes in it.\n"+
118
- "It has been renamed to '_parking_OLD_'.\n"+
119
- "Please rename the branch to what the changes are about (`git branch -m _parking_OLD_ my_fb_name`),\n"+
120
- " or remove it altogher (`git branch -D _parking_OLD_`).\n\n"+
121
- "***********************************************************************************************\n", :red, :bold)
118
+ "There is an old '_parking_' branch with unacounted changes in it.\n"+
119
+ "It has been renamed to '_parking_OLD_'.\n"+
120
+ "Please rename the branch to what the changes are about (`git branch -m _parking_OLD_ my_fb_name`),\n"+
121
+ " or remove it altogher (`git branch -D _parking_OLD_`).\n\n"+
122
+ "***********************************************************************************************\n", :red, :bold)
122
123
  end
123
124
 
124
125
  end
@@ -8,7 +8,7 @@
8
8
  # distributed under the License is distributed on an "AS IS" BASIS,
9
9
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
10
  # See the License for the specific language governing permissions and
11
- # limitations under the License.require 'shellwords'
11
+ # limitations under the License.
12
12
 
13
13
  require 'git-process/git_lib'
14
14
  require 'git-process/git_process'
@@ -22,6 +22,7 @@ module GitProc
22
22
  class Sync < Process
23
23
  include ChangeFileHelper
24
24
 
25
+
25
26
  def initialize(dir, opts)
26
27
  opts[:force] = true if opts[:rebase]
27
28
 
@@ -38,6 +39,7 @@ module GitProc
38
39
  end
39
40
 
40
41
 
42
+ #noinspection RubyControlFlowConversionInspection
41
43
  def verify_preconditions
42
44
  super
43
45
 
@@ -56,9 +58,17 @@ module GitProc
56
58
 
57
59
  def runner
58
60
  @current_branch ||= branches.current
59
- @remote_branch ||= "#{server_name}/#{@current_branch}"
61
+ @remote_branch ||= "#{server_name}/#@current_branch"
60
62
 
61
- fetch(server_name)
63
+ # if the remote branch has changed, merge those changes in before
64
+ # doing anything with the integration branch
65
+ old_sha = rev_parse(@remote_branch) rescue ''
66
+ fetch(server_name) if has_a_remote?
67
+ new_sha = rev_parse(@remote_branch) rescue ''
68
+ unless old_sha == new_sha
69
+ logger.info('There have been changes on this remote branch, so will merge them in.')
70
+ proc_merge(@remote_branch)
71
+ end
62
72
 
63
73
  if @do_rebase
64
74
  proc_rebase(integration_branch)
@@ -68,6 +78,8 @@ module GitProc
68
78
 
69
79
  if @local
70
80
  logger.debug("Not pushing to the server because the user selected local-only.")
81
+ elsif not has_a_remote?
82
+ logger.debug("Not pushing to the server because there is no remote.")
71
83
  elsif @current_branch == master_branch
72
84
  logger.warn("Not pushing to the server because the current branch is the mainline branch.")
73
85
  else
@@ -87,8 +99,8 @@ module GitProc
87
99
  fetch(server_name)
88
100
  new_sha = rev_parse(@remote_branch) rescue ''
89
101
  unless old_sha == new_sha
90
- logger.warn("'#{@current_branch}' changed on '#{server_name}'"+
91
- " [#{old_sha[0..5]}->#{new_sha[0..5]}]; trying sync again.")
102
+ logger.warn("'#@current_branch' changed on '#{server_name}'"+
103
+ " [#{old_sha[0..5]}->#{new_sha[0..5]}]; trying sync again.")
92
104
  runner # try again
93
105
  end
94
106
  end
@@ -8,7 +8,7 @@
8
8
  # distributed under the License is distributed on an "AS IS" BASIS,
9
9
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
10
  # See the License for the specific language governing permissions and
11
- # limitations under the License.require 'shellwords'
11
+ # limitations under the License.
12
12
 
13
13
  require 'git-process/git_process_error'
14
14
 
@@ -8,13 +8,13 @@
8
8
  # distributed under the License is distributed on an "AS IS" BASIS,
9
9
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
10
  # See the License for the specific language governing permissions and
11
- # limitations under the License.require 'shellwords'
11
+ # limitations under the License.
12
12
 
13
13
  module GitProc
14
14
  module Version
15
15
  MAJOR = 1
16
16
  MINOR = 0
17
- PATCH = 4
17
+ PATCH = 5
18
18
  BUILD = nil
19
19
 
20
20
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
data/spec/FileHelpers.rb CHANGED
@@ -4,6 +4,7 @@ include FileUtils
4
4
  module FileHelpers
5
5
  TEST_DIR = File.dirname(__FILE__)
6
6
 
7
+
7
8
  def dir_files(dir)
8
9
  Dir.entries(dir).grep(/^[^.]/)
9
10
  end
@@ -34,7 +34,7 @@ module GitRepoHelper
34
34
  def create_files(file_names)
35
35
  Dir.chdir(gitprocess.workdir) do |dir|
36
36
  file_names.each do |fn|
37
- gitprocess.logger.debug {"Creating #{dir}/#{fn}"}
37
+ gitprocess.logger.debug { "Creating #{dir}/#{fn}" }
38
38
  FileUtils.touch fn
39
39
  end
40
40
  end
@@ -44,7 +44,7 @@ module GitRepoHelper
44
44
 
45
45
  def change_file(filename, contents, lib = gitprocess)
46
46
  Dir.chdir(lib.workdir) do
47
- File.open(filename, 'w') {|f| f.puts contents}
47
+ File.open(filename, 'w') { |f| f.puts contents }
48
48
  end
49
49
  end
50
50
 
@@ -69,7 +69,7 @@ module GitRepoHelper
69
69
  def clone(branch='master', remote_name = 'origin', &block)
70
70
  td = Dir.mktmpdir
71
71
 
72
- logger.debug {"Cloning '#{tmpdir}' to '#{td}'"}
72
+ logger.debug { "Cloning '#{tmpdir}' to '#{td}'" }
73
73
 
74
74
  opts = {}
75
75
  opts[:quiet] = true if log_level == Logger::ERROR
@@ -20,7 +20,7 @@ describe GitProc::ChangeFileHelper do
20
20
  include GitRepoHelper
21
21
 
22
22
  before(:each) do
23
- create_files(['.gitignore'])
23
+ create_files(%w(.gitignore))
24
24
  gitprocess.commit('initial')
25
25
  end
26
26
 
@@ -52,7 +52,7 @@ describe GitProc::ChangeFileHelper do
52
52
 
53
53
  gp.merge('origin/master') rescue ''
54
54
 
55
- expect {gp.offer_to_help_uncommitted_changes}.should raise_error GitProc::UncommittedChangesError
55
+ expect { gp.offer_to_help_uncommitted_changes }.should raise_error GitProc::UncommittedChangesError
56
56
  end
57
57
 
58
58
 
@@ -52,13 +52,14 @@ describe GitProc::AbstractMergeErrorBuilder do
52
52
 
53
53
  builder.resolved_files.should == []
54
54
  builder.unresolved_files.should == ['a', 'b c']
55
- match_commands [
56
- 'git config --global rerere.enabled true',
57
- 'git mergetool a b\ c',
58
- '# Verify \'a\' merged correctly.',
59
- '# Verify \'b c\' merged correctly.',
60
- 'git add a b\ c',
55
+ c = [
56
+ 'git config --global rerere.enabled true',
57
+ 'git mergetool a b\ c',
58
+ '# Verify \'a\' merged correctly.',
59
+ '# Verify \'b c\' merged correctly.',
60
+ 'git add a b\ c',
61
61
  ]
62
+ match_commands c
62
63
  end
63
64
 
64
65
 
@@ -67,14 +68,15 @@ describe GitProc::AbstractMergeErrorBuilder do
67
68
  status.stub(:modified).and_return(['a', 'b c'])
68
69
  builder.stub(:error_message).and_return("\nResolved 'a' using previous resolution.\n")
69
70
 
70
- builder.resolved_files.should == ['a']
71
+ builder.resolved_files.should == %w(a)
71
72
  builder.unresolved_files.should == ['b c']
72
- match_commands [
73
- '# Verify that \'rerere\' did the right thing for \'a\'.',
74
- 'git mergetool b\ c',
75
- '# Verify \'b c\' merged correctly.',
76
- 'git add b\ c',
73
+ c = [
74
+ '# Verify that \'rerere\' did the right thing for \'a\'.',
75
+ 'git mergetool b\ c',
76
+ '# Verify \'b c\' merged correctly.',
77
+ 'git add b\ c',
77
78
  ]
79
+ match_commands c
78
80
  end
79
81
 
80
82
 
@@ -84,30 +86,32 @@ describe GitProc::AbstractMergeErrorBuilder do
84
86
  status.stub(:modified).and_return(['a', 'b c'])
85
87
  builder.stub(:error_message).and_return("\nResolved 'a' using previous resolution.\n")
86
88
 
87
- builder.resolved_files.should == ['a']
89
+ builder.resolved_files.should == %w(a)
88
90
  builder.unresolved_files.should == ['b c']
89
- match_commands [
90
- '# Verify that \'rerere\' did the right thing for \'a\'.',
91
- 'git add a',
92
- 'git mergetool b\ c',
93
- '# Verify \'b c\' merged correctly.',
94
- 'git add b\ c',
91
+ c = [
92
+ '# Verify that \'rerere\' did the right thing for \'a\'.',
93
+ 'git add a',
94
+ 'git mergetool b\ c',
95
+ '# Verify \'b c\' merged correctly.',
96
+ 'git add b\ c',
95
97
  ]
98
+ match_commands c
96
99
  end
97
100
 
98
101
 
99
102
  it "merged with a file added in both branches" do
100
103
  lib.stub(:rerere_autoupdate?).and_return(false)
101
- status.stub(:unmerged).and_return(['a'])
102
- status.stub(:modified).and_return(['b'])
103
- status.stub(:added).and_return(['a', 'c'])
104
-
105
- builder.resolved_files.should == []
106
- builder.unresolved_files.should == ['a']
107
- match_commands [
108
- '# \'a\' was added in both branches; Fix the conflict.',
109
- 'git add a',
104
+ status.stub(:unmerged).and_return(%w(a))
105
+ status.stub(:modified).and_return(%w(b))
106
+ status.stub(:added).and_return(%w(a c))
107
+
108
+ builder.resolved_files.should == %w()
109
+ builder.unresolved_files.should == %w(a)
110
+ c = [
111
+ '# \'a\' was added in both branches; Fix the conflict.',
112
+ 'git add a',
110
113
  ]
114
+ match_commands c
111
115
  end
112
116
 
113
117
  end