gitsu 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.licenseignore +2 -0
  3. data/.simplecov +16 -0
  4. data/.travis.yml +19 -2
  5. data/Gemfile +17 -1
  6. data/README.md +36 -7
  7. data/Rakefile +37 -3
  8. data/TODO +4 -2
  9. data/bin/git-su +15 -0
  10. data/bin/git-whoami +15 -0
  11. data/features/add_user.feature +16 -0
  12. data/features/change_user_in_different_scopes.feature +16 -0
  13. data/features/clear_user.feature +16 -0
  14. data/features/configure_default_scope.feature +22 -2
  15. data/features/edit_config.feature +16 -0
  16. data/features/list_users.feature +16 -0
  17. data/features/print_current_user.feature +16 -0
  18. data/features/print_options.feature +16 -0
  19. data/features/step_definitions/gitsu_steps.rb +33 -12
  20. data/features/support/env.rb +16 -0
  21. data/features/switch_to_fully_qualified_user.feature +21 -0
  22. data/features/switch_to_multiple_users.feature +64 -0
  23. data/features/switch_to_stored_user.feature +16 -0
  24. data/gitsu.gemspec +20 -3
  25. data/lib/gitsu.rb +17 -0
  26. data/lib/gitsu/array.rb +31 -0
  27. data/lib/gitsu/config_repository.rb +49 -0
  28. data/lib/gitsu/factory.rb +26 -3
  29. data/lib/gitsu/git.rb +44 -35
  30. data/lib/gitsu/gitsu.rb +27 -3
  31. data/lib/gitsu/runner.rb +16 -0
  32. data/lib/gitsu/shell.rb +17 -2
  33. data/lib/gitsu/switcher.rb +68 -30
  34. data/lib/gitsu/user.rb +80 -11
  35. data/lib/gitsu/user_file.rb +18 -2
  36. data/lib/gitsu/user_list.rb +68 -12
  37. data/lib/gitsu/version.rb +17 -1
  38. data/man/git-su.1.ronn +36 -4
  39. data/spec/gitsu/array_spec.rb +71 -0
  40. data/spec/gitsu/bin_spec.rb +16 -0
  41. data/spec/gitsu/config_repository_spec.rb +67 -0
  42. data/spec/gitsu/git_spec.rb +36 -15
  43. data/spec/gitsu/gitsu_spec.rb +41 -18
  44. data/spec/gitsu/runner_spec.rb +16 -0
  45. data/spec/gitsu/shell_spec.rb +55 -0
  46. data/spec/gitsu/switcher_spec.rb +53 -13
  47. data/spec/gitsu/user_file_spec.rb +91 -0
  48. data/spec/gitsu/user_list_spec.rb +112 -41
  49. data/spec/gitsu/user_spec.rb +97 -0
  50. data/spec/gitsu/version_spec.rb +16 -0
  51. data/spec/spec_helper.rb +16 -0
  52. metadata +45 -28
@@ -1,5 +1,21 @@
1
+ # Gitsu
2
+ # Copyright (C) 2013 drrb
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
1
17
  module GitSu
2
- VERSION = "1.0.0"
18
+ VERSION = "2.0.0"
3
19
 
4
20
  class Version
5
21
  class ParseError < StandardError
@@ -3,7 +3,7 @@ git-su(1) -- Manage your Git Users
3
3
 
4
4
  ## SYNOPSIS
5
5
 
6
- git su [OPTIONS] [user]
6
+ git su [OPTIONS] [user...]
7
7
 
8
8
  ## DESCRIPTION
9
9
 
@@ -12,6 +12,7 @@ Gitsu helps you to manage your projects' Git users.
12
12
  * quickly see which user Git will use to commit
13
13
  * quickly switch between Git users
14
14
  * configure a list of Git users to switch between
15
+ * switch to multiple users at once for pairing
15
16
 
16
17
  ## OPTIONS
17
18
 
@@ -37,15 +38,18 @@ Gitsu helps you to manage your projects' Git users.
37
38
 
38
39
  Gitsu supports the following configuration options, specified either in Git config files, or by executing `git config`:
39
40
 
40
- git-su.defaultSelectScope
41
+ gitsu.defaultSelectScope
41
42
  One of "local", "global", or "system" (without quotes). Specifies the default scope that the user is switched in when `git su` is run.
42
43
 
44
+ gitsu.groupEmailAddress
45
+ The group email address to use when switching to multiple users. E.g., if you specify "developers@company.org", pairing email addresses will look like "me+you+developers@example.org". Defaults to "dev@example.com".
46
+
43
47
  color.ui
