gitswitch 0.4.3 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d9158f1a5fc0f97b3635cee121ea2302af4666df
4
- data.tar.gz: 6e6d5254b0fa461ad77ab9177c715024072800ce
2
+ SHA256:
3
+ metadata.gz: 19172f6e57fbee0cfefbf53f21abef74d7634ec95358a57970c7b20580753aa6
4
+ data.tar.gz: eeb466be90eb179bdcc915836c23ab9a782a5deb6cb5bbe62a623b360b28090f
5
5
  SHA512:
6
- metadata.gz: 80e0bd6275c0155b078b9934343dc560f1180bc7e57d96aae113639a912fca42e8702a4365df62005f0225532052631754819f09aaa4f536de87bad1a0d53c9f
7
- data.tar.gz: 06d83533d2329c6342fe5e4c7a309d428759f6f867cacfac5c01139d4b4bb08e63cc37834914d85ab905bc946da5b6fa648b675ec2373159d3fa49c8b056a4ff
6
+ metadata.gz: ae1d9f2b84cbae1b5fa3248e3b27289c77304d2f1ccc663410f7d4eb2dbc2d66150d38978f503de90d97b61183d0eed0f0b0e78ab3cc3b7e5088241e87a5202a
7
+ data.tar.gz: f24802fc950a68e7b8fe0542f90fb7929f8641891aca0d7265e29fbb5b21105e0e51d6276d8653e5c929790a3a2fb27fbe3f50e736952db8c928141bb0fec5fb
@@ -0,0 +1,32 @@
1
+ name: Ruby CI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ paths-ignore:
8
+ - 'README.rdoc'
9
+ pull_request:
10
+ branches:
11
+ - main
12
+ paths-ignore:
13
+ - 'README.rdoc'
14
+ jobs:
15
+ test:
16
+ runs-on: ubuntu-latest
17
+ if: "contains(github.event.commits[0].message, '[ci skip]') == false"
18
+
19
+ strategy:
20
+ matrix:
21
+ ruby: [3.2.1, 3.1.3, 3.0.5, 2.7.7]
22
+
23
+ steps:
24
+ - name: Checkout
25
+ uses: actions/checkout@v2
26
+ - name: Setup Ruby
27
+ uses: ruby/setup-ruby@v1
28
+ with:
29
+ ruby-version: ${{ matrix.ruby }}
30
+ bundler-cache: true
31
+ - name: Test
32
+ run: bundle exec rake spec
data/README.rdoc CHANGED
@@ -1,7 +1,5 @@
1
1
  = gitswitch
2
2
 
