git-smart 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,9 +1,10 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gem 'colorize'
4
4
 
5
5
  group :development do
6
6
  gem 'rspec'
7
- gem 'rcov'
7
+ gem 'simplecov'
8
8
  gem 'rocco'
9
+ gem 'rake'
9
10
  end
@@ -1,10 +1,12 @@
1
1
  GEM
2
- remote: http://rubygems.org/
2
+ remote: https://rubygems.org/
3
3
  specs:
4
4
  colorize (0.5.8)
5
5
  diff-lcs (1.1.3)
6
+ docile (1.1.1)
7
+ multi_json (1.8.2)
6
8
  mustache (0.99.4)
7
- rcov (0.9.11)
9
+ rake (10.0.3)
8
10
  redcarpet (1.17.2)
9
11
  rocco (0.8.2)
10
12
  mustache
@@ -17,12 +19,18 @@ GEM
17
19
  rspec-expectations (2.7.0)
18
20
  diff-lcs (~> 1.1.2)
19
21
  rspec-mocks (2.7.0)
22
+ simplecov (0.8.2)
23
+ docile (~> 1.1.0)
24
+ multi_json
25
+ simplecov-html (~> 0.8.0)
26
+ simplecov-html (0.8.0)
20
27
 
21
28
  PLATFORMS
22
29
  ruby
23
30
 
24
31
  DEPENDENCIES
25
32
  colorize
26
- rcov
33
+ rake
27
34
  rocco
28
35
  rspec
36
+ simplecov
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.7
1
+ 0.1.10
@@ -1,16 +1,41 @@
1
+ # encoding: utf-8
2
+
3
+ require 'yaml'
4
+ require 'pathname'
5
+
1
6
  class GitRepo
2
7
  def initialize(dir)
3
8
  @dir = dir
4
- if !File.exists? File.join(@dir, ".git")
9
+ unless File.directory?(git_dir)
10
+ raise GitSmart::RunFailed.new(
11
+ <<-MSG.gsub(/^\s+/, '')
12
+ You need to run this from within a Git directory.
13
+ Current working directory: #{File.expand_path(dir)}
14
+ Expected .git directory: #{git_dir}
15
+ MSG
16
+ )
17
+ end
18
+ end
19
+
20
+ def git_dir
21
+ gitdir = Pathname.new(@dir).join('.git')
22
+
23
+ unless File.exists?(gitdir)
5
24
  @dir = git('rev-parse', '--show-toplevel').chomp
6
- if !File.exists? File.join(@dir, ".git")
7
- raise GitSmart::RunFailed.new("You need to run this from within a git directory")
8
- end
25
+ gitdir = Pathname.new(@dir).join('.git') unless @dir.empty?
26
+ end
27
+
28
+ if File.file?(gitdir)
29
+ submodule = YAML.load_file(gitdir)
30
+ gitdir = Pathname.new(@dir).join(submodule['gitdir']).to_path
9
31
  end
32
+
33
+ gitdir
10
34
  end
11
35
 
12
36
  def current_branch
