gitx 2.21.3 → 2.21.4.ci.145.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 55c4613b3110f7334a5a2b4db2089b1847c26ad8
4
- data.tar.gz: a2f450ee343e9eb85974c24611e13739085e2c47
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NmZmMzE3ZGYxNzI4YTQ4NzVjMmFmNGM1YjEyY2UxZDE5ZTBiMDY0OQ==
5
+ data.tar.gz: !binary |-
6
+ MmQ5YzNlMWYxZjZjYjU0NmY0MTJiYjZlMTIxZDZlMjA0NDY1MWQ0OQ==
5
7
  SHA512:
6
- metadata.gz: 0e60cb3c0c2f34c1fe553326c6bc490621753dfc8558e331a1e486478e891a6e3b01b9aee11215c87de89564e41af7c2a93395a9675fba71b6e40a39e56c9691
7
- data.tar.gz: 3aa2adf8efe47a7da168aaefc92baa1406a7af55a8c20d16af624f540592624314808d5d8ce4ee24356275ff2112218cad38bdab6263c00930003d62c643055a
8
+ metadata.gz: !binary |-
9
+ YzVlZTNlYjAwMjRkYzI1Nzc1Y2Y2NTczM2ZjZWM2ODg2NjE3MWQ4NjBlNzdm
10
+ MGUyMjIwZDg1MzZhNGFlZjgzOWYyNmE1MTRhZjgxMjIxNDEzMGIzNDQxODA3
11
+ YTI5MmZkZDg0MDFkNmZkNzk3OWY3MzJlMmUzOWMyMjE1YWMzZWE=
12
+ data.tar.gz: !binary |-
13
+ ZjVlMGVkNDczMWI5NTBjYTllNGRiZGE2MjRjZjY3Y2Q4ODU0NWM5YmJjY2Vm
14
+ ZTYxZDhiMWRkMjUyOGNjOGZhMTVkOTI1YWU3MmUwZGU2YmVjZDVjNzY2N2Vi
15
+ Njk5YTMwMTYyM2ExZDRhNzc4ZDUzYzM2MzA2ODhlNzg2ZmRmMDU=
data/README.md CHANGED
@@ -15,10 +15,6 @@ so they are available without learning any new commands!
15
15
  $ gem install gitx
