rlt 0.1.7 → 0.1.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dfdc9c5d045cbcc39ffb1bb464837a33bd7d8c7d
4
- data.tar.gz: c67974bfc4c30f3f4e8b92054ea808a1d0bc0c39
3
+ metadata.gz: 294c220cc2dee9c6f061133ed9f650c6571a4bbc
4
+ data.tar.gz: b7d2fdbf841d7ccd869d0e71d5ab41e44c2fcc72
5
5
  SHA512:
6
- metadata.gz: d6cbd4a5ea9cf4f13615bfb22ed8b626cdfe87ad676744a3fa57063dab7eecff0a2bbdf58a53756f5bc87677b1e51e5bf8e132bc327b1a84884846398520b57d
7
- data.tar.gz: 134515e9e44e1d5c20d651886e8bad2f5eaf1ac5f1c9e04b4cc9019735f966b453f934c4456b040655ea197605f67e552f1ae1984fe38226582b057b6aeb6990
6
+ metadata.gz: fabcfa9a794d57858e5bd403830de86af1a5135e3c3d5dc6a7ae68cbda437347587998d0c24724a83559c4a6263212c315e61d84e9a138982fb4c47c68e41004
7
+ data.tar.gz: 195171058600ae6638532f09327f0966b9f79c28ff0035641b0c1ec7a8ddc672091037da1ea2d5a943d91290e33d1650e41f9590a498d60e45df0f2244252fb6
data/lib/rlt/cli.rb CHANGED
@@ -4,6 +4,7 @@ require 'thor'
4
4
  require 'rlt/commands/cmt'
5
5
  require 'rlt/commands/switch'
6
6
  require 'rlt/commands/close'
7
+ require 'rlt/commands/rst'
7
8
 
8
9
  module Rlt
9
10
  class CLI < Thor
@@ -9,8 +9,26 @@ module Rlt
9
9
  class Cmt
10
10
  CONF_SUBJECT_TEMPLATE = 'subject_template'
11
11
  CONF_BODY_TEMPLATE = 'body_template'
12
+ CONF_PRE = 'pre'
12
13
 
13
14
  def self.run(config, add_all)
15
+ result = run_pre_script_if_any(config)
16
+ return print_abort_due_to_pre_script_failure unless result
17
+ ask_and_commit(add_all, config)
18
+ end
19
+
20
+ def self.print_abort_due_to_pre_script_failure
21
+ Utils::Logger.error 'Aborted due to the pre-script failed.'
22
+ end
23
+
24
+ def self.run_pre_script_if_any(config)
25
+ return true if config[CONF_PRE].nil?
26
+ Utils::Logger.info 'Executing pre-script:'
27
+ Utils::Logger.desc " #{config[CONF_PRE]}"
28
+ Utils::Shell.new.run_safely config[CONF_PRE]
29
+ end
30
+
31
+ def self.ask_and_commit(add_all, config)
14
32
  branch_name = Utils::GitUtil.current_branch_name
15
33
  Utils::Logger.info "Committing to '#{branch_name}'"
16
34
  (subject, body) = subject_and_body(config, branch_name)
@@ -0,0 +1,11 @@
1
+
2
+ module Rlt
3
+ module Commands
4
+ class Rst
5
+ def self.run(_config)
6
+ Utils::GitUtil.reset_hard_head
7
+ Utils::GitUtil.clean_untracked
8
+ end
9
+ end
10
+ end
11
+ end
data/lib/rlt/config.rb CHANGED
@@ -21,20 +21,30 @@ module Rlt
21
21
  c.keys
22
22
  end
23
23
 
24
- def load_config
25
- YAML.load_file(file_path)
24
+ def load_config(path)
25
+ result = YAML.load_file(path)
26
+ return result if result.is_a? Hash
27
+ {}
26
28
  rescue Errno::ENOENT
27
29
  {}
28
30
  end
29
31
 
30
- def file_path
32
+ def local_config_path
31
33
  sample_config_path = "#{Dir.pwd}/.rlt.sample.yml"
32
34
  return sample_config_path if Rlt.debug && File.exist?(sample_config_path)
33
35
  "#{Dir.pwd}/.rlt.yml"
34
36
  end
35
37
 
38
+ def global_config_path
39
+ File.expand_path('~/.rlt.yml')
40
+ end
41
+
42
+ def load_all_configs
43
+ load_config(global_config_path).merge(load_config(local_config_path))
44
+ end
45
+
36
46
  def config_map
37
- (@config_map ||= load_config)
47
+ (@config_map ||= load_all_configs)
38
48
  end
39
49
  end
40
50
 
@@ -34,7 +34,7 @@ module Rlt
34
34
  end
35
35
 
36
36
  def self.add_all
37
- Shell.new.run 'git', 'add', '-A'
37
+ Shell.new.run 'git add -A'
38
38
  end