13
- File.read(File.join(@dir, ".git", "HEAD")).strip.sub(/^.*refs\/heads\//, '')
37
+ head_file = File.join(git_dir, 'HEAD')
38
+ File.read(head_file).strip.sub(%r(^.*refs/heads/), '')
14
39
  end
15
40
 
16
41
  def sha(ref)
@@ -139,6 +164,7 @@ class GitRepo
139
164
  private
140
165
 
141
166
  def exec_git(*args)
167
+ return if @dir.empty?
142
168
  Dir.chdir(@dir) {
143
169
  SafeShell.execute('git', *args)
144
170
  }
@@ -11,6 +11,9 @@ describe 'smart-merge with failures' do
11
11
  mkdir local
12
12
  cd local
13
13
  git init
14
+ git config --local user.name 'Maxwell Smart'
15
+ git config --local user.email 'agent86@control.gov'
16
+ git config --local core.pager 'cat'
14
17
  echo -e 'one\ntwo\nthree\nfour\n' > README
15
18
  mkdir lib
16
19
  echo 'puts "pro hax"' > lib/codes.rb
@@ -11,6 +11,9 @@ describe 'smart-merge' do
11
11
  mkdir local
12
12
  cd local
13
13
  git init
14
+ git config --local user.name 'Maxwell Smart'
15
+ git config --local user.email 'agent86@control.gov'
16
+ git config --local core.pager 'cat'
14
17
  echo 'hurr durr' > README
15
18
  mkdir lib
16
19
  echo 'puts "pro hax"' > lib/codes.rb
@@ -58,7 +61,7 @@ describe 'smart-merge' do
58
61
  out.should report("Branch 'newbranch' has diverged by 1 commit. Merging in.")
59
62
  out.should report("* Branch 'master' has not moved on since 'newbranch' diverged. Running with --no-ff anyway, since a fast-forward is unexpected behaviour.")
60
63
  out.should report("Executing: git merge --no-ff newbranch")
61
- out.should report("2 files changed, 2 insertions(+), 0 deletions(-)")
64
+ out.should report(/2 files changed, 2 insertions\(\+\)(, 0 deletions\(-\))?$/)
62
65
  out.should report(/All good\. Created merge commit [\w]{7}\./)
63
66
  end
64
67
 
@@ -77,7 +80,7 @@ describe 'smart-merge' do
77
80
  out.should report("Branch 'newbranch' has diverged by 1 commit. Merging in.")
78
81
  out.should report("Branch 'master' has 1 new commit since 'newbranch' diverged.")
79
82
  out.should report("Executing: git merge --no-ff newbranch")
80
- out.should report("2 files changed, 2 insertions(+), 0 deletions(-)")
83
+ out.should report(/2 files changed, 2 insertions\(\+\)(, 0 deletions\(-\))?$/)
81
84
  out.should report(/All good\. Created merge commit [\w]{7}\./)
82
85
  end
83
86
 
@@ -91,7 +94,7 @@ describe 'smart-merge' do
91
94
  out = run_command(local_dir, 'smart-merge', 'newbranch')
92
95
  out.should report("Executing: git stash")
93
96
  out.should report("Executing: git merge --no-ff newbranch")
94
- out.should report("2 files changed, 2 insertions(+), 0 deletions(-)")
97
+ out.should report(/2 files changed, 2 insertions\(\+\)(, 0 deletions\(-\))?$/)
95
98
  out.should report("Reapplying local changes...")
96
99
  out.should report("Executing: git stash pop")
97
100
  out.should report(/All good\. Created merge commit [\w]{7}\./)
@@ -12,14 +12,20 @@ describe 'smart-pull' do
12
12
  mkdir remote
13
13
  cd remote
14
14
  git init
15
+ git config --local user.name 'Maxwell Smart'
16
+ git config --local user.email 'agent86@control.gov'
17
+ git config --local core.pager 'cat'
15
18
  echo 'hurr durr' > README
16
19
  mkdir lib
17
20
  echo 'puts "pro hax"' > lib/codes.rb
18
21
  git add .
19
22
  git commit -m 'first'
20
23
  cd ..
21
-
22
24
  git clone remote/.git local
25
+ cd local
26
+ git config --local user.name 'Agent 99'
27
+ git config --local user.email 'agent99@control.gov'
28
+ git config --local core.pager 'cat'
23
29
  ]
24
30
  end
25
31
 
@@ -68,7 +74,7 @@ describe 'smart-pull' do
68
74
  out.should report("Local branch 'master' has not moved on. Fast-forwarding.")
69
75
  out.should report("Executing: git merge --ff-only origin/master")
70
76
  out.should report(/Updating [^\.]+..[^\.]+/)
71
- out.should report("1 files changed, 1 insertions(+), 0 deletions(-)")
77
+ out.should report(/1 files? changed, 1 insertions?\(\+\)(, 0 deletions\(-\))?$/)
72
78
  end
73
79
 
74
80
  it "should not stash before fast-forwarding if untracked files are present" do
@@ -79,7 +85,7 @@ describe 'smart-pull' do
79
85
  local_dir.should have_git_status({:untracked => ['noob']})
80
86
  out = run_command(local_dir, 'smart-pull')
81
87
  out.should report("Executing: git merge --ff-only origin/master")
82
- out.should report("1 files changed, 1 insertions(+), 0 deletions(-)")
88
+ out.should report(/1 files? changed, 1 insertions?\(\+\)(, 0 deletions\(-\))?$/)
83
89
  local_dir.should have_git_status({:untracked => ['noob']})
84
90
  end
85
91
 
@@ -95,7 +101,7 @@ describe 'smart-pull' do
95
101
  out.should report("Working directory dirty. Stashing...")
