pivotal_git_scripts 1.1.0 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  pkg/*
2
2
  *.gem
3
3
  .bundle
4
+ spec/tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in pivotal_git_scripts.gemspec
4
+ gemspec
5
+
6
+ gem "rake"
7
+ gem "bundler"
8
+ gem "rspec"
9
+ gem "unindent"
@@ -0,0 +1,29 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ pivotal_git_scripts (1.1.2)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.1.3)
10
+ rake (0.9.2.2)
11
+ rspec (2.8.0)
12
+ rspec-core (~> 2.8.0)
13
+ rspec-expectations (~> 2.8.0)
14
+ rspec-mocks (~> 2.8.0)
15
+ rspec-core (2.8.0)
16
+ rspec-expectations (2.8.0)
17
+ diff-lcs (~> 1.1.2)
18
+ rspec-mocks (2.8.0)
19
+ unindent (1.0)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ bundler
26
+ pivotal_git_scripts!
27
+ rake
28
+ rspec
29
+ unindent
data/README.md CHANGED
@@ -2,10 +2,14 @@
2
2
 
3
3
  These scripts are helpers for managing developer workflow when using git repos hosted on GitHub. Install as a rubygem and they can be run as standard git commands like `git about`.
4
4
 
5
- ## Installation
5
+ ## Gem Installation
6
6
 
7
7
  $ gem install pivotal_git_scripts
8
8
 
9
+ ## System Wide Installation
10
+
11
+ $ cd /usr/local/bin && curl -L http://github.com/pivotal/git_scripts/tarball/master | gunzip | tar xvf - --strip=2
12
+
9
13
  ## git-about
10
14
 
11
15
  `git about` shows settings set by `git pair` and `git project`
@@ -28,10 +32,11 @@ Use `git pair` to set the git config user info that sets the commit user metadat
28
32
  email:
29
33
  prefix: pair
30
34
  domain: pivotallabs.com
35
+ #global: true
31
36
 
32
37
  You can put the .pairs file in your project repo root directory and check it into git, or you can put it in your ~ directory so it's available to all projects on the workstation.
33
38
 
34
- By default this command affects the configuration in the current project (.git/config). Use the `--global` option to set the global git configuration for all projects (~/.gitconfig).
39
+ By default this command affects the configuration in the current project (.git/config). Use the `--global` option or add 'global: true' to your pairs file to set the global git configuration for all projects (~/.gitconfig).
35
40
 
36
41
  ## git-project
37
42
 
@@ -43,4 +48,11 @@ This script sets the user account you will use to access repos hosted on github.
43
48
  User git
44
49
  IdentityFile /Users/pivotal/.ssh/id_github_current
45
50
 
46
- Copyright (c) 2010 Pivotal Labs. This software is licensed under the MIT License.
51
+ Authors
52
+ ====
53
+ Copyright (c) 2010 [Pivotal Labs](http://pivotallabs.com). This software is licensed under the MIT License.
54
+
55
+ ### [Contributors](https://github.com/pivotal/git_scripts/contributors)
56
+ - lots of pivots :)
57
+ - [James Sanders](https://github.com/jsanders)
58
+ - [Todd Persen](https://github.com/toddboom)
data/Rakefile CHANGED
@@ -1,2 +1,22 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
1
+ require "bundler/gem_tasks"
2
+
3
+ task :default do
4
+ sh "bundle exec rspec spec"
5
+ end
6
+
7
+ # extracted from https://github.com/grosser/project_template
8
+ rule /^version:bump:.*/ do |t|
9
+ sh "git status | grep 'nothing to commit'" # ensure we are not dirty
10
+ index = ['major', 'minor','patch'].index(t.name.split(':').last)
11
+ file = 'lib/pivotal_git_scripts/version.rb'
12
+
13
+ version_file = File.read(file)
14
+ old_version, *version_parts = version_file.match(/(\d+)\.(\d+)\.(\d+)/).to_a
15
+ version_parts[index] = version_parts[index].to_i + 1
16
+ version_parts[2] = 0 if index < 2 # remove patch for minor
17
+ version_parts[1] = 0 if index < 1 # remove minor for major
18
+ new_version = version_parts * '.'
19
+ File.open(file,'w'){|f| f.write(version_file.sub(old_version, new_version)) }
20
+
21
+ sh "bundle && git add #{file} Gemfile.lock && git commit -m 'bump version to #{new_version}'"
22
+ end
@@ -1,14 +1,13 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- config = `git config -l`
4
2
  user_name = `git config --get user.name`