16
16
  ```
17
17
 
18
- ### Global Options
19
- * `--trace` or `-v` = verbose output for debugging commands
20
- * `--pretend` or `-p` = dry run commands and do not actually invoke operations
21
-
22
18
  ## git start <new_branch_name (optional)>
23
19
 
24
20
  update local repository with latest upstream changes and create a new feature branch
@@ -2,6 +2,7 @@ require 'thor'
2
2
  require 'pathname'
3
3
  require 'rugged'
4
4
  require 'gitx'
5
+ require 'gitx/executor'
5
6
 
6
7
  module Gitx
7
8
  module Cli
@@ -12,11 +13,6 @@ module Gitx
12
13
 
13
14
  add_runtime_options!
14
15
 
15
- method_option :trace, type: :boolean, aliases: '-v'
16
- def initialize(*args)
17
- super(*args)
18
- end
19
-
20
16
  private
21
17
 
22
18
  def repo
@@ -26,12 +22,18 @@ module Gitx
26
22
  end
27
23
  end
28
24
 
25
+ def run_cmd(*cmd)
26
+ executor.execute(*cmd) do |output|
27
+ say(output, :yellow)
28
+ end
29
+ end
30
+
29
31
  def run_git_cmd(*cmd)
30
32
  run_cmd('git', *cmd)
31
33
  end
32
34
 
33
35
  def checkout_branch(branch_name)
34
- run_cmd "git checkout #{branch_name}"
36
+ run_git_cmd 'checkout', branch_name
35
37
  end
36
38
 
37
39
  # lookup the current branch of the repo
@@ -47,14 +49,13 @@ module Gitx
47
49
  fail "Cannot #{action} reserved branch" if config.reserved_branch?(branch) || config.aggregate_branch?(branch)
48
50
  end
49
51
 
50
- # helper to invoke other CLI commands
51
- def execute_command(command_class, method, args = [])
52
- command_class.new.send(method, *args)
53
- end
54
-
55
52
  def config
56
53
  @configuration ||= Gitx::Configuration.new(repo.workdir)
57
54
  end
55
+
56
+ def executor
57
+ @executor ||= Gitx::Executor.new
58
+ end
58
59
  end
59
60
  end
60
61
  end
@@ -10,8 +10,8 @@ module Gitx
10
10
  method_option :message, type: :string, aliases: '-m', desc: 'message to attach to the buildtag'
11
11
  def buildtag
12
12
  fail "Branch must be one of the supported taggable branches: #{config.taggable_branches}" unless config.taggable_branch?(branch_name)
13
- run_cmd "git tag #{git_tag} -a -m '#{label}'"
14
- run_cmd "git push origin #{git_tag}"
13
+ run_git_cmd 'tag', git_tag, '--annotate', '--message', label
14
+ run_git_cmd 'push', 'origin', git_tag
15
15
  end
16
16
 
17
17
  private
@@ -8,16 +8,16 @@ module Gitx
8
8
  desc 'cleanup', 'Cleanup branches that have been merged into master from the repo'
9
9
  def cleanup
10
10
  checkout_branch config.base_branch
11
- run_cmd 'git pull'
12
- run_cmd 'git remote prune origin'
11
+ run_git_cmd 'pull'
12
+ run_git_cmd 'remote', 'prune', 'origin'
13
13
 
14
14
  say 'Deleting local and remote branches that have been merged into '
15
15
  say config.base_branch, :green
16
16
  merged_branches(remote: true).each do |branch|
17
- run_cmd "git push origin --delete #{branch}"
17
+ run_git_cmd 'push', 'origin', '--delete', branch
18
18
  end
19
19
  merged_branches(remote: false).each do |branch|
20
- run_cmd "git branch -d #{branch}"
20
+ run_git_cmd 'branch', '--delete', branch
21
21
  end
22
22
  end
23
23
 
@@ -26,9 +26,9 @@ module Gitx
26
26
  # @return list of branches that have been merged
27
27
  def merged_branches(options = {})
28
28
  args = []
29
- args << '-r' if options[:remote]
29
+ args << '--remote' if options[:remote]
30
30
  args << '--merged'
31
- output = run_cmd("git branch #{args.join(' ')}").split("\n")
31
+ output = run_git_cmd('branch', *args).split("\n")
32
32
  branches = output.map do |branch|
33
33
  branch = branch.gsub(/\*/, '').strip.split(' ').first
34
34
  branch = branch.split('/').last if options[:remote]
@@ -16,12 +16,7 @@ module Gitx
16
16
  branch = feature_branch_name
17
17
  print_message(branch, integration_branch)
18
18
 
19
- begin
20
- execute_command(UpdateCommand, :update)
21
- rescue
22
- raise MergeError, 'Merge conflict occurred. Please fix merge conflict and rerun the integrate command'
23
- end
24
-
19
+ run_git_cmd 'update'
25
20
  pull_request = pull_request_for_branch(branch)
26
21
  integrate_branch(branch, integration_branch, pull_request) unless options[:resume]
27
22
  checkout_branch branch
@@ -47,11 +42,11 @@ module Gitx
47
42
  commit_message = "[gitx] Integrating #{branch} into #{integration_branch}"
48
43
  commit_message += " (Pull request ##{pull_request.number})" if pull_request
49
44
  begin
50
- run_cmd %Q(git merge --no-ff -m "#{commit_message}" #{branch})
45
+ run_git_cmd 'merge', '--no-ff', '--message', commit_message, branch
51
46
  rescue
52
47
  raise MergeError, "Merge conflict occurred. Please fix merge conflict and rerun command with --resume #{branch} flag"
53
48
  end
54
- run_cmd 'git push origin HEAD'
49
+ run_git_cmd 'push', 'origin', 'HEAD'
55
50
  end
56
51
 
57
52
  def feature_branch_name
@@ -67,8 +62,8 @@ module Gitx
67
62
  # nuke local branch and pull fresh version from remote repo
68
63
  def fetch_remote_branch(target_branch)
69
64
  create_remote_branch(target_branch) unless remote_branch_exists?(target_branch)
70
- run_cmd 'git fetch origin'
71
- run_cmd "git branch -D #{target_branch}", allow_failure: true
65
+ run_git_cmd 'fetch', 'origin'
66
+ run_git_cmd('branch', '--delete', '--force', target_branch) rescue Gitx::Executor::ExecutionError
72
67
  checkout_branch target_branch
73
68
  end
74
69
 
@@ -86,7 +81,7 @@ module Gitx
86
81
 
87
82
  def create_remote_branch(target_branch)
88
83
  repo.create_branch(target_branch, config.base_branch)
89
- run_cmd "git push origin #{target_branch}:#{target_branch}"
84
+ run_git_cmd 'push', 'origin', "#{target_branch}:#{target_branch}"
90
85
  end
91
86
  end
92
87
  end
@@ -22,11 +22,10 @@ module Gitx
22
22
  say last_known_good_tag, :green
23
23
 
24
24
  checkout_branch config.base_branch
25
- run_cmd "git branch -D #{bad_branch}", allow_failure: true
26
- run_cmd "git push origin --delete #{bad_branch}", allow_failure: true
27
- run_cmd "git checkout -b #{bad_branch} #{last_known_good_tag}"
28
- run_cmd "git push origin #{bad_branch}"
29
- run_cmd "git branch --set-upstream-to origin/#{bad_branch}"
25
+ run_git_cmd('branch', '--delete', '--force', bad_branch) rescue Gitx::Executor::ExecutionError
26
+ run_git_cmd('push', 'origin', '--delete', bad_branch) rescue Gitx::Executor::ExecutionError
27
+ run_git_cmd 'checkout', '-b', bad_branch, last_known_good_tag
28
+ run_git_cmd 'share'
30
29
  checkout_branch config.base_branch
31
30
  end
32
31
 
@@ -34,7 +33,7 @@ module Gitx
34
33
 
35
34
  def migrations_need_to_be_reverted?(bad_branch, last_known_good_tag)
36
35
  return false unless File.exist?('db/migrate')
37
- outdated_migrations = run_cmd("git diff #{last_known_good_tag}...#{bad_branch} --name-only db/migrate").split
36
+ outdated_migrations = run_git_cmd('diff', "#{last_known_good_tag}...#{bad_branch}", '--name-only', 'db/migrate').split
38
37
  return false if outdated_migrations.empty?
39
38
 
40
39
  say "#{bad_branch} contains migrations that may need to be reverted. Ensure any reversable migrations are reverted on affected databases before nuking.", :red
@@ -53,8 +52,8 @@ module Gitx
53
52
  end
54
53
 
55
54
  def build_tags_for_branch(branch)
56
- run_cmd 'git fetch --tags'
57
- build_tags = run_cmd("git tag -l 'build-#{branch}-*'").split
55
+ run_git_cmd 'fetch', '--tags'
56
+ build_tags = run_git_cmd('tag', '--list', "build-#{branch}-*").split
58
57
  build_tags.sort
59
58
  end
60
59
  end
@@ -1,7 +1,6 @@
1
1
  require 'thor'
2
2
  require 'gitx'
3
3
  require 'gitx/cli/base_command'
4
- require 'gitx/cli/update_command'
5
4
  require 'gitx/github'
6
5
 
7
6
  module Gitx
@@ -17,15 +16,15 @@ module Gitx
17
16
  branch ||= current_branch.name
18
17
  assert_not_protected_branch!(branch, 'release')
19
18
  checkout_branch(branch)
20
- execute_command(UpdateCommand, :update)
19
+ run_git_cmd 'update'
21
20
 
22
21
  pull_request = find_or_create_pull_request(branch)
23
22
  return unless confirm_branch_status?(branch)
24
23
 
25
24
  checkout_branch config.base_branch
26
- run_cmd "git pull origin #{config.base_branch}"
27
- run_cmd %Q(git merge --no-ff -m "[gitx] Releasing #{branch} to #{config.base_branch} (Pull request ##{pull_request.number})" #{branch})
28
- run_cmd 'git push origin HEAD'
25
+ run_git_cmd 'pull', 'origin', config.base_branch
26
+ run_git_cmd 'merge', '--no-ff', '--message', "[gitx] Releasing #{branch} to #{config.base_branch} (Pull request ##{pull_request.number})", branch
27
+ run_git_cmd 'push', 'origin', 'HEAD'
29
28
 
30
29
  after_release
31
30
  end
@@ -50,7 +50,7 @@ module Gitx
50
50
  reject_pull_request(pull_request) if options[:reject]
51
51
  assign_pull_request(pull_request) if options[:assignee]
52
52
 
53
- run_cmd "open #{pull_request.html_url}" if options[:open]
53
+ run_cmd('open', pull_request.html_url) if options[:open]
54
54
  end
55
55
 
56
56
  private
@@ -7,8 +7,8 @@ module Gitx
7
7
  class ShareCommand < BaseCommand
8
8
  desc 'share', 'Share the current branch in the remote repository'
9
9
  def share
10
- run_cmd "git push origin #{current_branch.name}"
11
- run_cmd "git branch --set-upstream-to origin/#{current_branch.name}"
10
+ run_git_cmd 'push', 'origin', current_branch.name
11
+ run_git_cmd 'track'
12
12
  end
13
13
  end
14
14
  end
@@ -7,7 +7,7 @@ module Gitx
7
7
  class TrackCommand < BaseCommand
8
8
  desc 'track', 'set the current branch to track the remote branch with the same name'
9
9
  def track
10
- run_cmd "git branch --set-upstream-to origin/#{current_branch.name}"
10
+ run_git_cmd 'branch', '--set-upstream-to', "origin/#{current_branch.name}"
11
11
  end
12
12
  end
13
13
  end
@@ -14,15 +14,15 @@ module Gitx
14
14
 
15
15
  update_branch(current_branch.name) if remote_branch_exists?(current_branch.name)
16
16
  update_branch(config.base_branch)
17
- run_cmd 'git push origin HEAD'
17
+ run_git_cmd 'share'
18
18
  end
19
19
 
20
20
  private
21
21
 
22
22
  def update_branch(branch)
23
- run_cmd "git pull origin #{branch}"
23
+ run_git_cmd 'pull', 'origin', branch
24
24
  rescue
25
- raise MergeError, 'Merge Conflict Occurred. Please fix merge conflict and rerun the update command'
25
+ raise MergeError, 'Merge conflict occurred. Please fix merge conflict and rerun the command'
26
26
  end
27
27
 
28
28
  def remote_branch_exists?(branch)
@@ -0,0 +1,26 @@
1
+ require 'open3'
2
+
3
+ module Gitx
4
+ class Executor
5
+ ExecutionError = Class.new(StandardError)
6
+
7
+ # execute a shell command and raise an error if non-zero exit code is returned
8
+ # return the string output from the command
9
+ # block argument is passed all output from the executed thread
10
+ def execute(*cmd)
11
+ yield "$ #{cmd.join(' ')}" if block_given?
12
+ output = ''
13
+
14
+ Open3.popen2e(*cmd) do |stdin, stdout_err, wait_thread|
15
+ while line = stdout_err.gets
16
+ output << line
17
+ yield line if block_given?
18
+ end
19
+
20
+ exit_status = wait_thread.value
21
+ fail ExecutionError, "#{cmd.join(' ')} failed" unless exit_status.success?
22
+ end
23
+ output
24
+ end
25
+ end
26
+ end
@@ -1,27 +1,5 @@
1
- require 'open3'
2
-
3
1
  class Thor
4
2
  module Actions
5
- # execute a shell command and raise an error if non-zero exit code is returned
6
- # return the string output from the command
7
- def run_cmd(*args)
8
- options = args.last.is_a?(Hash) ? args.pop : {}
9
- cmd = args
10
- say "$ #{cmd.join(' ')}", :yellow
11
- output = ''
12
-
13
- Open3.popen2e(*cmd) do |stdin, stdout_err, wait_thr|
14
- while line = stdout_err.gets
15
- say(line, :yellow) if options[:trace]
16
- output << line
17
- end
18
-
19
- exit_status = wait_thr.value
20
- fail "#{cmd.join(' ')} failed" unless exit_status.success? || options[:allow_failure]
21
- end
22
- output
23
- end
24
-
25
3
  # launch configured editor to retreive message/string
26
4
  # see http://osdir.com/ml/ruby-talk/2010-06/msg01424.html
27
5
  # see https://gist.github.com/rkumar/456809
data/lib/gitx/github.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  require 'octokit'
2
2
  require 'fileutils'
3
3
  require 'yaml'
4
- require 'gitx/cli/update_command'
5
4
 
6
5
  module Gitx
7
6
  module Github
@@ -23,7 +22,7 @@ module Gitx
23
22
  pull_request = find_pull_request(branch)
24
23
  pull_request ||= begin
25
24
  checkout_branch(branch)
26
- execute_command(Gitx::Cli::UpdateCommand, :update)
25
+ run_git_cmd 'update'
27
26
  pull_request = create_pull_request(branch)
28
27
  say 'Created pull request: '
29
28
  say pull_request.html_url, :green
@@ -73,7 +72,7 @@ module Gitx
73
72
  end
74
73
 
75
74
  def pull_request_body(branch)
76
- changelog = run_cmd("git log #{config.base_branch}...#{branch} --reverse --no-merges --pretty=format:'* %B'")
75
+ changelog = run_git_cmd('log', "#{config.base_branch}...#{branch}", '--reverse', '--no-merges', "--pretty=format:'* %B'")
77
76
  description = options[:description]
78
77
 
79
78
  description_template = []
data/lib/gitx/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Gitx
2
- VERSION = '2.21.3'
2
+ VERSION = '2.21.4'
3
3
  end
@@ -10,6 +10,7 @@ describe Gitx::Cli::BuildtagCommand do
10
10
  }
11
11
  end
12
12
  let(:cli) { described_class.new(args, options, config) }
13
+ let(:executor) { cli.send(:executor) }
13
14
  let(:branch) { double('fake branch', name: 'feature-branch') }
14
15
 
15
16
  before do
@@ -40,8 +41,8 @@ describe Gitx::Cli::BuildtagCommand do
40
41
  end
41
42
  before do
42
43
  Timecop.freeze(Time.utc(2013, 10, 30, 10, 21, 28)) do
43
- expect(cli).to receive(:run_cmd).with("git tag build-master-2013-10-30-10-21-28 -a -m '[gitx] buildtag for master'").ordered
44
- expect(cli).to receive(:run_cmd).with('git push origin build-master-2013-10-30-10-21-28').ordered
44
+ expect(executor).to receive(:execute).with('git', 'tag', 'build-master-2013-10-30-10-21-28', '--annotate', '--message', '[gitx] buildtag for master').ordered
45
+ expect(executor).to receive(:execute).with('git', 'push', 'origin', 'build-master-2013-10-30-10-21-28').ordered
45
46
  cli.buildtag
46
47
  end
47
48
  end
@@ -58,8 +59,8 @@ describe Gitx::Cli::BuildtagCommand do
58
59
  end
59
60
  before do
60
61
  Timecop.freeze(Time.utc(2013, 10, 30, 10, 21, 28)) do
61
- expect(cli).to receive(:run_cmd).with("git tag build-master-2013-10-30-10-21-28 -a -m 'custom git commit message'").ordered
62
- expect(cli).to receive(:run_cmd).with('git push origin build-master-2013-10-30-10-21-28').ordered
62
+ expect(executor).to receive(:execute).with('git', 'tag', 'build-master-2013-10-30-10-21-28', '--annotate', '--message', 'custom git commit message').ordered
63
+ expect(executor).to receive(:execute).with('git', 'push', 'origin', 'build-master-2013-10-30-10-21-28').ordered
63
64
  cli.buildtag
64
65
  end
65
66
  end
@@ -9,8 +9,11 @@ describe Gitx::Cli::CleanupCommand do
9
9
  pretend: true
10
10
  }
11
11
  end
12
- let(:cli) { Gitx::Cli::CleanupCommand.new(args, options, config) }
12
+ let(:cli) { described_class.new(args, options, config) }
13
+ let(:executor) { cli.send(:executor) }
13
14
  let(:branch) { double('fake branch', name: 'feature-branch') }
15
+ let(:remote_branches) { 'merged-remote-feature' }
16
+ let(:local_branches) { 'merged-local-feature' }
14
17
 
15
18
  before do
16
19
  allow(cli).to receive(:current_branch).and_return(branch)
@@ -20,13 +23,13 @@ describe Gitx::Cli::CleanupCommand do
20
23
  before do
21
24
  allow(cli).to receive(:say)
22
25
 
23
- expect(cli).to receive(:run_cmd).with('git checkout master').ordered
24
- expect(cli).to receive(:run_cmd).with('git pull').ordered
25
- expect(cli).to receive(:run_cmd).with('git remote prune origin').ordered
26
- expect(cli).to receive(:run_cmd).with('git branch -r --merged').and_return('merged-remote-feature').ordered
27
- expect(cli).to receive(:run_cmd).with('git push origin --delete merged-remote-feature').ordered
28
- expect(cli).to receive(:run_cmd).with('git branch --merged').and_return('merged-local-feature').ordered
29
- expect(cli).to receive(:run_cmd).with('git branch -d merged-local-feature').ordered
26
+ expect(executor).to receive(:execute).with('git', 'checkout', 'master').ordered
27
+ expect(executor).to receive(:execute).with('git', 'pull').ordered
28
+ expect(executor).to receive(:execute).with('git', 'remote', 'prune', 'origin').ordered
29
+ expect(executor).to receive(:execute).with('git', 'branch', '--remote', '--merged').and_return(remote_branches).ordered
30
+ expect(executor).to receive(:execute).with('git', 'push', 'origin', '--delete', 'merged-remote-feature').ordered
31
+ expect(executor).to receive(:execute).with('git', 'branch', '--merged').and_return(local_branches).ordered
32
+ expect(executor).to receive(:execute).with('git', 'branch', '--delete', 'merged-local-feature').ordered
30
33
 
31
34
  cli.cleanup
32
35
  end