rlt 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +3 -0
- data/lib/rlt/colored_text.rb +27 -0
- data/lib/rlt/commands/cmt_command.rb +2 -3
- data/lib/rlt/commands/switch_command.rb +24 -4
- data/lib/rlt/logger.rb +8 -4
- data/lib/rlt/version.rb +1 -1
- data/lib/rlt.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 924868479d56a4d4bf7f01d69665c6047abfb764535c31989a0d7dd6a1042c53
|
4
|
+
data.tar.gz: 2920cea7739142556919b8694e5a231c5b59a6e5780920dd7cda30510eef0e09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13301ef6ae59a1a799a965ccfbfd97161d5e7597a8db66b6bbf55cbb3d520744afa5271a490443a717e2c1a13026a38dcf253364d745ef2790a28cb7495f156c
|
7
|
+
data.tar.gz: 33230ffa43b5a38a34462f518f8aec736ddb769c954f64d9a135d715c5000c7dd2aeb5e0ae97e1afaa72ca432a58eb3edd5fe0be143ecb11ae6e672946989660
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -24,6 +24,9 @@ $ rlt switch <branch_name>
|
|
24
24
|
|
25
25
|
This will switch to `<branch_name>`. If the branch does not exist, then it will create it.
|
26
26
|
|
27
|
+
And it automatically stashes uncommitted changes including untracked files switching to other branch.
|
28
|
+
When coming back, it automatically unstashes it.
|
29
|
+
|
27
30
|
## Configuration
|
28
31
|
|
29
32
|
The great power in rlt comes from configuration, using ERB syntax in YAML.
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'pastel'
|
4
|
+
|
5
|
+
module Rlt
|
6
|
+
class ColoredText
|
7
|
+
def self.verbose(msg)
|
8
|
+
Pastel.new.white(msg)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.info(msg)
|
12
|
+
Pastel.new.cyan(msg)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.desc(msg)
|
16
|
+
Pastel.new.magenta(msg)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.warn(msg)
|
20
|
+
Pastel.new.yellow(msg)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.error(msg)
|
24
|
+
Pastel.new.red(msg)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'erb'
|
4
|
-
require 'pastel'
|
5
4
|
require 'tty-prompt'
|
6
5
|
require 'tmpdir'
|
7
6
|
|
@@ -13,7 +12,7 @@ module Rlt
|
|
13
12
|
|
14
13
|
def self.run(config, *arguments)
|
15
14
|
branch_name = acquire_branch_name
|
16
|
-
puts "Commiting to '#{
|
15
|
+
puts "Commiting to '#{ColoredText.info(branch_name)}'\n\n"
|
17
16
|
(subject, body) = subject_and_body(config, branch_name)
|
18
17
|
add_all if arguments[0] == '-a'
|
19
18
|
commit(subject, body)
|
@@ -49,7 +48,7 @@ module Rlt
|
|
49
48
|
end
|
50
49
|
|
51
50
|
def self.ask_body
|
52
|
-
puts 'Body: ' +
|
51
|
+
puts 'Body: ' + ColoredText.desc('(Insert empty line to finish)')
|
53
52
|
lines = ask_multiline_until_done('>', :cyan)
|
54
53
|
lines.join("\n")
|
55
54
|
end
|
@@ -9,7 +9,9 @@ module Rlt
|
|
9
9
|
|
10
10
|
def self.run(config, *arguments)
|
11
11
|
branch_name = change_branch_name(config, arguments[0])
|
12
|
+
save_stash_if_any
|
12
13
|
switch(branch_name)
|
14
|
+
apply_stash_if_any(branch_name)
|
13
15
|
end
|
14
16
|
|
15
17
|
def self.change_branch_name(config, branch_name)
|
@@ -19,6 +21,20 @@ module Rlt
|
|
19
21
|
ERB.new(branch_name_template).result binding
|
20
22
|
end
|
21
23
|
|
24
|
+
def self.save_stash_if_any
|
25
|
+
return if `git status -s`.strip.empty?
|
26
|
+
Logger.info 'Saving stash'
|
27
|
+
Shell.new.run 'git', 'stash', 'save', '--include-untracked', 'Auto stash'
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.apply_stash_if_any(branch_name)
|
31
|
+
name = stash_name(branch_name)
|
32
|
+
return if name.nil?
|
33
|
+
Logger.info 'Applied stash'
|
34
|
+
Shell.new.run 'git', 'stash', 'apply', name, '--index'
|
35
|
+
Shell.new.run 'git', 'stash', 'drop', name
|
36
|
+
end
|
37
|
+
|
22
38
|
def self.exclude?(config, branch_name)
|
23
39
|
list = %w[master develop] + (config['exclude'] || [])
|
24
40
|
list.include? branch_name
|
@@ -29,13 +45,13 @@ module Rlt
|
|
29
45
|
end
|
30
46
|
|
31
47
|
def self.checkout(branch_name)
|
32
|
-
result =
|
48
|
+
result = Shell.new(no_output: true).run_safely 'git', 'checkout', branch_name
|
33
49
|
Logger.info "Switched to '#{branch_name}'." unless result.failure?
|
34
50
|
result
|
35
51
|
end
|
36
52
|
|
37
53
|
def self.create_and_checkout(branch_name)
|
38
|
-
|
54
|
+
Shell.new(no_output: true).run 'git', 'checkout', '-b', branch_name
|
39
55
|
Logger.info "Created & Switched to '#{branch_name}'."
|
40
56
|
end
|
41
57
|
|
@@ -50,8 +66,12 @@ module Rlt
|
|
50
66
|
arguments.size == 1
|
51
67
|
end
|
52
68
|
|
53
|
-
def self.
|
54
|
-
|
69
|
+
def self.stash_name(branch_name)
|
70
|
+
line = `git stash list`.strip.split("\n").find do |line|
|
71
|
+
line.split(':')[1].strip == "On #{branch_name}"
|
72
|
+
end
|
73
|
+
return nil if line.nil?
|
74
|
+
line.split(':').first
|
55
75
|
end
|
56
76
|
end
|
57
77
|
end
|
data/lib/rlt/logger.rb
CHANGED
@@ -5,19 +5,23 @@ require 'pastel'
|
|
5
5
|
module Rlt
|
6
6
|
class Logger
|
7
7
|
def self.verbose(msg)
|
8
|
-
puts
|
8
|
+
puts ColoredText.verbose(msg)
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.info(msg)
|
12
|
-
puts
|
12
|
+
puts ColoredText.info(msg)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.desc(msg)
|
16
|
+
puts ColoredText.desc(msg)
|
13
17
|
end
|
14
18
|
|
15
19
|
def self.warn(msg)
|
16
|
-
puts
|
20
|
+
puts ColoredText.warn(msg)
|
17
21
|
end
|
18
22
|
|
19
23
|
def self.error(msg)
|
20
|
-
puts
|
24
|
+
puts ColoredText.error(msg)
|
21
25
|
end
|
22
26
|
end
|
23
27
|
end
|
data/lib/rlt/version.rb
CHANGED
data/lib/rlt.rb
CHANGED
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.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pastel
|
@@ -133,6 +133,7 @@ files:
|
|
133
133
|
- exe/rlt
|
134
134
|
- lib/rlt.rb
|
135
135
|
- lib/rlt/base_command.rb
|
136
|
+
- lib/rlt/colored_text.rb
|
136
137
|
- lib/rlt/command_runner.rb
|
137
138
|
- lib/rlt/commands/cmt_command.rb
|
138
139
|
- lib/rlt/commands/switch_command.rb
|