39
39
 
40
40
  def self.uncommitted_change?
@@ -51,44 +51,43 @@ module Rlt
51
51
 
52
52
  def self.save_stash(message, opts = {})
53
53
  Logger.info 'Saving stash' if opts[:print_info]
54
- Shell.new.run 'git', 'stash', 'save', '--include-untracked', message
54
+ Shell.new.run 'git stash save', '--include-untracked', message
55
55
  end
56
56
 
57
57
  def self.apply_stash(name, opts = {})
58
58
  Logger.info 'Applied stash' if opts[:print_info]
59
- Shell.new.run 'git', 'stash', 'apply', name, '--index'
59
+ Shell.new.run 'git stash apply', name, '--index'
60
60
  end
61
61
 
62
62
  def self.drop_stash(name, opts = {})
63
63
  Logger.info 'Dropped stash' if opts[:print_info]
64
- Shell.new.run 'git', 'stash', 'drop', name
64
+ Shell.new.run 'git stash drop', name
65
65
  end
66
66
 
67
67
  def self.checkout(branch_name, opts = {})
68
68
  Logger.info "Switching to `#{branch_name}`" if opts[:print_info]
69
- Shell.new.run 'git', 'checkout', branch_name
69
+ Shell.new.run 'git checkout', branch_name
70
70
  end
71
71
 
72
72
  def self.silently_try_checkout(branch_name)
73
- result = Shell.new(no_output: true).run_safely 'git', 'checkout', branch_name
74
- result.success?
73
+ Shell.new(no_output: true).run_safely 'git checkout', branch_name
75
74
  end
76
75
 
77
76
  def self.silently_create_and_checkout(branch_name)
78
- Shell.new(no_output: true).run 'git', 'checkout', '-b', branch_name
77
+ Shell.new(no_output: true).run 'git checkout -b', branch_name
79
78
  end
80
79
 
81
80
  def self.commit_with_long_message(message)
82
81
  Logger.verbose message if Rlt.debug
83
82
  commit_msg_file_path = "#{Dir.tmpdir}/.rlt.commit.msg.#{StringUtil.short_random_string}"
84
83
  File.write(commit_msg_file_path, message)
85
- Shell.new.run 'git', 'commit', '-F', commit_msg_file_path
84
+ Shell.new.run 'git commit -F', commit_msg_file_path
86
85
  File.delete(commit_msg_file_path)
87
86
  end
88
87
 
89
88
  def self.merge_from(branch_name, opts = {})
90
89
  Logger.info "Merging from `#{branch_name}`" if opts[:print_info]
91
- Shell.new.run 'git', 'merge', branch_name
90
+ Shell.new.run 'git merge', branch_name
92
91
  end
93
92
 
94
93
  def self.any_conflict?
@@ -97,7 +96,7 @@ module Rlt
97
96
 
98
97
  def self.delete_branch(branch_name, opts = {})
99
98
  Logger.info "Deleting `#{branch_name}`" if opts[:print_info]
100
- Shell.new.run 'git', 'branch', '-d', branch_name
99
+ Shell.new.run 'git branch -d', branch_name
101
100
  end
102
101
 
103
102
  def self.remotes
@@ -106,7 +105,15 @@ module Rlt
106
105
 
107
106
  def self.safely_delete_remote_branch(remote, branch_name, opts = {})
108
107
  Logger.info "Try deleting remote branch: #{remote}/#{branch_name}" if opts[:print_info]
109
- Shell.new.run_safely 'git', 'push', remote, ":#{branch_name}"
108
+ Shell.new.run_safely 'git push', remote, ":#{branch_name}"
109
+ end
110
+
111
+ def self.reset_hard_head
112
+ Shell.new.run 'git reset --hard HEAD'
113
+ end
114
+
115
+ def self.clean_untracked
116
+ Shell.new.run 'git clean -fd'
110
117
  end
111
118
  end
112
119
  end
@@ -18,7 +18,7 @@ module Rlt
18
18
  def run_safely(*args)
19
19
  result = @cmd.run!(*args, user: current_user)
20
20
  puts '' if Rlt.debug
21
- result
21
+ result.success?
22
22
  end
23
23
 
24
24
  def current_user
data/lib/rlt/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rlt
4
- VERSION = '0.1.7'
4
+ VERSION = '0.1.8'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rlt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eunjae Lee
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-08 00:00:00.000000000 Z
11
+ date: 2018-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pastel
@@ -136,6 +136,7 @@ files:
136
136
  - lib/rlt/cli.rb
137
137
  - lib/rlt/commands/close.rb
138
138
  - lib/rlt/commands/cmt.rb
139
+ - lib/rlt/commands/rst.rb
139
140
  - lib/rlt/commands/switch.rb
140
141
  - lib/rlt/config.rb
141
142
  - lib/rlt/debug.rb