5
- user_name = "NONE" if user_name.length == 0
3
+ user_name = "NONE" if user_name.strip.empty?
4
+
6
5
  user_email = `git config --get user.email`
7
- user_email = "NONE" if user_email.length == 0
6
+ user_email = "NONE" if user_email.strip.empty?
8
7
 
9
8
  begin
10
- keyfile = File.readlink(File.expand_path("~/.ssh/id_github_current"))
11
- project = keyfile =~ %r{id_github_(\w+)} ? $1 : "NONE"
9
+ key_file = File.readlink(File.expand_path("~/.ssh/id_github_current"))
10
+ project = (key_file =~ %r{id_github_(\w+)} ? $1 : "NONE")
12
11
  rescue Errno::ENOENT
13
12
  project = "NONE"
14
13
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Configures the git author to a list of developers when pair programming,
4
4
  # alphabetized on first name
5
- #
5
+ #
6
6
  # Usage: git pair ls gw (Sets the repo specific author to 'Greg Woodward & Loren Siebert')
7
7
  # git pair (Unsets the repo specific author so the git global config takes effect)
8
8
  # git pair --global ls gw (Sets the global author to 'Greg Woodward & Loren Siebert')
@@ -14,10 +14,8 @@
14
14
 
15
15
  require 'yaml'
16
16
 
17
- unless File.exists?(".git")
18
- puts "This doesn't look like a git repository."
19
- exit 1
20
- end
17
+ git_dir = `git rev-parse --git-dir`.chomp
18
+ exit 1 unless File.exists?(git_dir)
21
19
 
22
20
  ## Configuration
23
21
 
@@ -31,6 +29,8 @@ def get_pairs_config
31
29
  candidate_file_path = File.join("..", candidate_file_path)
32
30
  end
33
31
  end
32
+ puts pairs_file_path.inspect
33
+
34
34
  unless pairs_file_path
35
35
  puts <<-INSTRUCTIONS
36
36
  Could not find a .pairs file. Create a YAML file in your project or home directory.
@@ -51,11 +51,17 @@ INSTRUCTIONS
51
51
  pairs_file_path ? YAML.load_file(pairs_file_path) : {}
52
52
  end
53
53
 
54
+ def get_global_config(config)
55
+ if ARGV.delete("--global") || config["global"]
56
+ "--global"
57
+ end
58
+ end
59
+
54
60
  ## End of configuration
55
61
  #######################################################################
56
62
 
57
- global_config_string = ARGV.delete("--global").to_s
58
63
  config = get_pairs_config
64
+ global_config_string = get_global_config(config)
59
65
  authors = ARGV.map do |initials|
60
66
  if full_name = config['pairs'][initials.downcase]
61
67
  full_name
@@ -81,22 +87,27 @@ if authors.any?
81
87
  else
82
88
  authors = names[0..-2].join(", ") + " & " + names.last
83
89
  end