44
48
  Gitsu respects the value of color.ui in the same way Git does. That is, output is colored only if color.ui is set to true, and stdout is a tty.
45
49
 
46
50
  ## HOMEPAGE
47
51
 
48
- http://drrb.github.com/gitsu
52
+ http://drrb.github.io/gitsu
49
53
 
50
54
  ## EXAMPLES
51
55
 
@@ -110,10 +114,38 @@ To clear the user for a specific scope
110
114
 
111
115
  `Clearing global user`
112
116
 
117
+ ### Pairing
118
+
119
+ Gitsu supports switching to multiple users at once. When pairing, this lets you switch
120
+ to attribute both users in each commit.
121
+
122
+ E.g., to switch to two configured users:
123
+
124
+ `$ git su joe rack`
125
+
126
+ `Switched local user to Joseph Porter KCB and Raphe Rackstraw <jporter+rrack+dev@example.com>`
113
127
 
114
128
  ## AUTHOR
115
129
 
116
- drrb at the git hub
130
+ drrrrrrrrrrrb at g mail
131
+
132
+ ## LICENSE
133
+
134
+ Gitsu
135
+ Copyright (C) 2013 drrb
136
+
137
+ This program is free software: you can redistribute it and/or modify
138
+ it under the terms of the GNU General Public License as published by
139
+ the Free Software Foundation, either version 3 of the License, or
140
+ (at your option) any later version.
141
+
142
+ This program is distributed in the hope that it will be useful,
143
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
144
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
145
+ GNU General Public License for more details.
146
+
147
+ You should have received a copy of the GNU General Public License
148
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
117
149
 
118
150
  ## SEE ALSO
119
151
 
@@ -0,0 +1,71 @@
1
+ # Gitsu
2
+ # Copyright (C) 2013 drrb
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require 'spec_helper'
18
+
19
+ describe Array do
20
+ describe "#to_sentence" do
21
+ context "when array is empty" do
22
+ let(:array) { [] }
23
+
24
+ it "returns an empty string" do
25
+ array.to_sentence.should == ""
26
+ end
27
+ end
28
+
29
+ context "when array has one element" do
30
+ let(:array) { [:apple] }
31
+
32
+ it "returns the element as a string" do
33
+ array.to_sentence.should == "apple"
34
+ end
35
+ end
36
+
37
+ context "when array has two elements" do
38
+ let(:array) { %w[apples oranges] }
39
+
40
+ it "returns the elements with an 'and' in between" do
41
+ array.to_sentence.should == "apples and oranges"
42
+ end
43
+ end
44
+
45
+ context "when array has multiple elements" do
46
+ let(:array) { %w[apples oranges bananas] }
47
+
48
+ it "returns the elements as a sentence" do
49
+ array.to_sentence.should == "apples, oranges and bananas"
50
+ end
51
+ end
52
+ end
53
+
54
+ describe "#pluralize" do
55
+ context "when the array has one element" do
56
+ let(:array) { [:apple] }
57
+
58
+ it "returns the word unchanged" do
59
+ array.pluralize("fruit").should == "fruit"
60
+ end
61
+ end
62
+
63
+ context "when the array has more than one element" do
64
+ let(:array) { [:apple, :orange] }
65
+
66
+ it "returns the word with an 's' on the end" do
67
+ array.pluralize("fruit").should == "fruits"
68
+ end
69
+ end
70
+ end
71
+ end
@@ -1,3 +1,19 @@
1
+ # Gitsu
2
+ # Copyright (C) 2013 drrb
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
1
17
  require 'spec_helper'
2
18
 
3
19
  describe "git-su executable" do
