rlt 0.1.5 → 0.1.6
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.
- checksums.yaml +5 -5
- data/exe/rlt +12 -2
- data/lib/rlt/cli.rb +43 -0
- data/lib/rlt/commands/close.rb +94 -0
- data/lib/rlt/commands/{cmt_command.rb → cmt.rb} +12 -38
- data/lib/rlt/commands/switch.rb +57 -0
- data/lib/rlt/config.rb +8 -8
- data/lib/rlt/debug.rb +7 -0
- data/lib/rlt/error.rb +6 -0
- data/lib/rlt/utils/colored_text.rb +29 -0
- data/lib/rlt/utils/git_util.rb +113 -0
- data/lib/rlt/utils/logger.rb +29 -0
- data/lib/rlt/utils/shell.rb +39 -0
- data/lib/rlt/utils/string_util.rb +19 -0
- data/lib/rlt/version.rb +1 -1
- data/lib/rlt.rb +8 -20
- metadata +36 -35
- data/.gitignore +0 -13
- data/.rlt.sample.yml +0 -27
- data/.rspec +0 -3
- data/.rubocop.yml +0 -9
- data/.ruby-version +0 -1
- data/.travis.yml +0 -5
- data/CODE_OF_CONDUCT.md +0 -74
- data/Gemfile +0 -8
- data/Gemfile.lock +0 -78
- data/LICENSE.txt +0 -21
- data/README.md +0 -142
- data/Rakefile +0 -8
- data/bin/console +0 -15
- data/bin/setup +0 -8
- data/lib/rlt/base_command.rb +0 -17
- data/lib/rlt/colored_text.rb +0 -27
- data/lib/rlt/command_runner.rb +0 -37
- data/lib/rlt/commands/switch_command.rb +0 -78
- data/lib/rlt/commands_map.rb +0 -37
- data/lib/rlt/git_native_command_builder.rb +0 -25
- data/lib/rlt/logger.rb +0 -27
- data/lib/rlt/register_aliases.rb +0 -14
- data/lib/rlt/register_commands.rb +0 -25
- data/lib/rlt/shell.rb +0 -23
- data/releases/rlt-0.1.0.tar.gz +0 -0
- data/rlt.gemspec +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e8103d3ed650fed8f99f8e0c57f5515c66849626
|
4
|
+
data.tar.gz: 65012e4e9b016e389e82b9db9206cd4b952f0766
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88122ab1296aba40b00b3469883d1dbe8025db9031fd44cd43934d924e3da7951de0486e9b7030192a2214d3b24c70ea9984627f264d214a9039d7a27417832f
|
7
|
+
data.tar.gz: 98adfc71e188bf936dc9887ea61bf951fb0b6047a5447f20aaa1d7486d71b5f046a0a427bc166853940441d63f6bca492da75f8708175bdab8912c44a0309c31
|
data/exe/rlt
CHANGED
@@ -2,8 +2,18 @@
|
|
2
2
|
|
3
3
|
# frozen_string_literal: true
|
4
4
|
|
5
|
-
$LOAD_PATH
|
5
|
+
$LOAD_PATH << File.expand_path('lib', __dir__)
|
6
6
|
|
7
7
|
require 'rlt'
|
8
8
|
|
9
|
-
|
9
|
+
begin
|
10
|
+
Rlt::CLI.start(ARGV)
|
11
|
+
rescue TTY::Reader::InputInterrupt
|
12
|
+
puts ''
|
13
|
+
# ignore
|
14
|
+
rescue TTY::Command::ExitError
|
15
|
+
puts ''
|
16
|
+
# ignore
|
17
|
+
rescue Rlt::GitNativeCommandError
|
18
|
+
Rlt::Utils::GitUtil.execute_native_command(ARGV)
|
19
|
+
end
|
data/lib/rlt/cli.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
require 'rlt/commands/cmt'
|
5
|
+
require 'rlt/commands/switch'
|
6
|
+
require 'rlt/commands/close'
|
7
|
+
|
8
|
+
module Rlt
|
9
|
+
class CLI < Thor
|
10
|
+
def self.handle_no_command_error(command)
|
11
|
+
raise GitNativeCommandError if Utils::GitUtil::NATIVE_COMMANDS.include? command
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.command_name(klass)
|
16
|
+
Utils::StringUtil.underscore(klass.name.split('::').last)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.run(klass, *arguments)
|
20
|
+
config = Rlt.config('command', command_name(klass))
|
21
|
+
klass.send(:run, config, *arguments)
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'cmt', 'Commit with structured commit message'
|
25
|
+
method_option :add_all,
|
26
|
+
aliases: '-a',
|
27
|
+
desc: 'Add all before commit',
|
28
|
+
type: :boolean, default: false
|
29
|
+
def cmt
|
30
|
+
CLI.run Rlt::Commands::Cmt, options.add_all?
|
31
|
+
end
|
32
|
+
|
33
|
+
desc 'switch <branch_name>', 'Switch branches with auto stash/unstash'
|
34
|
+
def switch(branch_name)
|
35
|
+
CLI.run Rlt::Commands::Switch, branch_name
|
36
|
+
end
|
37
|
+
|
38
|
+
desc 'close', 'Delete current branch and merge it to master'
|
39
|
+
def close
|
40
|
+
CLI.run Rlt::Commands::Close
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rlt
|
4
|
+
module Commands
|
5
|
+
class Close
|
6
|
+
def self.run(config)
|
7
|
+
master_branch = master_branch(config)
|
8
|
+
current_branch_name = Utils::GitUtil.current_branch_name
|
9
|
+
return if should_stop?(master_branch, config)
|
10
|
+
run_internal(current_branch_name, master_branch)
|
11
|
+
Utils::Logger.info "Done closing `#{current_branch_name}`."
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.run_internal(current_branch_name, master_branch)
|
15
|
+
merge_back_and_forth(current_branch_name, master_branch)
|
16
|
+
delete_branch(current_branch_name)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.should_stop?(master_branch, config)
|
20
|
+
return true if uncommitted_changes?
|
21
|
+
return true if config_not_existing?(config)
|
22
|
+
return true if master_branch_now?(master_branch)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.uncommitted_changes?
|
26
|
+
result = Utils::GitUtil.uncommitted_change?
|
27
|
+
print_uncommitted_changes_error if result
|
28
|
+
result
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.config_not_existing?(config)
|
32
|
+
result = config['master_branch'].nil?
|
33
|
+
print_explicit_config_error if result
|
34
|
+
result
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.master_branch_now?(master_branch)
|
38
|
+
result = Utils::GitUtil.current_branch_name == master_branch
|
39
|
+
print_master_branch_now_error(master_branch) if result
|
40
|
+
result
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.master_branch(config)
|
44
|
+
config['master_branch']
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.merge_back_and_forth(current_branch_name, master_branch)
|
48
|
+
Utils::GitUtil.merge_from(master_branch, print_info: true)
|
49
|
+
return if any_conflict?
|
50
|
+
Utils::GitUtil.checkout(master_branch, print_info: true)
|
51
|
+
Utils::GitUtil.merge_from(current_branch_name, print_info: true)
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.any_conflict?
|
55
|
+
result = Utils::GitUtil.any_conflict?
|
56
|
+
print_conflict_error if result
|
57
|
+
result
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.print_uncommitted_changes_error
|
61
|
+
Utils::Logger.error 'There are uncommitted changes.'
|
62
|
+
Utils::Logger.error 'Commit them first!'
|
63
|
+
end
|
64
|
+
|
65
|
+
# rubocop:disable Metrics/MethodLength
|
66
|
+
def self.print_explicit_config_error
|
67
|
+
Utils::Logger.error 'You must explicitly configure name of master branch at `.rlt.yml`'
|
68
|
+
Utils::Logger.error 'For example,'
|
69
|
+
Utils::Logger.error ''
|
70
|
+
Utils::Logger.error '# .rlt.yml'
|
71
|
+
Utils::Logger.error 'command:'
|
72
|
+
Utils::Logger.error ' close:'
|
73
|
+
Utils::Logger.error ' master_branch: master'
|
74
|
+
end
|
75
|
+
# rubocop:enable Metrics/MethodLength
|
76
|
+
|
77
|
+
def self.print_master_branch_now_error(master_branch)
|
78
|
+
Utils::Logger.error "You cannot close `#{master_branch}`."
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.print_conflict_error
|
82
|
+
Utils::Logger.error 'Aborting the process due to the conflict.'
|
83
|
+
Utils::Logger.error 'Resolve them first, and try it again.'
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.delete_branch(current_branch_name)
|
87
|
+
Utils::GitUtil.delete_branch(current_branch_name, print_info: true)
|
88
|
+
Utils::GitUtil.remotes.each do |remote|
|
89
|
+
Utils::GitUtil.safely_delete_remote_branch(remote, current_branch_name, print_info: true)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -6,22 +6,18 @@ require 'tmpdir'
|
|
6
6
|
|
7
7
|
module Rlt
|
8
8
|
module Commands
|
9
|
-
class
|
10
|
-
CONF_SUBJECT_TEMPLATE = 'subject_template'
|
11
|
-
CONF_BODY_TEMPLATE = 'body_template'
|
9
|
+
class Cmt
|
10
|
+
CONF_SUBJECT_TEMPLATE = 'subject_template'
|
11
|
+
CONF_BODY_TEMPLATE = 'body_template'
|
12
12
|
|
13
|
-
def self.run(config,
|
14
|
-
branch_name =
|
15
|
-
|
13
|
+
def self.run(config, add_all)
|
14
|
+
branch_name = Utils::GitUtil.current_branch_name
|
15
|
+
Utils::Logger.info "Committing to '#{branch_name}'"
|
16
16
|
(subject, body) = subject_and_body(config, branch_name)
|
17
|
-
add_all if
|
17
|
+
Utils::GitUtil.add_all if add_all
|
18
18
|
commit(subject, body)
|
19
19
|
end
|
20
20
|
|
21
|
-
def self.add_all
|
22
|
-
Shell.new.run 'git', 'add', '.'
|
23
|
-
end
|
24
|
-
|
25
21
|
def self.subject_and_body(config, branch_name)
|
26
22
|
subject = adjust_subject_template(ask_subject, config, branch_name)
|
27
23
|
body = adjust_body_template(ask_body, config, branch_name)
|
@@ -29,27 +25,20 @@ module Rlt
|
|
29
25
|
end
|
30
26
|
|
31
27
|
def self.commit(subject, body)
|
32
|
-
|
33
|
-
File.write(commit_msg_file_path, "#{subject}\n\n#{body}".strip)
|
34
|
-
Shell.new.run 'git', 'commit', '-F', commit_msg_file_path
|
35
|
-
File.delete(commit_msg_file_path)
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.short_random_string
|
39
|
-
(0...4).map { rand(65..90).chr }.join
|
28
|
+
Utils::GitUtil.commit_with_long_message("#{subject}\n\n#{body}".strip)
|
40
29
|
end
|
41
30
|
|
42
31
|
def self.ask_subject
|
43
32
|
prompt = TTY::Prompt.new
|
44
|
-
prompt.ask('Subject:', active_color: :
|
33
|
+
prompt.ask('Subject:', active_color: :magenta) do |q|
|
45
34
|
q.required true
|
46
35
|
q.modify :capitalize
|
47
|
-
end
|
36
|
+
end.gsub(/\.$/, '')
|
48
37
|
end
|
49
38
|
|
50
39
|
def self.ask_body
|
51
|
-
puts 'Body:
|
52
|
-
lines = ask_multiline_until_done('>', :
|
40
|
+
puts 'Body: (Insert empty line to finish)'
|
41
|
+
lines = ask_multiline_until_done('>', :magenta)
|
53
42
|
lines.join("\n")
|
54
43
|
end
|
55
44
|
|
@@ -76,21 +65,6 @@ module Rlt
|
|
76
65
|
return body if config.nil? || template.nil?
|
77
66
|
ERB.new(template).result binding
|
78
67
|
end
|
79
|
-
|
80
|
-
def self.acquire_branch_name
|
81
|
-
`git rev-parse --abbrev-ref HEAD`.strip
|
82
|
-
end
|
83
|
-
|
84
|
-
def self.print_help(*_arguments)
|
85
|
-
puts 'USAGE:'
|
86
|
-
puts ' 1. rlt commit # Almost same as `git commit`. You do not need `-m` parameter here.'
|
87
|
-
puts ''
|
88
|
-
puts ' 2. rlt commit -a # This performs `git add .` before committing.'
|
89
|
-
end
|
90
|
-
|
91
|
-
def self.valid_parameters?(*arguments)
|
92
|
-
arguments.empty? || (arguments.size == 1 && arguments[0] == '-a')
|
93
|
-
end
|
94
68
|
end
|
95
69
|
end
|
96
70
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'erb'
|
4
|
+
|
5
|
+
module Rlt
|
6
|
+
module Commands
|
7
|
+
class Switch
|
8
|
+
CONF_BRANCH_NAME_TEMPLATE = 'branch_name_template'
|
9
|
+
|
10
|
+
def self.run(config, branch_name)
|
11
|
+
modified_branch_name = change_branch_name(config, branch_name)
|
12
|
+
save_stash_if_any
|
13
|
+
switch(modified_branch_name)
|
14
|
+
apply_stash_if_any(modified_branch_name)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.change_branch_name(config, branch_name)
|
18
|
+
return branch_name if dont_change_branch_name?(config, branch_name)
|
19
|
+
branch_name_template = config[CONF_BRANCH_NAME_TEMPLATE]
|
20
|
+
return branch_name if branch_name_template.nil?
|
21
|
+
ERB.new(branch_name_template).result binding
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.save_stash_if_any
|
25
|
+
return if Utils::GitUtil.uncommitted_change?
|
26
|
+
Utils::GitUtil.save_stash('Auto stash', print_info: true)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.apply_stash_if_any(branch_name)
|
30
|
+
stash_name = Utils::GitUtil.latest_stash_name(branch_name)
|
31
|
+
return if stash_name.nil?
|
32
|
+
Utils::GitUtil.apply_stash(stash_name, print_info: true)
|
33
|
+
Utils::GitUtil.drop_stash(stash_name, print_info: true)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.dont_change_branch_name?(config, branch_name)
|
37
|
+
list = %w[master develop] + (config['exclude'] || [])
|
38
|
+
list.include? branch_name
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.switch(branch_name)
|
42
|
+
create_and_checkout(branch_name) unless checkout(branch_name)
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.checkout(branch_name)
|
46
|
+
result = Utils::GitUtil.silently_try_checkout(branch_name)
|
47
|
+
Utils::Logger.info "Switched to '#{branch_name}'." if result
|
48
|
+
result
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.create_and_checkout(branch_name)
|
52
|
+
Utils::GitUtil.silently_create_and_checkout(branch_name)
|
53
|
+
Utils::Logger.info "Created & Switched to '#{branch_name}'."
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/rlt/config.rb
CHANGED
@@ -7,11 +7,11 @@ module Rlt
|
|
7
7
|
def config(category, command)
|
8
8
|
c = config_map.dig category, command
|
9
9
|
return c unless c.nil?
|
10
|
-
return {} if command ==
|
11
|
-
config_map.dig(category,
|
10
|
+
return {} if command == original_name_of_alias(command)
|
11
|
+
config_map.dig(category, original_name_of_alias(command)) || {}
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
14
|
+
def original_name_of_alias(command)
|
15
15
|
config_map.dig 'alias', command
|
16
16
|
end
|
17
17
|
|
@@ -28,15 +28,15 @@ module Rlt
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def file_path
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
"#{Dir.pwd}/.rlt.yml"
|
35
|
-
end
|
31
|
+
sample_config_path = "#{Dir.pwd}/.rlt.sample.yml"
|
32
|
+
return sample_config_path if Rlt.debug && File.exist?(sample_config_path)
|
33
|
+
"#{Dir.pwd}/.rlt.yml"
|
36
34
|
end
|
37
35
|
|
38
36
|
def config_map
|
39
37
|
(@config_map ||= load_config)
|
40
38
|
end
|
41
39
|
end
|
40
|
+
|
41
|
+
extend Config
|
42
42
|
end
|
data/lib/rlt/debug.rb
ADDED
data/lib/rlt/error.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'pastel'
|
4
|
+
|
5
|
+
module Rlt
|
6
|
+
module Utils
|
7
|
+
class ColoredText
|
8
|
+
def self.verbose(msg)
|
9
|
+
Pastel.new.white(msg)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.info(msg)
|
13
|
+
Pastel.new.magenta.bold(msg)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.desc(msg)
|
17
|
+
Pastel.new.green(msg)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.warn(msg)
|
21
|
+
Pastel.new.yellow(msg)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.error(msg)
|
25
|
+
Pastel.new.red(msg)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rlt
|
4
|
+
module Utils
|
5
|
+
class GitUtil
|
6
|
+
# git help -a
|
7
|
+
NATIVE_COMMANDS =
|
8
|
+
%w[add add--interactive am annotate apply archimport archive bisectbisect--helper blame
|
9
|
+
branch bundle cat-file check-attr check-ignore check-mailmap check-ref-format checkout
|
10
|
+
checkout-index cherry cherry-pick citool clean clone column commit commit-tree config
|
11
|
+
count-objects credential credential-cache credential-cache--daemon credential-store
|
12
|
+
cvsexportcommit cvsimport cvsserver daemon describe diff diff-files diff-index diff-tree
|
13
|
+
difftool difftool--helper fast-export fast-import fetch fetch-pack filter-branch
|
14
|
+
fmt-merge-msg for-each-ref format-patch fsck fsck-objects gc get-tar-commit-id grep gui
|
15
|
+
gui--askpass hash-object help http-backend http-fetch http-push index-pack init init-db
|
16
|
+
instaweb interpret-trailers log ls-files ls-remote ls-tree mailinfo mailsplit merge
|
17
|
+
merge-base merge-file merge-index merge-octopus merge-one-file merge-ours merge-recursive
|
18
|
+
merge-resolve merge-subtree merge-tree mergetool mktag mktree mv name-rev notes p4
|
19
|
+
pack-objects pack-redundant pack-refs patch-id prune prune-packed pull push quiltimport
|
20
|
+
read-tree rebase receive-pack reflog relink remote remote-ext remote-fd remote-ftp
|
21
|
+
remote-ftps remote-http remote-https remote-testsvn repack replace request-pull rerere
|
22
|
+
reset rev-list rev-parse revert rm send-email send-pack sh-i18n--envsubst shell shortlog
|
23
|
+
show show-branch show-index show-ref stage stash status stripspace submodule
|
24
|
+
submodule--helper svn symbolic-ref tag unpack-file unpack-objects update-index update-ref
|
25
|
+
update-server-info upload-archive upload-pack var verify-commit verify-pack verify-tag
|
26
|
+
web--browse whatchanged worktree write-tree].freeze
|
27
|
+
|
28
|
+
def self.execute_native_command(args)
|
29
|
+
Shell.new.run 'git', *args
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.current_branch_name
|
33
|
+
`git rev-parse --abbrev-ref HEAD`.strip
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.add_all
|
37
|
+
Shell.new.run 'git', 'add', '-A'
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.uncommitted_change?
|
41
|
+
!`git status -s`.strip.empty?
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.latest_stash_name(branch_name)
|
45
|
+
line = `git stash list`.strip.split("\n").find do |l|
|
46
|
+
l.split(':')[1].strip == "On #{branch_name}"
|
47
|
+
end
|
48
|
+
return nil if line.nil?
|
49
|
+
line.split(':').first
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.save_stash(message, opts = {})
|
53
|
+
Logger.info 'Saving stash' if opts[:print_info]
|
54
|
+
Shell.new.run 'git', 'stash', 'save', '--include-untracked', message
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.apply_stash(name, opts = {})
|
58
|
+
Logger.info 'Applied stash' if opts[:print_info]
|
59
|
+
Shell.new.run 'git', 'stash', 'apply', name, '--index'
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.drop_stash(name, opts = {})
|
63
|
+
Logger.info 'Dropped stash' if opts[:print_info]
|
64
|
+
Shell.new.run 'git', 'stash', 'drop', name
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.checkout(branch_name, opts = {})
|
68
|
+
Logger.info "Switching to `#{branch_name}`" if opts[:print_info]
|
69
|
+
Shell.new.run 'git', 'checkout', branch_name
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.silently_try_checkout(branch_name)
|
73
|
+
result = Shell.new(no_output: true).run_safely 'git', 'checkout', branch_name
|
74
|
+
result.success?
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.silently_create_and_checkout(branch_name)
|
78
|
+
Shell.new(no_output: true).run 'git', 'checkout', '-b', branch_name
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.commit_with_long_message(message)
|
82
|
+
Logger.verbose message if Rlt.debug
|
83
|
+
commit_msg_file_path = "#{Dir.tmpdir}/.rlt.commit.msg.#{StringUtil.short_random_string}"
|
84
|
+
File.write(commit_msg_file_path, message)
|
85
|
+
Shell.new.run 'git', 'commit', '-F', commit_msg_file_path
|
86
|
+
File.delete(commit_msg_file_path)
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.merge_from(branch_name, opts = {})
|
90
|
+
Logger.info "Merging from `#{branch_name}`" if opts[:print_info]
|
91
|
+
Shell.new.run 'git', 'merge', branch_name
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.any_conflict?
|
95
|
+
!`git diff --name-only --diff-filter=U`.strip.empty?
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.delete_branch(branch_name, opts = {})
|
99
|
+
Logger.info "Deleting `#{branch_name}`" if opts[:print_info]
|
100
|
+
Shell.new.run 'git', 'branch', '-d', branch_name
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.remotes
|
104
|
+
`git remote`.strip.split('\n')
|
105
|
+
end
|
106
|
+
|
107
|
+
def self.safely_delete_remote_branch(remote, branch_name, opts = {})
|
108
|
+
Logger.info "Try deleting remote branch: #{remote}/#{branch_name}" if opts[:print_info]
|
109
|
+
Shell.new.run_safely 'git', 'push', remote, ":#{branch_name}"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'pastel'
|
4
|
+
|
5
|
+
module Rlt
|
6
|
+
module Utils
|
7
|
+
class Logger
|
8
|
+
def self.verbose(msg)
|
9
|
+
puts ColoredText.verbose(msg)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.info(msg)
|
13
|
+
puts ColoredText.info(msg)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.desc(msg)
|
17
|
+
puts ColoredText.desc(msg)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.warn(msg)
|
21
|
+
puts ColoredText.warn(msg)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.error(msg)
|
25
|
+
puts ColoredText.error(msg)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tty-command'
|
4
|
+
|
5
|
+
module Rlt
|
6
|
+
module Utils
|
7
|
+
class Shell
|
8
|
+
def initialize(opts = {})
|
9
|
+
@cmd = TTY::Command.new(printer: printer(opts), pty: true, dry_run: Rlt.debug)
|
10
|
+
end
|
11
|
+
|
12
|
+
def run(*args)
|
13
|
+
result = @cmd.run(*args, user: current_user)
|
14
|
+
puts '' if Rlt.debug
|
15
|
+
result
|
16
|
+
end
|
17
|
+
|
18
|
+
def run_safely(*args)
|
19
|
+
result = @cmd.run!(*args, user: current_user)
|
20
|
+
puts '' if Rlt.debug
|
21
|
+
result
|
22
|
+
end
|
23
|
+
|
24
|
+
def current_user
|
25
|
+
ENV['USER'] || ENV['USERNAME']
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def printer(opts)
|
31
|
+
if Rlt.debug
|
32
|
+
:quiet
|
33
|
+
else
|
34
|
+
opts[:no_output] ? :null : :quiet
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rlt
|
4
|
+
module Utils
|
5
|
+
class StringUtil
|
6
|
+
def self.underscore(str)
|
7
|
+
str.gsub(/::/, '/')
|
8
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
9
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
10
|
+
.tr('-', '_')
|
11
|
+
.downcase
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.short_random_string
|
15
|
+
(0...4).map { rand(65..90).chr }.join
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/rlt/version.rb
CHANGED
data/lib/rlt.rb
CHANGED
@@ -1,24 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'rlt/version'
|
4
|
-
require 'rlt/shell'
|
5
|
-
require 'rlt/colored_text'
|
6
|
-
require 'rlt/logger'
|
7
|
-
require 'rlt/base_command'
|
8
|
-
require 'rlt/git_native_command_builder'
|
9
|
-
Dir["#{__dir__}/rlt/commands/**/*.rb"].each { |f| require f }
|
10
|
-
require 'rlt/register_commands'
|
11
|
-
require 'rlt/register_aliases'
|
12
|
-
require 'rlt/command_runner'
|
13
4
|
require 'rlt/config'
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
RegisterCommands.register
|
23
|
-
RegisterAliases.register
|
24
|
-
end
|
5
|
+
require 'rlt/utils/shell'
|
6
|
+
require 'rlt/utils/colored_text'
|
7
|
+
require 'rlt/utils/logger'
|
8
|
+
require 'rlt/utils/string_util'
|
9
|
+
require 'rlt/utils/git_util'
|
10
|
+
require 'rlt/debug'
|
11
|
+
require 'rlt/error'
|
12
|
+
require 'rlt/cli'
|