rlt 0.1.3 → 0.1.4

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
  SHA256:
3
- metadata.gz: 7d5e0d5c96151a0109da828bea2aceefe7724ae31f1b48db2b857a8be57544fc
4
- data.tar.gz: 4bb26123cb6654a975937707851fd789cabd0a6d70a6b53da1e088ea53ab7776
3
+ metadata.gz: 924868479d56a4d4bf7f01d69665c6047abfb764535c31989a0d7dd6a1042c53
4
+ data.tar.gz: 2920cea7739142556919b8694e5a231c5b59a6e5780920dd7cda30510eef0e09
5
5
  SHA512:
6
- metadata.gz: 212073d3b4b2acd1f826124fbf37d70ca267a019d1d0dd724d9ffdf2c5e0468b205d1b6a046f20a51ede74078eb9b8f97be15c2b835a21c80101025dd2970e98
7
- data.tar.gz: '09018f8e6be388149a24971bcb84a6879d8ec57de64c161647aee08ee26ecf3082e7d8e926a0532e701ada21242540a09496d51addda4013a2f5e393d91e4bd1'
6
+ metadata.gz: 13301ef6ae59a1a799a965ccfbfd97161d5e7597a8db66b6bbf55cbb3d520744afa5271a490443a717e2c1a13026a38dcf253364d745ef2790a28cb7495f156c
7
+ data.tar.gz: 33230ffa43b5a38a34462f518f8aec736ddb769c954f64d9a135d715c5000c7dd2aeb5e0ae97e1afaa72ca432a58eb3edd5fe0be143ecb11ae6e672946989660
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rlt (0.1.3)
4
+ rlt (0.1.4)
5
5
  pastel (~> 0.7.2)
6
6
  tty-command (~> 0.8.0)
7
7
  tty-prompt (~> 0.16.1)
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 '#{Pastel.new.green(branch_name)}'\n\n"
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: ' + Pastel.new.magenta('(Insert empty line to finish)')
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 = shell.run_safely 'git', 'checkout', branch_name
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
- shell.run 'git', 'checkout', '-b', branch_name
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.shell
54
- Shell.new(no_output: true)
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 Pastel.new.white(msg)
8
+ puts ColoredText.verbose(msg)
9
9
  end
10
10
 
11
11
  def self.info(msg)
12
- puts Pastel.new.cyan(msg)
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 Pastel.new.yellow(msg)
20
+ puts ColoredText.warn(msg)
17
21
  end
18
22
 
19
23
  def self.error(msg)
20
- puts Pastel.new.red(msg)
24
+ puts ColoredText.error(msg)
21
25
  end
22
26
  end
23
27
  end
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.3'
4
+ VERSION = '0.1.4'
5
5
  end
data/lib/rlt.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'rlt/version'
4
4
  require 'rlt/shell'
5
+ require 'rlt/colored_text'
5
6
  require 'rlt/logger'
6
7
  require 'rlt/base_command'
7
8
  require 'rlt/git_native_command_builder'
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.3
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-03 00:00:00.000000000 Z
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