@@ -0,0 +1,67 @@
1
+ # Gitsu
2
+ # Copyright (C) 2013 drrb
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require 'spec_helper'
18
+
19
+ module GitSu
20
+ describe ConfigRepository do
21
+ let(:git) { double('git') }
22
+ let(:repository) { ConfigRepository.new(git) }
23
+
24
+ describe "#get" do
25
+ it "looks up the specified config in Git" do
26
+ git.should_receive(:get_config).with(:derived, "config.key").and_return "value"
27
+ repository.get("config.key").should == "value"
28
+ end
29
+ end
30
+
31
+ describe "#group_email_address" do
32
+ context "when a group email address is configured" do
33
+ it "returns the configured group email address" do
34
+ git.should_receive(:get_config).with(:derived, "gitsu.groupEmailAddress").and_return("pairs@example.org")
35
+ repository.group_email_address.should == "pairs@example.org"
36
+ end
37
+ end
38
+ context "when no group email address is configured" do
39
+ it "returns the placeholder group email address" do
40
+ git.should_receive(:get_config).with(:derived, "gitsu.groupEmailAddress").and_return("")
41
+ repository.group_email_address.should == "dev@example.com"
42
+ end
43
+ end
44
+ end
45
+
46
+ describe "#default_select_scope" do
47
+ context "when a default selecton scope is configured" do
48
+ it "returns the configured default scope" do
49
+ git.should_receive(:get_config).with(:derived, "gitsu.defaultSelectScope").and_return("global")
50
+ repository.default_select_scope.should == :global
51
+ end
52
+ end
53
+ context "when no default selection scope is configured" do
54
+ it "returns the conventional default scope (local)" do
55
+ git.should_receive(:get_config).with(:derived, "gitsu.defaultSelectScope").and_return("")
56
+ repository.default_select_scope.should == :local
57
+ end
58
+ end
59
+ context "when an invalid default selection scope is configured" do
60
+ it "dies noisily" do
61
+ git.should_receive(:get_config).with(:derived, "gitsu.defaultSelectScope").and_return("xxxxxx")
62
+ expect {repository.default_select_scope}.to raise_error(ConfigRepository::InvalidConfigError)
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -1,3 +1,19 @@
1
+ # Gitsu
2
+ # Copyright (C) 2013 drrb
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
1
17
  require 'spec_helper'
2
18
 
3
19
  module GitSu
@@ -165,23 +181,21 @@ module GitSu
165
181
  end
166
182
  end
167
183
 
168
- describe "#default_select_scope" do
169
- context "when a default selecton scope is configured" do
170
- it "returns the configured default scope" do
171
- shell.should_receive(:capture).with("git config git-su.defaultSelectScope").and_return("global")
172
- git.default_select_scope.should == :global
173
- end
184
+ describe "#get_config" do
185
+ it "looks up config in Git in the specified scope" do
186
+ shell.should_receive(:capture).with("git config --global config.key").and_return "value"
187
+ git.get_config(:global, "config.key").should == "value"
174
188
  end
175
- context "when no default selection scope is configured" do
176
- it "returns the conventional default scope (local)" do
177
- shell.should_receive(:capture).with("git config git-su.defaultSelectScope").and_return("")
178
- git.default_select_scope.should == :local
179
- end
189
+ it "caches the result" do
190
+ shell.should_receive(:capture).with("git config --global config.key").and_return "value"
191
+ git.get_config(:global, "config.key").should == "value"
192
+ git.get_config(:global, "config.key").should == "value"
180
193
  end
181
- context "when an invalid default selection scope is configured" do
182
- it "dies noisily" do
183
- shell.should_receive(:capture).with("git config git-su.defaultSelectScope").and_return("xxxxxx")
184
- expect {git.default_select_scope}.to raise_error(Git::InvalidConfigError)
194
+
195
+ context "when :derived scope is specified" do
196
+ it "looks up config in Git without specifying the scope" do
197
+ shell.should_receive(:capture).with("git config config.key").and_return "value"
198
+ git.get_config(:derived, "config.key").should == "value"
185
199
  end
186
200
  end
187
201
  end
@@ -192,5 +206,12 @@ module GitSu
192
206
  git.commit("file.dat", "Committing changes")
193
207
  end
194
208
  end
209
+
210
+ describe "#list_files" do
211
+ it "calls 'git ls-files' with the specified flags" do
212
+ shell.should_receive(:capture).with("git ls-files --modified --cached").and_return "file1\nfile2\n"
213
+ git.list_files(:modified, :cached).should == [ "file1", "file2" ]
214
+ end
215
+ end
195
216
  end
196
217
  end
@@ -1,3 +1,19 @@
1
+ # Gitsu
2
+ # Copyright (C) 2013 drrb
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
1
17
  require 'spec_helper'
2
18
 
3
19
  module GitSu
@@ -10,22 +26,29 @@ module GitSu
10
26
  context 'when query string provided' do
11
27
  context 'when no scope specified' do
12
28
  it 'switches to the specified user in the default scope' do