96
102
  out.should report("Executing: git stash")
97
103
  out.should report("Executing: git merge --ff-only origin/master")
98
- out.should report("1 files changed, 1 insertions(+), 0 deletions(-)")
104
+ out.should report(/1 files? changed, 1 insertions?\(\+\)(, 0 deletions\(-\))?$/)
99
105
  out.should report("Reapplying local changes...")
100
106
  out.should report("Executing: git stash pop")
101
107
  local_dir.should have_git_status({:added => ['noob'], :modified => ['lib/codes.rb']})
@@ -159,4 +165,51 @@ describe 'smart-pull' do
159
165
  local_dir.should have_last_few_commits(['local changes', 'upstream changes', 'first'])
160
166
  end
161
167
  end
168
+
169
+ context 'with a submodule' do
170
+ before do
171
+ %x[
172
+ cd #{WORKING_DIR}
173
+ mkdir submodule
174
+ cd submodule
175
+ git init
176
+ git config --local user.name 'The Chief'
177
+ git config --local user.email 'agentq@control.gov'
178
+ git config --local core.pager 'cat'
179
+ echo 'Unusual, but effective.' > README
180
+ git add .
181
+ git commit -m 'first'
182
+ cd ..
183
+ cd local
184
+ git submodule add "${PWD}/../submodule/.git" submodule
185
+ git commit -am 'Add submodule'
186
+ ]
187
+ end
188
+ let(:submodule_dir) { local_dir + '/submodule' }
189
+
190
+ it 'can smart-pull the repo containing the submodule' do
191
+ out = run_command(local_dir, 'smart-pull')
192
+ out.should report('Executing: git fetch origin')
193
+ out.should report("Remote branch 'origin/master' has not moved on.")
194
+ out.should report("You have 1 new commit on 'master'.")
195
+ end
196
+
197
+ it 'can smart-pull the submodule' do
198
+ out = run_command(submodule_dir, 'smart-pull')
199
+ out.should report('Executing: git fetch origin')
200
+ out.should report("Neither your local branch 'master', nor the remote branch 'origin/master' have moved on.")
201
+ out.should report('Already up-to-date')
202
+ end
203
+ end
204
+
205
+ context 'outside of a repo' do
206
+ it 'should report a meaningful error' do
207
+ Dir.mktmpdir do |non_repo_dir|
208
+ out = run_command(non_repo_dir, 'smart-pull')
209
+ out.should report 'You need to run this from within a Git directory'
210
+ out.should report 'Current working directory: '
211
+ out.should report 'Expected .git directory: '
212
+ end
213
+ end
214
+ end
162
215
  end
@@ -1,4 +1,5 @@
1
1
  require 'rspec'
2
+ require 'tmpdir'
2
3
 
3
4
  require File.dirname(__FILE__) + '/../lib/git-smart'
4
5
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-smart
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-01-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: colorize
16
- requirement: &70163409621800 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70163409621800
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rspec
27
- requirement: &70163409621260 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: 2.7.0
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *70163409621260
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 2.7.0
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: rcov
38
- requirement: &70163409620520 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *70163409620520
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: rocco
49
- requirement: &70163409619900 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,7 +69,12 @@ dependencies:
54
69
  version: '0'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *70163409619900
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  description: Installs some additional 'smart' git commands, like `git smart-pull`.
59
79
  email: glenmaddern@gmail.com
60
80
  executables:
@@ -95,12 +115,9 @@ files:
95
115
  - spec/smart-merge_spec.rb
96
116
  - spec/smart-pull_spec.rb
97
117
  - spec/spec_helper.rb
98
- - !binary |-
99
- YmluL2dpdC1zbWFydC1sb2c=
100
- - !binary |-
101
- YmluL2dpdC1zbWFydC1tZXJnZQ==
102
- - !binary |-
103
- YmluL2dpdC1zbWFydC1wdWxs
118
+ - bin/git-smart-log
119
+ - bin/git-smart-merge
120
+ - bin/git-smart-pull
104
121
  homepage: http://github.com/geelen/git-smart
105
122
  licenses:
106
123
  - MIT
@@ -122,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
139
  version: '0'
123
140
  requirements: []
124
141
  rubyforge_project:
125
- rubygems_version: 1.8.11
142
+ rubygems_version: 1.8.23
126
143
  signing_key:
127
144
  specification_version: 3
128
145
  summary: Add some smarts to your git workflow