84
- email =
85
- if email_prefix = config['email']['prefix']
86
- "#{([email_prefix] + emails).join('+')}@#{config['email']['domain']}"
87
- else
88
- config['email']
89
- end
90
+
91
+ email = if config['email'].is_a?(Hash)
92
+ "#{([config['email']['prefix']] + emails).compact.join('+')}@#{config['email']['domain']}"
93
+ else
94
+ config['email']
95
+ end
96
+
97
+ initials = ARGV.join(' ')
98
+
90
99
  system(%Q{git config #{global_config_string} user.name "#{authors}"})
91
100
  system(%Q{git config #{global_config_string} user.email "#{email}"})
101
+ system(%Q{git config #{global_config_string} user.initials "#{initials}"})
92
102
  else
93
103
  system("git config #{global_config_string} --unset user.name")
94
104
  system("git config #{global_config_string} --unset user.email")
105
+ system("git config #{global_config_string} --unset user.initials")
95
106
  puts "Unset #{global_config_string} user.name and user.email"
96
107
  end
97
108
 
98
109
  global_name_setting = `git config --global --get-regexp '^user\.name'`
99
- local_name_setting = `git config -f .git/config --get-regexp '^user\.name'`
110
+ local_name_setting = `git config -f #{git_dir}/config --get-regexp '^user\.name'`
100
111
  if global_name_setting.length > 0 && local_name_setting.length > 0
101
112
  puts "NOTE: Overriding global user.name setting with local."
102
113
  end
@@ -105,7 +116,7 @@ puts "local: #{local_name_setting}" if local_name_setting.length > 0
105
116
 
106
117
 
107
118
  global_email_setting = `git config --global --get-regexp '^user\.email'`
108
- local_email_setting = `git config -f .git/config --get-regexp '^user\.email'`
119
+ local_email_setting = `git config -f #{git_dir}/config --get-regexp '^user\.email'`
109
120
  if global_email_setting.length > 0 && local_email_setting.length > 0
110
121
  puts "NOTE: Overriding global user.email setting with local."
111
122
  end
@@ -0,0 +1,3 @@
1
+ module PivotalGitScripts
2
+ VERSION = "1.1.2"
3
+ end
@@ -1,17 +1,25 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.push File.expand_path("../lib", __FILE__)
3
+ require "pivotal_git_scripts/version"
2
4
 
3
5
  Gem::Specification.new do |s|
4
6
  s.name = "pivotal_git_scripts"
5
- s.version = "1.1.0"
6
- s.date = Time.now.strftime('%Y-%m-%d')
7
- s.platform = Gem::Platform::RUBY
7
+ s.version = PivotalGitScripts::VERSION
8
8
  s.authors = ["Pivotal Labs"]
9
9
  s.email = ["gems@pivotallabs.com"]
10
10
  s.homepage = "http://github.com/pivotal/git_scripts"
11
11
  s.summary = %q{Developer git workflow convenience scripts}
12
12
  s.description = %q{These scripts are helpers for managing developer workflow when using git repos hosted on GitHub.}
13
- s.has_rdoc = false
13
+
14
+ s.rubyforge_project = "pivotal_git_scripts"
14
15
 
15
16
  s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+ s.license = "MIT"
21
+
22
+ # specify any dependencies here; for example:
23
+ # s.add_development_dependency "rspec"
24
+ # s.add_runtime_dependency "rest-client"
17
25
  end
@@ -0,0 +1,213 @@
1
+ require "unindent"
2
+
3
+ describe "CLI" do
4
+ before :all do
5
+ # use local scripts
6
+ ENV["PATH"] = "#{File.join(File.dirname(__FILE__),"..","bin")}:#{ENV["PATH"]}"
7
+ end
8
+
9
+ def run(command, options={})
10
+ result = `#{command}`
11
+ raise "FAILED #{command} : #{result}" if $?.success? == !!options[:fail]
12
+ result
13
+ end
14
+
15
+ def write(file, content)
16
+ File.open(file, 'w'){|f| f.write content }
17
+ end
18
+
19
+ around do |example|
20
+ dir = "spec/tmp"
21
+ run "rm -rf #{dir}"
22
+ run "mkdir #{dir}"
23
+
24
+ # use fake home for .ssh hacks
25
+ run "mkdir #{dir}/home"
26
+ ENV["HOME"] = File.expand_path("#{dir}/home")
27
+
28
+ Dir.chdir dir do
29
+ run "touch a && git init && git add . && git commit -am 'initial'"
30
+ example.run
31
+ end
32
+ end
33
+
34
+ describe "about" do
35
+ it "lists the user" do
36
+ run "git config user.name NAME"
37
+ run("git about").should =~ /git user:\s+NAME/
38
+ end
39
+
40
+ it "lists the user as NONE if there is none" do
41
+ run "git config user.name ''"
42
+ run("git about").should =~ /git user:\s+NONE/
43
+ end
44
+
45
+ it "lists the email" do
46
+ run "git config user.email EMAIL"
47
+ run("git about").should =~ /git email:\s+EMAIL/
48
+ end
49
+
50
+ it "lists the email as NONE if there is none" do
51
+ run "git config user.email ''"
52
+ run("git about").should =~ /git email:\s+NONE/
53
+ end
54
+
55
+ it "does not find a project" do
56
+ run("git about").should =~ /GitHub project:\s+NONE/
57
+ end
58
+
59
+ context "with github project" do
60
+ before do
61
+ run "mkdir home/.ssh"
62
+ run "touch home/.ssh/id_github_foo"
63
+ run "ln -s home/.ssh/id_github_foo home/.ssh/id_github_current"
64
+ end
65
+
66
+ it "finds a project" do
67
+ run("git about").should =~ /GitHub project:\s+foo/
68
+ end
69
+ end
70
+ end
71
+
72
+ describe "pair" do
73
+ def expect_config(result, name, initials, email, options={})
74
+ global = "cd /tmp && " if options[:global]
75
+ run("#{global}git config user.name").should == "#{name}\n"
76
+ run("#{global}git config user.initials").should == "#{initials}\n"
77
+ run("#{global}git config user.email").should == "#{email}\n"
78
+
79
+ prefix = (options[:global] ? "global: " : "local: ")
80
+ result.should include "#{prefix}user.name #{name}"
81
+ #result.should include "#{prefix}user.initials #{initials}" # TODO
82
+ result.should include "#{prefix}user.email #{email}"
83
+ end
84
+
85
+ context "with .pairs file" do
86
+ before do
87
+ write ".pairs", <<-YAML.unindent
88
+ pairs:
89
+ ab: Aa Bb
90
+ bc: Bb Cc
91
+ cd: Cc Dd
92
+
93
+ email:
94
+ prefix: the-pair
95
+ domain: the-host.com
96
+ YAML
97
+ end
98
+
99
+ describe "global" do
100
+ it "sets pairs globally when global: true is set" do
101
+ write ".pairs", File.read(".pairs") + "\nglobal: true"
102
+ result = run "git pair ab"
103
+ expect_config result, "Aa Bb", "ab", "the-pair+aa@the-host.com", :global => true
104
+ end
105
+
106
+ it "sets pairs globally when --global is given" do
107
+ result = run "git pair ab --global"
108
+ result.should include "global: user.name Aa Bb"
109
+ expect_config result, "Aa Bb", "ab", "the-pair+aa@the-host.com", :global => true
110
+ end
111
+
112
+ it "unsets global config when no argument is passed" do
113
+ run "git pair ab --global"
114
+ run "git pair ab"
115
+ result = run "git pair --global"
116
+ #result.should include "Unset --global user.name, user.email and user.initials"
117
+ expect_config result, "Aa Bb", "ab", "the-pair+aa@the-host.com"
118
+ result.should_not include("global:")
119
+ end
120
+ end
121
+
122
+ it "can set a single user as pair" do
123
+ result = run "git pair ab"
124
+ expect_config result, "Aa Bb", "ab", "the-pair+aa@the-host.com"
125
+ end
126
+
127
+ it "can set a 2 users as pair" do
128
+ result = run "git pair ab bc"
129
+ expect_config result, "Aa Bb & Bb Cc", "ab bc", "the-pair+aa+bb@the-host.com"
130
+ end
131
+
132
+ it "can set a n users as pair" do
133
+ result = run "git pair ab bc cd"
134
+ expect_config result, "Aa Bb, Bb Cc & Cc Dd", "ab bc cd", "the-pair+aa+bb+cc@the-host.com"
135
+ end
136
+
137
+ it "fails when there is no .git in the tree" do
138
+ run "rm -f /tmp/pairs"
139
+ run "cp .pairs /tmp"
140
+ Dir.chdir "/tmp" do
141
+ result = run "git pair ab 2>&1", :fail => true
142
+ result.should include("Not a git repository (or any of the parent directories)")
143
+ end
144
+ run "rm -f /tmp/pairs"
145
+ end
146
+
147
+ it "finds .pairs file in lower parent folder" do
148
+ run "mkdir foo"
149
+ Dir.chdir "foo" do
150
+ result = run "git pair ab"
151
+ expect_config result, "Aa Bb", "ab", "the-pair+aa@the-host.com"
152
+ end
153
+ end
154
+
155
+ it "unsets local config when no argument is passed" do
156
+ run "git pair ab --global"
157
+ run "git pair bc"
158
+ result = run "git pair"
159
+ #result.should include "Unset user.name, user.email and user.initials" #TODO
160
+ expect_config result, "Aa Bb", "ab", "the-pair+aa@the-host.com", :global => true
161
+ result.should_not include("local:")
162
+ end
163
+
164
+ it "uses hard email when given" do
165
+ write ".pairs", File.read(".pairs").sub(/email:.*/m, "email: foo@bar.com")
166
+ result = run "git pair ab"
167
+ expect_config result, "Aa Bb", "ab", "foo@bar.com"
168
+ end
169
+
170
+ it "uses no email prefix when only host is given" do
171
+ write ".pairs", File.read(".pairs").sub(/email:.*/m, "email:\n domain: foo.com")
172
+ result = run "git pair ab"
173
+ expect_config result, "Aa Bb", "ab", "aa@foo.com"
174
+ end
175
+
176
+ it "fails with unknown initials" do
177
+ result = run "git pair xx", :fail => true
178
+ result.should include("Couldn't find author name for initials: xx")
179
+ end
180
+
181
+ it "uses alternate email prefix" do
182
+ write ".pairs", File.read(".pairs").sub(/ab:.*/, "ab: Aa Bb; blob")
183
+ result = run "git pair ab"
184
+ expect_config result, "Aa Bb", "ab", "the-pair+blob@the-host.com"
185
+ end
186
+ end
187
+
188
+ context "without a .pairs file in the tree" do
189
+ around do |example|
190
+ Dir.chdir "/tmp" do
191
+ run "rm -f .pairs"
192
+ dir = "git_stats_test"
193
+ run "rm -rf #{dir}"
194
+ run "mkdir #{dir}"
195
+ Dir.chdir dir do
196
+ run "git init"
197
+ example.run
198
+ end
199
+ run "rm -rf #{dir}"
200
+ end
201
+ end
202
+
203
+ it "fails if it cannot find a pairs file" do
204
+ run "git pair ab", :fail => true
205
+ end
206
+
207
+ it "prints instructions" do
208
+ result = run "git pair ab", :fail => true
209
+ result.should include("Could not find a .pairs file. Create a YAML file in your project or home directory.")
210
+ end
211
+ end
212
+ end
213
+ end
metadata CHANGED
@@ -1,38 +1,32 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: pivotal_git_scripts
3
- version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease: false
6
- segments:
7
- - 1
8
- - 1
9
- - 0
10
- version: 1.1.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.2
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Pivotal Labs
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2010-11-15 00:00:00 -08:00
19
- default_executable:
12
+ date: 2012-03-14 00:00:00.000000000Z
20
13
  dependencies: []
21
-
22
- description: These scripts are helpers for managing developer workflow when using git repos hosted on GitHub.
23
- email:
14
+ description: These scripts are helpers for managing developer workflow when using
15
+ git repos hosted on GitHub.
16
+ email:
24
17
  - gems@pivotallabs.com
25
- executables:
18
+ executables:
26
19
  - git-about
27
20
  - git-pair
28
21
  - git-project
29
22
  - git-superpull
30
23
  extensions: []
31
-
32
24
  extra_rdoc_files: []
33
-
34
- files:
25
+ files:
35
26
  - .gitignore
27
+ - .rspec
28
+ - Gemfile
29
+ - Gemfile.lock
36
30
  - MIT.LICENSE
37
31
  - README.md
38
32
  - Rakefile
@@ -40,40 +34,33 @@ files:
40
34
  - bin/git-pair
41
35
  - bin/git-project
42
36
  - bin/git-superpull
37
+ - lib/pivotal_git_scripts/version.rb
43
38
  - pivotal_git_scripts.gemspec
44
- has_rdoc: true
39
+ - spec/cli_spec.rb
45
40
  homepage: http://github.com/pivotal/git_scripts
46
- licenses: []
47
-
41
+ licenses:
42
+ - MIT
48
43
  post_install_message:
49
44
  rdoc_options: []
50
-
51
- require_paths:
45
+ require_paths:
52
46
  - lib
53
- required_ruby_version: !ruby/object:Gem::Requirement
47
+ required_ruby_version: !ruby/object:Gem::Requirement
54
48
  none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- hash: 3
59
- segments:
60
- - 0
61
- version: "0"
62
- required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
54
  none: false
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- hash: 3
68
- segments:
69
- - 0
70
- version: "0"
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
71
59
  requirements: []
72
-
73
- rubyforge_project:
74
- rubygems_version: 1.3.7
60
+ rubyforge_project: pivotal_git_scripts
61
+ rubygems_version: 1.8.6
75
62
  signing_key:
76
63
  specification_version: 3
77
64
  summary: Developer git workflow convenience scripts
78
- test_files: []
79
-
65
+ test_files:
66
+ - spec/cli_spec.rb