13
- switcher.should_receive(:request).with('Joe Bloggs', :default)
14
- gitsu.go ['Joe', 'Bloggs']
29
+ switcher.should_receive(:request).with(:default, 'Joe Bloggs')
30
+ gitsu.go ['Joe Bloggs']
31
+ end
32
+ end
33
+
34
+ context 'when multiple users specified' do
35
+ it 'switches to all users' do
36
+ switcher.should_receive(:request).with(:default, 'Jimmy Baggs', 'Joe Bloggs')
37
+ gitsu.go ['Jimmy Baggs', 'Joe Bloggs']
15
38
  end
16
39
  end
17
40
 
18
41
  context 'when local scope specified' do
19
42
  context 'as short option (-l)' do
20
43
  it 'switches to the specified user in the default scope' do
21
- switcher.should_receive(:request).with('Joe Bloggs', :local)
22
- gitsu.go ['Joe', 'Bloggs', "-l"]
44
+ switcher.should_receive(:request).with(:local, 'Joe Bloggs')
45
+ gitsu.go ['Joe Bloggs', "-l"]
23
46
  end
24
47
  end
25
48
  context 'as long option (--local)' do
26
49
  it 'switches to the specified user in the default scope' do
27
- switcher.should_receive(:request).with('Joe Bloggs', :local)
28
- gitsu.go ['Joe', 'Bloggs', "--local"]
50
+ switcher.should_receive(:request).with(:local, 'Joe Bloggs')
51
+ gitsu.go ['Joe Bloggs', "--local"]
29
52
  end
30
53
  end
31
54
  end
@@ -33,14 +56,14 @@ module GitSu
33
56
  context 'when global scope specified' do
34
57
  context 'as short option (-g)' do
35
58
  it 'switches to the specified user in the global scope' do
36
- switcher.should_receive(:request).with('Joe Bloggs', :global)
37
- gitsu.go ['Joe', 'Bloggs', "-g"]
59
+ switcher.should_receive(:request).with(:global, 'Joe Bloggs')
60
+ gitsu.go ['Joe Bloggs', "-g"]
38
61
  end
39
62
  end
40
63
  context 'as long option (--global)' do
41
64
  it 'switches to the specified user in the global scope' do
42
- switcher.should_receive(:request).with('Joe Bloggs', :global)
43
- gitsu.go ['Joe', 'Bloggs', "--global"]
65
+ switcher.should_receive(:request).with(:global, 'Joe Bloggs')
66
+ gitsu.go ['Joe Bloggs', "--global"]
44
67
  end
45
68
  end
46
69
  end
@@ -48,24 +71,24 @@ module GitSu
48
71
  context 'when system scope specified' do
49
72
  context 'as short option (-s)' do
50
73
  it 'switches to the specified user in the system scope' do
51
- switcher.should_receive(:request).with('Joe Bloggs', :system)
52
- gitsu.go ['Joe', 'Bloggs', "-s"]
74
+ switcher.should_receive(:request).with(:system, 'Joe Bloggs')
75
+ gitsu.go ['Joe Bloggs', "-s"]
53
76
  end
54
77
  end
55
78
  context 'as long option (--system)' do
56
79
  it 'switches to the specified user in the system scope' do
57
- switcher.should_receive(:request).with('Joe Bloggs', :system)
58
- gitsu.go ['Joe', 'Bloggs', "--system"]
80
+ switcher.should_receive(:request).with(:system, 'Joe Bloggs')
81
+ gitsu.go ['Joe Bloggs', "--system"]
59
82
  end
60
83
  end
61
84
  end
62
85
 
63
86
  context 'when multiple scopes specified' do
64
87
  it 'switches to the specified user in the specified scopes' do
65
- switcher.should_receive(:request).with('Joe Bloggs', :local)
66
- switcher.should_receive(:request).with('Joe Bloggs', :global)
67
- switcher.should_receive(:request).with('Joe Bloggs', :system)
68
- gitsu.go ['Joe', 'Bloggs', "--local", "--global", "--system"]
88
+ switcher.should_receive(:request).with(:local, 'Joe Bloggs')
89
+ switcher.should_receive(:request).with(:global, 'Joe Bloggs')
90
+ switcher.should_receive(:request).with(:system, 'Joe Bloggs')
91
+ gitsu.go ['Joe Bloggs', "--local", "--global", "--system"]
69
92
  end
70
93
  end
71
94
  end
@@ -1,3 +1,19 @@
1
+ # Gitsu
2
+ # Copyright (C) 2013 drrb
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
1
17
  require 'spec_helper'
2
18
 
3
19
  module GitSu