3
- [![Build Status](https://travis-ci.org/joealba/gitswitch.svg?branch=master)](https://travis-ci.org/joealba/gitswitch)
4
-
5
3
  Easily set/switch your current git user info for a git repo .git/config or your global ~/.gitconfig file.
6
4
 
7
5
  This gem should come in handy if you have work and personal repositories. It also might help with switching between users while pair programming.
@@ -55,19 +53,7 @@ Delete a current entry. [TAG] parameter is optional. If omitted, you'll see a
55
53
  # gitswitch delete [TAG]
56
54
 
57
55
  Update your global .git user instead of your current repository
58
- # gitswitch global work
56
+ # gitswitch switch work --global
59
57
 
60
58
  Show your current git user info. If you are in a git repo directory, it will show you the info associated with the current repository. Outside a repo (or if you use the --global option), it will show you the info from your global .git config.
61
59
  # gitswitch info
62
-
63
- == What's with all the aliases for each task?
64
-
65
- I initially wrote the gem using optparse and used the '-r' style params to keep the commands as short as possible. Now, I've decided to lean toward a rake-style descriptive method of passing commands -- which meshes well with the way Thor likes to do things. But the old command line options still work fine in case you got used to it.
66
-
67
- == Recent changes (2012 edition)
68
-
69
- I've learned a few things, taken some inspiration from David Copeland's "Build Awesome Command-Line Applications in Ruby" book, and stolen the idea of making everything a class method from Hashrocket's hitch gem.
70
-
71
- In Ruby 1.9, command line argument strings get frozen, which makes gsub! unhappy. I wasn't on 1.9 two years ago, and my tests are far too incomplete for Travis CI to catch this bug. But alas, it is now fixed.
72
-
73
- I've made the first steps toward returning reasonable exit status codes. A failed git command will not yet throw a proper exit code.
data/Rakefile CHANGED
@@ -4,7 +4,6 @@ require 'rspec/core/rake_task'
4
4
 
5
5
  Bundler::GemHelper.install_tasks
6
6
 
7
-
8
7
  desc 'Default: Run specs'
9
8
  task :default => :spec
10
9
 
data/bin/gitswitch CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "gitswitch"
4
- Gitswitch::CLI.start
4
+
5
+ Dry::CLI.new(Gitswitch::CLI::Commands).call
data/gitswitch.gemspec CHANGED
@@ -9,17 +9,23 @@ Gem::Specification.new do |s|
9
9
 
10
10
  s.authors = ["Joe Alba"]
11
11
  s.date = %q{2012-04-29}
12
- s.default_executable = %q{gitswitch}
13
- s.homepage = %q{http://github.com/joealba/gitswitch}
12
+ s.homepage = %q{https://github.com/joealba/gitswitch}
14
13
  s.description = %q{Easily switch your git name/e-mail user info -- Handy for work vs. personal and for pair programming}
15
14
  s.summary = %q{Easy git user switching}
16
15
  s.email = %q{joe@joealba.com}
17
-
16
+ s.metadata = {
17
+ "bug_tracker_uri" => "#{s.homepage}/issues",
18
+ "changelog_uri" => "#{s.homepage}/blob/main/CHANGELOG.md",
19
+ "documentation_uri" => s.homepage.to_s,
20
+ "homepage_uri" => s.homepage.to_s,
21
+ "source_code_uri" => s.homepage.to_s
22
+ }
23
+
18
24
  s.extra_rdoc_files = [
19
25
  "LICENSE",
20
26
  "README.rdoc"
21
27
  ]
22
-
28
+
23
29
  s.files = `git ls-files`.split("\n")
24
30
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
25
31
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
@@ -27,9 +33,9 @@ Gem::Specification.new do |s|
27
33
 
28
34
  s.rdoc_options = ["--charset=UTF-8"]
29
35
 
30
- s.add_dependency('rake')
31
- s.add_dependency('thor')
36
+ s.add_dependency('rake')
37
+ s.add_dependency('dry-cli')
38
+ s.add_dependency('tty-prompt')
32
39
  s.add_development_dependency(%q<rspec>, [">= 3.3.0"])
33
-
40
+ s.add_development_dependency 'simplecov'
34
41
  end
35
-
data/lib/gitswitch/cli.rb CHANGED
@@ -1,164 +1,207 @@
1
- require 'thor'
2
-
3
-
4
- class Gitswitch
5
- class CLI < Thor
6
- EXIT_OK = 0
7
- EXIT_MISSING_INFO = 1
8
-
9
- ######################################################################
10
- desc "init", "Initialize your .gitswitch file"
11
- def init
12
- if !Gitswitch::gitswitch_file_exists
13
- if yes?("Gitswitch users file ~/.gitswitch not found. Would you like to create one? (y/n): ")
14
- Gitswitch.create_fresh_gitswitch_file
15
- else
16
- puts "Ok, that's fine. Exiting."
17
- exit EXIT_OK
1
+ require "dry/cli"
2
+ require "tty-prompt"
3
+
4
+ module Gitswitch
5
+ module CLI
6
+ module Helpers
7
+ def prompt_for_email_and_name
8
+ prompt = TTY::Prompt.new
9
+ email = prompt.ask(" E-mail address: ").to_s.chomp
10
+ if email.empty?
11
+ puts "No e-mail address provided"
12
+ exit Gitswitch::EXIT_MISSING_INFO
18
13
  end
19
- else
20
- if yes?("Gitswitch users file ~/.gitswitch already exists. Would you like to wipe it out and create a fresh one? (y/n): ")
21
- Gitswitch.create_fresh_gitswitch_file
14
+
15
+ default_name = Gitswitch::get_git_user_info({global: true})[:name]
16
+ name = prompt.ask(" Name: (ENTER to use \"" + default_name + "\") ").to_s.chomp
17
+ name = default_name if name.empty?
18
+
19
+ if name.empty?
20
+ puts "No name provided"
22
21
  end
22
+
23
+ return [email, name]
23
24
  end
25
+ end
24
26
 
25
- # Grab the current global info to drop into the default slot -- if available
26
- user = Gitswitch.get_git_user_info({:global => true})
27
- if user[:name].empty? && user[:email].empty?
28
- puts "No global git user.name and user.email configurations were found. Set up a default now."
29
- add('default')
30
- else
31
- puts "Adding your global .gitconfig user info to the \"default\" tag..."
32
- Gitswitch.set_gitswitch_entry('default', user[:email], user[:name])
27
+ module Commands
28
+ extend Dry::CLI::Registry
29
+
30
+ class Init < Dry::CLI::Command
31
+ desc "Initialize your .gitswitch file"
32
+
33
+ def call(*)
34
+ prompt = TTY::Prompt.new
35
+
36
+ if !Gitswitch::gitswitch_file_exists
37
+ if prompt.yes?("Gitswitch users file ~/.gitswitch not found. Would you like to create one? (y/n):")
38
+ Gitswitch.create_fresh_gitswitch_file
39
+ else
40
+ puts "Ok, that's fine. Exiting."
41
+ exit Gitswitch::EXIT_OK
42
+ end
43
+ else
44
+ if prompt.yes?("Gitswitch users file ~/.gitswitch already exists. Would you like to wipe it out and create a fresh one? (y/n):")
45
+ Gitswitch.create_fresh_gitswitch_file
46
+ end
47
+ end
48
+
49
+ # Grab the current global info to drop into the default slot -- if available
50
+ user = Gitswitch.get_git_user_info({global: true})
51
+ if user[:name].empty? && user[:email].empty?
52
+ puts "No global git user.name and user.email configurations were found. Set up a default now."
53
+ add('default')
54
+ else
55
+ puts "Adding your global .gitconfig user info to the \"default\" tag..."
56
+ Gitswitch.set_gitswitch_entry('default', user[:email], user[:name])
57
+ end
58
+
59
+ exit Gitswitch::EXIT_OK
60
+ end
33
61
  end
34
62
 
35
- exit EXIT_OK
36
- end
63
+ class Info < Dry::CLI::Command
64
+ desc "Show the current git user"
65
+ option :global, type: :boolean, default: false, desc: "Show global config"
37
66
 
38
-
39
- ######################################################################
40
- desc "version", "Show the gitswitch version"
41
- map ["-v","--version"] => :version
42
- def version
43
- puts Gitswitch::VERSION
44
- exit EXIT_OK
45
- end
67
+ def call(**options)
68
+ puts Gitswitch.current_user_info(options)
46
69
 
70
+ exit Gitswitch::EXIT_OK
71
+ end
72
+ end
47
73
 
48
- ######################################################################
49
- desc "info", "Show the current git user"
50
- map "-i" => :info
51
- method_option :global, :type => :boolean
52
- def info
53
- puts Gitswitch.current_user_info(options)
54
- exit EXIT_OK
55
- end
74
+ class List < Dry::CLI::Command
75
+ desc "Show all the git user tags you have configured"
56
76
 
77
+ def call(*)
78
+ puts Gitswitch.list_users
57
79
 
58
- ######################################################################
59
- desc "list", "Show all the git user tags you have configured"
60
- map ["-l","--list"] => :list
61
- def list
62
- puts Gitswitch.list_users
63
- exit EXIT_OK
64
- end
80
+ exit Gitswitch::EXIT_OK
81
+ end
82
+ end
65
83
 
84
+ class Switch < Dry::CLI::Command
85
+ desc "Switch git user"
86
+ argument :tag, desc: "Tag name"
87
+ option :global, type: :boolean, default: false, desc: "Set global config"
66
88
 
67
- ######################################################################
68
- desc "switch [TAG]", "Switch git user"
69
- map "-r" => :switch
70
- method_option :global, :type => :boolean, :aliases => ["-s","--global"] ## To support the deprecated behavior
71
- method_option :repository, :type => :boolean, :aliases => "-r"
72
- def switch(tag = 'default')
73
- options[:global] ? global(tag) : Gitswitch.switch_repo_user(tag)
74
- puts Gitswitch.current_user_info(options)
75
- exit EXIT_OK
76
- end
89
+ def call(tag: "default", **options)
90
+ options[:global] ? Gitswitch.switch_global_user(tag) : Gitswitch.switch_repo_user(tag)
91
+ puts Gitswitch.current_user_info(options)
77
92
 
93
+ exit Gitswitch::EXIT_OK
94
+ end
95
+ end
78
96
 
79
- ######################################################################
80
- desc "global [TAG]", "Switch global git user (your ~/.gitconfig file)"
81
- map "-s" => :global
82
- def global(tag = 'default')
83
- Gitswitch.switch_global_user(tag)
84
- exit EXIT_OK
85
- end
97
+ class Global < Dry::CLI::Command
98
+ desc "Switch the global git user info (your ~/.gitconfig file)"
99
+ argument :tag, desc: "Tag name"
86
100
 
101
+ def call(tag: "default", **)
102
+ Gitswitch.switch_global_user(tag)
87
103
 
88
- ######################################################################
89
- desc "add [TAG]", "Add a new tagged user entry"
90
- map ["-a","--add"] => :add
91
- def add(tag = '')
92
- # tag.gsub!(/\W+/,'') ## ARGV gets frozen, so gsub! will throw an error.
93
- tag = tag.gsub(/\W+/,'')
94
- tag = ask("Enter a tag to describe this git user entry: ").gsub(/\W+/,'') if (tag.nil? || tag.empty?)
95
-
96
- if tag.empty?
97
- puts "You must enter a short tag to describe the git user entry you would like to save."
98
- exit EXIT_MISSING_INFO
104
+ exit Gitswitch::EXIT_OK
105
+ end
99
106
  end
100
107
 
101
- puts "Adding a new gitswitch user entry for tag '#{tag}'"
102
- (email, name) = prompt_for_email_and_name
103
- Gitswitch.set_gitswitch_entry(tag, email, name)
104
- exit EXIT_OK
105
- end
108
+ class Add < Dry::CLI::Command
109
+ include ::Gitswitch::CLI::Helpers
110
+
111
+ desc "Add a new tagged user entry"
112
+ argument :tag, desc: "Tag name"
106
113
 
114
+ def call(tag: "", **)
115
+ tag = tag.gsub(/\W+/,'')
116
+ if (tag.nil? || tag.empty?)
117
+ prompt = TTY::Prompt.new
118
+ tag = prompt.ask("Enter a tag to describe this git user entry: ").to_s.gsub(/\W+/,'')
119
+ end
107
120
 
108
- ######################################################################
109
- desc "update [TAG]", "Update a tagged user entry"
110
- map ["-o","--overwrite"] => :add
111
- def update(tag = '')
112
- tag_table = Gitswitch.get_tag_display
113
-
114
- tag = tag.gsub(/\W+/,'')
115
- if (tag.nil? || tag.empty?)
116
- tag = ask("Which tag would you like to update: \n#{tag_table}").gsub(/\W+/,'')
121
+ if tag.empty?
122
+ puts "You must enter a short tag to describe the git user entry you would like to save."
123
+ exit Gitswitch::EXIT_MISSING_INFO
124
+ end
125
+
126
+ puts "Adding a new gitswitch user entry for tag '#{tag}'"
127
+ (email, name) = prompt_for_email_and_name
128
+ Gitswitch.set_gitswitch_entry(tag, email, name)
129
+ exit Gitswitch::EXIT_OK
130
+ end
117
131
  end
118
-
119
- puts "Updating #{tag} entry..."
120
- (email, name) = prompt_for_email_and_name
121
- Gitswitch.set_gitswitch_entry(tag, email, name)
122
- exit EXIT_OK
123
- end
124
132
 
133
+ class Delete < Dry::CLI::Command
134
+ desc "Delete a tagged user entry"
135
+
136
+ def call(tag: "")
137
+ tag_table = Gitswitch.get_tag_display
138
+
139
+ tag = tag.gsub(/\W+/, '')
140
+ if (tag.empty?)
141
+ puts tag_table
142
+ prompt = TTY::Prompt.new
143
+ tag = prompt.ask("\nWhich tag would you like to delete: ").to_s.gsub(/\W+/,'')
144
+ end
125
145
 
126
- ######################################################################
127
- desc "delete [TAG]", "Delete a tagged user entry"
128
- def delete(tag = '')
129
- tag_table = Gitswitch.get_tag_display
130
-
131
- tag = tag.gsub(/\W+/,'')
132
- if (tag.nil? || tag.empty?)
133
- tag = ask("Which tag would you like to delete: \n#{tag_table}").gsub(/\W+/,'')
146
+ if tag.empty?
147
+ puts "No tag chosen"
148
+ exit Gitswitch::EXIT_MISSING_INFO
149
+ end
150
+
151
+ Gitswitch.delete_gitswitch_entry(tag)
152
+
153
+ puts Gitswitch.get_tag_display
154
+
155
+ exit Gitswitch::EXIT_OK
156
+ end
134
157
  end
135
158
 
136
- Gitswitch.delete_gitswitch_entry(tag)
137
- exit EXIT_OK
138
- end
159
+ class Update < Dry::CLI::Command
160
+ include ::Gitswitch::CLI::Helpers
139
161
 
162
+ desc "Update a tagged user entry"
163
+ argument :tag, desc: "Tag name"
140
164
 
141
- private
142
-
165
+ def call(tag: "", **)
166
+ tag_table = Gitswitch.get_tag_display
143
167
 
144
- ######################################################################
145
- def prompt_for_email_and_name
146
- email = ask(" E-mail address: ").chomp
147
- ## TODO: Validate e-mail
148
- if email.nil?
149
- puts "No e-mail address provided"
168
+ tag = tag.gsub(/\W+/, '')
169
+ if (tag.empty?)
170
+ prompt = TTY::Prompt.new
171
+ tag = prompt.ask("Which tag would you like to update: \n#{tag_table}\nTag: ").to_s.gsub(/\W+/,'')
172
+ end
173
+
174
+ if tag.empty?
175
+ puts "No tag chosen"
176
+ exit Gitswitch::EXIT_MISSING_INFO
177
+ end
178
+
179
+ puts "Updating #{tag} entry..."
180
+ (email, name) = prompt_for_email_and_name
181
+ Gitswitch.set_gitswitch_entry(tag, email, name)
182
+
183
+ exit Gitswitch::EXIT_OK
184
+ end
150
185
  end
151
-
152
- name = ask(" Name: (ENTER to use \"" + Gitswitch::get_git_user_info({:global => true})[:name] + "\") ").chomp
153
- name = Gitswitch::get_git_user_info({:global => true})[:name] if name.empty?
154
-
155
- if name.nil?
156
- puts "No name provided"
186
+
187
+ class Version < Dry::CLI::Command
188
+ desc "Show the gitswitch version"
189
+
190
+ def call(*)
191
+ puts Gitswitch::VERSION
192
+
193
+ exit Gitswitch::EXIT_OK
194
+ end
157
195
  end
158
196
 
159
- return [email, name]
197
+ register "add", Add, aliases: ["-a", "--add"]
198
+ register "delete", Delete, aliases: ["remove"]
199
+ register "info", Info, aliases: ["-i", "--info"]
200
+ register "init", Init
201
+ register "list", List, aliases: ["-l", "--list"]
202
+ register "switch", Switch, aliases: ["-r"]
203
+ register "update", Update, aliases: ["-o","--overwrite"]
204
+ register "version", Version, aliases: ["-v", "--version"]
160
205
  end
161
-
162
-
163
206
  end
164
- end
207
+ end
@@ -1,7 +1,7 @@
1
1
  require 'yaml'
2
2
 
3
- class Gitswitch
4
- def self.gitswitch_config_file
3
+ module Gitswitch
4
+ def self.gitswitch_config_file
5
5
  ENV['GITSWITCH_CONFIG_FILE'] || File.join(ENV["HOME"], ".gitswitch")
6
6
  end
7
7
 
@@ -24,7 +24,7 @@ class Gitswitch
24
24
  end
25
25
 
26
26
  def self.gitswitch_file_exists
27
- File.exists? gitswitch_config_file
27
+ File.exist? gitswitch_config_file
28
28
  end
29
29
 
30
30
  def self.save_gitswitch_file(users_hash)
@@ -47,7 +47,7 @@ class Gitswitch
47
47
  # * +email+ - Required
48
48
  # * +name+ - Required
49
49
  def self.set_gitswitch_entry(tag, email, name)
50
- users[tag] = {:name => name, :email => email}
50
+ users[tag] = {name: name, email: email}
51
51
  save_gitswitch_file(users)
52
52
  end
53
53
 
@@ -61,7 +61,7 @@ class Gitswitch
61
61
  end
62
62
 
63
63
  def self.get_user(tag)
64
- ## TODO: Stop coding so defensively.
64
+ ## TODO: Stop coding so defensively.
65
65
  if !users.empty? && users[tag] && !users[tag].empty?
66
66
  users[tag]
67
67
  end
@@ -72,28 +72,30 @@ class Gitswitch
72
72
  end
73
73
 
74
74
  def self.get_tag_display
75
- max_length = users.keys.sort{|x,y| y.length <=> x.length }.first.length
76
- users.each_pair.map {|key,value| sprintf(" %#{max_length}s %s\n", key, value[:email]) }
75
+ users.map do |key, user|
76
+ item = "#{key}:\n"
77
+ item << " Name: #{user[:name]}\n" if !user[:name].to_s.empty?
78
+ item << " E-mail: #{user[:email]}\n"
79
+ item
80
+ end.join("\n")
77
81
  end
78
82
 
79
83
  def self.list_users
80
- response = ''
81
- response << "\nCurrent git user options --\n"
82
- users.each do |key, user|
83
- response << "#{key}:\n"
84
- response << " Name: #{user[:name]}\n" if !user[:name].to_s.empty?
85
- response << " E-mail: #{user[:email]}\n\n"
86
- end
84
+ response = "\nCurrent git user options --\n"
85
+ response << get_tag_display
86
+
87
87
  response
88
88
  end
89
89
 
90
90
  ## Return active user information.
91
91
  ## If you're in a git repo, show that user info. Otherwise, display the global info.
92
92
  def self.current_user_info(options = {})
93
- response = !Gitswitch::in_a_git_repo || options[:global] ? "Your git user information from your global config:\n" : "Your git user information from the current repository:\n"
94
93
  current_git_user = Gitswitch::get_git_user_info(options)
95
- response << "Name: #{current_git_user[:name]}\n"
94
+
95
+ response = !Gitswitch::in_a_git_repo || options[:global] ? "Your git user information from your global config:\n" : "Your git user information from the current repository:\n"
96
+ response << "Name: #{current_git_user[:name]}\n"
96
97
  response << "E-mail: #{current_git_user[:email]}\n"
98
+
97
99
  response
98
100
  end
99
101
 
@@ -105,7 +107,7 @@ class Gitswitch
105
107
  def self.switch_global_user(tag = "default")
106
108
  if user = get_user(tag)
107
109
  puts "Switching your .gitconfig user info to \"#{tag}\" tag (#{user[:name]} <#{user[:email]}>)."
108
- git_config(user, {:global => true})
110
+ git_config(user, {global: true})
109
111
  else
110
112
  puts "ERROR: Could not find info for tag \"#{tag}\" in your .gitswitch file"
111
113
  end
@@ -130,7 +132,6 @@ class Gitswitch
130
132
  end
131
133
  end
132
134
 
133
-
134
135
  ##############################################################
135
136
  # TODO: Straight delegation through to Gitswitch::Git
136
137
  def self.in_a_git_repo
@@ -144,5 +145,4 @@ class Gitswitch
144
145
  def self.get_git_user_info(options = {})
145
146
  Gitswitch::Git.get_git_user_info(options)
146
147
  end
147
-
148
148
  end
data/lib/gitswitch/git.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'shellwords' if !String.new.methods.include?('shellescape')
2
2
 
3
- class Gitswitch
4
- class Git
3
+ module Gitswitch
4
+ module Git
5
5
  GIT_BIN = '/usr/bin/env git'
6
6
 
7
7
  def self.version
@@ -15,7 +15,7 @@ class Gitswitch
15
15
  def self.git_config(user, options = {})
16
16
  git_args = 'config --replace-all'
17
17
  git_args += ' --global' if options[:global]
18
-
18
+
19
19
  %x(#{GIT_BIN} #{git_args} user.email #{user[:email].to_s.shellescape})
20
20
  %x(#{GIT_BIN} #{git_args} user.name #{user[:name].to_s.shellescape}) if !user[:name].to_s.empty?
21
21
  end
@@ -23,12 +23,11 @@ class Gitswitch
23
23
  def self.get_git_user_info(options = {})
24
24
  git_args = 'config --get'
25
25
  git_args += ' --global' if options[:global]
26
-
26
+
27
27
  {
28
- :name => %x(#{GIT_BIN} #{git_args} user.name).to_s.chomp,
29
- :email => %x(#{GIT_BIN} #{git_args} user.email).to_s.chomp
30
- }
28
+ name: %x(#{GIT_BIN} #{git_args} user.name).to_s.chomp,
29
+ email: %x(#{GIT_BIN} #{git_args} user.email).to_s.chomp
30
+ }
31
31
  end
32
-
33
32
  end
34
- end
33
+ end
@@ -1,3 +1,3 @@
1
- class Gitswitch
2
- VERSION = "0.4.3"
3
- end
1
+ module Gitswitch
2
+ VERSION = "0.5.1"
3
+ end
data/lib/gitswitch.rb CHANGED
@@ -2,3 +2,8 @@ require 'gitswitch/version'
2
2
  require 'gitswitch/commands'
3
3
  require 'gitswitch/git'
4
4
  require 'gitswitch/cli'
5
+
6
+ module Gitswitch
7
+ EXIT_OK = 0
8
+ EXIT_MISSING_INFO = 1
9
+ end
data/spec/git_spec.rb CHANGED
@@ -9,5 +9,4 @@ describe Gitswitch::Git do
9
9
  it "grabs the local git version" do
10
10
  expect(Gitswitch::Git.version).to match /^\d+\.+\d+/ # Should start off looking like a version number
11
11
  end
12
-
13
- end
12
+ end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Gitswitch do
4
-
5
4
  describe "basics" do
6
5
  it "should have a VERSION" do
7
6
  expect(Gitswitch::VERSION).not_to eq ''
@@ -44,20 +43,15 @@ describe Gitswitch do
44
43
  Gitswitch.create_fresh_gitswitch_file
45
44
  expect(Gitswitch.users.keys.count).to eq 0
46
45
  end
47
-
48
46
  end
49
47
 
50
-
51
48
  describe "weird outlier cases" do
52
49
  it "in a git repo directory with no user info specified, show the global config header and user info" do
53
50
  skip
54
51
  end
55
52
  end
56
53
 
57
-
58
54
  it "shows the current git user credentials" do
59
55
  expect(Gitswitch.current_user_info).to match /^Your git user/
60
56
  end
61
-
62
-
63
57
  end
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,10 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
1
4
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
5
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- require 'rubygems'
4
- require 'gitswitch'
5
-
6
- require 'bundler'
7
- Bundler.setup
8
6
 
7
+ require 'gitswitch'
9
8
 
10
9
  RSpec.configure do |c|
11
10
  end
@@ -18,4 +17,4 @@ end
18
17
 
19
18
  def set_test_entry
20
19
  Gitswitch.set_gitswitch_entry(*get_test_entry)
21
- end
20
+ end
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitswitch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Alba
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2012-04-29 00:00:00.000000000 Z
@@ -25,7 +25,21 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: thor
28
+ name: dry-cli
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: tty-prompt
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ">="
@@ -52,6 +66,20 @@ dependencies:
52
66
  - - ">="
53
67
  - !ruby/object:Gem::Version
54
68
  version: 3.3.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  description: Easily switch your git name/e-mail user info -- Handy for work vs. personal
56
84
  and for pair programming
57
85
  email: joe@joealba.com
@@ -65,9 +93,9 @@ files:
65
93
  - ".bundle/config"
66
94
  - ".document"
67
95
  - ".gemtest"
96
+ - ".github/workflows/tests.yml"
68
97
  - ".gitignore"
69
98
  - ".rspec"
70
- - ".travis.yml"
71
99
  - Gemfile
72
100
  - LICENSE
73
101
  - README.rdoc
@@ -83,10 +111,15 @@ files:
83
111
  - spec/gitswitch_spec.rb
84
112
  - spec/spec_helper.rb
85
113
  - spec/tmp/.gitkeep
86
- homepage: http://github.com/joealba/gitswitch
114
+ homepage: https://github.com/joealba/gitswitch
87
115
  licenses: []
88
- metadata: {}
89
- post_install_message:
116
+ metadata:
117
+ bug_tracker_uri: https://github.com/joealba/gitswitch/issues
118
+ changelog_uri: https://github.com/joealba/gitswitch/blob/main/CHANGELOG.md
119
+ documentation_uri: https://github.com/joealba/gitswitch
120
+ homepage_uri: https://github.com/joealba/gitswitch
121
+ source_code_uri: https://github.com/joealba/gitswitch
122
+ post_install_message:
90
123
  rdoc_options:
91
124
  - "--charset=UTF-8"
92
125
  require_paths:
@@ -102,9 +135,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
135
  - !ruby/object:Gem::Version
103
136
  version: '0'
104
137
  requirements: []
105
- rubyforge_project:
106
- rubygems_version: 2.4.8
107
- signing_key:
138
+ rubygems_version: 3.3.26
139
+ signing_key:
108
140
  specification_version: 4
109
141
  summary: Easy git user switching
110
142
  test_files:
data/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- rvm:
2
- - 1.9.3
3
- - 2.1.7
4
- - 2.2.3
5
- - jruby-19mode
6
- - ruby-head