absgit 0.2.1 → 0.3.0

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
2
  SHA1:
3
- metadata.gz: 3e5b421181caae16aa6117e6b3a69da27869d11e
4
- data.tar.gz: 6018b58723501e31f4d410d56035467a314f0cba
3
+ metadata.gz: cd29facc8a9fc8d0fd30f4c06f532780ce7e16be
4
+ data.tar.gz: f3cf9946f25f02229d4d345a0d2daea7b3ffcf37
5
5
  SHA512:
6
- metadata.gz: e018de14b4a7f2267a7d7a9f62cd821ba9d9c9eabaa841595b168f8d681d6898ed4a4409f04d6ff430021fa57767e7d1284f723684463fd1058ab785bc6d783b
7
- data.tar.gz: d78ac731320c1f902af6d320858344766b5ae90cd033acf45156760cf00e3ef9e531514132982f5bb17a552b0bc82c8147092466bde300df03f9171e018b2624
6
+ metadata.gz: 1ce175e288ab5067c4103d08c4fa88c15fd84a30d81a6520e80e0396e0d343426a09bf849c3a258c63b575fcbfa89c4783868abad9fa2821860946fd20d9e287
7
+ data.tar.gz: af63a1d19436a28ca56ca8d4a24c9054db1759d99fb73f6caa984a88b21aeb467df7b667fb5ed1300a52e0063f22c3c2ce0dea3f93db1b622cce9c634c88b857
data/Rakefile CHANGED
@@ -9,11 +9,14 @@ task :run, [:absgit_args] do |dummy, args|
9
9
  )
10
10
  end
11
11
 
12
- desc 'Run the test suite'
13
- task :test do
14
- cmd = 'minitest4', 'test'
12
+ desc %q{Run the test suite (`pat' is used with "-n")}
13
+ task :test, [:pat] do |dummy, args|
15
14
  cmd = 'minitest4', '-p', 'test', '--', '-v'
16
15
 
16
+ if args.pat
17
+ cmd += ['-n', args.pat]
18
+ end
19
+
17
20
  #> we need to set RUBYLIB, because the test suite
18
21
  # invokes the application as a separate process
19
22
 
@@ -21,7 +24,10 @@ task :test do
21
24
  {
22
25
  'RUBYLIB' =>
23
26
  (
24
- [File.join(__dir__, 'lib')] +
27
+ [
28
+ File.join(__dir__, 'lib'),
29
+ File.join(__dir__, 'test', 'lib'),
30
+ ] +
25
31
  ENV.fetch('RUBYLIB', '').split(':')
26
32
  ).join(':')
27
33
  },
@@ -39,8 +39,8 @@ variables in its environment.
39
39
 
40
40
  Also,
41
41
  any argument which contains a slash and denotes
42
- a path inside the repository is turned into an
43
- absolute path before being passed to Git.
42
+ a path inside the repository is turned into a
43
+ canonicalised absolute pathname before being passed to Git.
44
44
  This enables relative paths and symlinks to work.
45
45
 
46
46
  ## Options
@@ -41,6 +41,12 @@ class Absgit
41
41
  @options[:help] = true
42
42
  end
43
43
 
44
+ parser.on(
45
+ '-p', '--path PATH', 'Use PATH to determine Git repository'
46
+ ) do |path|
47
+ @options[:path] = path
48
+ end
49
+
44
50
  parser.on('--version', 'Show program name and version') do
45
51
  @options[:version] = true
46
52
  end
@@ -49,7 +55,7 @@ class Absgit
49
55
 
50
56
  def run
51
57
  begin
52
- option_parser.order!
58
+ option_parser.order!(@args)
53
59
  rescue OptionParser::ParseError
54
60
  $stderr.puts 'Error: incorrect usage'
55
61
  $stderr.puts ''
@@ -69,12 +75,23 @@ class Absgit
69
75
  elsif @options[:help]
70
76
  puts option_parser
71
77
  else
72
- repo_path =
73
- @args[1..-1].find_all { |arg| repo_object_candidate?(arg) }.
74
- each_with_object(nil) { |arg|
75
- repo = self.class.get_repo_path(arg)
76
- break repo if !repo.nil?
77
- }
78
+ if @options[:path]
79
+ repo_path = self.class.get_repo_path(@options[:path])
80
+
81
+ if repo_path.nil?
82
+ $stderr.puts \
83
+ "Fatal error: cannot " +
84
+ "map path to Git repository: #{@options[:path]}"
85
+ exit(1)
86
+ end
87
+ else
88
+ repo_path =
89
+ @args[1..-1].find_all { |arg| repo_object_candidate?(arg) }.
90
+ each_with_object(nil) { |arg|
91
+ repo = self.class.get_repo_path(arg)
92
+ break repo if !repo.nil?
93
+ }
94
+ end
78
95
 
79
96
  if repo_path.nil?
80
97
  env = {}
@@ -1,3 +1,3 @@
1
1
  class Absgit
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -1,44 +1,21 @@
1
1
  require 'absgit'
2
+ require 'absgit_common'
2
3
  require 'fileutils'
3
4
  require 'shellwords'
4
5
  require 'tmpdir'
5
6
  require 'minitest/unit'
6
7
 
7
- class AbsgitTest < MiniTest::Unit::TestCase
8
- APP_PATH = File.expand_path(
9
- "../../bin/#{Absgit::PROGRAM_NAME}",
10
- __FILE__
11
- )
12
- APP_PATH_ESC = Shellwords.escape(APP_PATH)
13
-
14
- def setup
15
- @saved_dir = Dir.pwd
16
-
17
- @temp_dir = Dir.mktmpdir
18
-
19
- Dir.chdir(@temp_dir)
20
- end
21
-
22
- def teardown
23
- Dir.chdir(@saved_dir)
24
-
25
- FileUtils.rm_r(@temp_dir, secure: true)
26
- end
8
+ class AbsgitAboveRepoTest < MiniTest::Unit::TestCase
9
+ include AbsgitCommon
27
10
 
28
11
  def test_help_message_is_output
29
12
  assert_match(/--help\b/, `#{APP_PATH_ESC} --help`)
30
13
  end
31
14
 
32
15
  def test_options_for_git_are_left_alone
33
- refute_match(
34
- /--help\b/,
35
-
36
- #> any program that consumes its input will do
37
- # instead of "wc"
38
-
39
- %x{
40
- PAGER=wc #{APP_PATH_ESC} log --help
41
- }
16
+ refute_equal(
17
+ `#{APP_PATH_ESC} --help`,
18
+ `#{APP_PATH_ESC} log --help`
42
19
  )
43
20
  end
44
21
 
@@ -183,68 +160,52 @@ class AbsgitTest < MiniTest::Unit::TestCase
183
160
  assert_equal(num_commits_before + 1, num_commits(repo))
184
161
  end
185
162
 
186
- class InRepo < self
187
- def setup
188
- super
189
- Dir.chdir(get_repo)
190
- end
163
+ def test_path_option_works_for_symlink
164
+ # Given
191
165
 
192
- def test_exit_status_preserved
193
- [
194
- %w{ls-files},
195
- %w{ls-files --non-existent-option},
196
- %w{add non-existent-file},
197
- ].each do |args|
198
- # Given & When
199
-
200
- opts = {
201
- err: '/dev/null',
202
- out: '/dev/null',
203
- }
204
- system(*(%w{git} + args), opts)
205
- git_exit_status = $?.exitstatus
206
- system(*([APP_PATH] + args), opts)
207
- absgit_exit_status = $?.exitstatus
208
-
209
- # Then
210
-
211
- assert_equal(git_exit_status, absgit_exit_status)
212
- end
213
- end
214
- end
166
+ repo = get_repo
215
167
 
216
- private
168
+ tracked_file = File.join(repo, 'tracked_file')
169
+ FileUtils.touch(tracked_file)
217
170
 
218
- def files_in_index(repo)
219
- Dir.chdir(repo) do
220
- %x{git ls-files}.split("\n")
221
- end
222
- end
171
+ symlink = './symlink'
172
+ File.symlink(tracked_file, symlink)
223
173
 
224
- def num_commits(repo_dir)
225
- Dir.chdir(repo_dir) {
226
- `git rev-list --count HEAD`.match(/\A\d+\n\z/) { |m|
227
- m[0].to_i
228
- }
229
- }
230
- end
174
+ # When
231
175
 
232
- def get_repo
233
- dir = Dir.mktmpdir(nil, '.')
234
- system('git', 'init', '--quiet', dir)
235
- dir
176
+ system(APP_PATH, '--path', symlink, 'add', symlink)
177
+
178
+ # Then
179
+
180
+ assert_equal(1, files_in_index(repo).size)
236
181
  end
237
- end
238
182
 
239
- 0.times do
240
- module Kernel
241
- alias old_system system
183
+ def test_path_option_works_for_real_path
184
+ # Given
185
+
186
+ repo = get_repo
187
+
188
+ tracked_file = File.join(repo, 'tracked_file')
189
+ FileUtils.touch(tracked_file)
190
+
191
+ real_path = File.realpath(tracked_file)
242
192
 
243
- def system(*a)
244
- puts "\ndebug: about to call #{__method__} with " +
245
- "these parameters: #{a.inspect}"
246
- old_system(*a)
247
- puts "\ndebug: call to #{__method__} completed"
193
+ # When
194
+
195
+ system(APP_PATH, '--path', real_path, 'add', real_path)
196
+
197
+ # Then
198
+
199
+ assert_equal(1, files_in_index(repo).size)
200
+ end
201
+
202
+ def test_error_behaviour_for_path_option
203
+ output, err_msg = capture_subprocess_io do
204
+ system(APP_PATH, '--path', '/', 'log')
248
205
  end
206
+
207
+ refute $?.success?
208
+ assert_equal('', output)
209
+ assert_match(/./, err_msg)
249
210
  end
250
211
  end
@@ -0,0 +1,35 @@
1
+ require 'absgit'
2
+ require 'absgit_common'
3
+ require 'minitest/unit'
4
+
5
+ class AbsgitWithinRepoTest < MiniTest::Unit::TestCase
6
+ include AbsgitCommon
7
+
8
+ def setup
9
+ super
10
+ Dir.chdir(get_repo)
11
+ end
12
+
13
+ def test_exit_status_preserved
14
+ [
15
+ %w{ls-files},
16
+ %w{ls-files --non-existent-option},
17
+ %w{add non-existent-file},
18
+ ].each do |args|
19
+ # Given & When
20
+
21
+ opts = {
22
+ err: '/dev/null',
23
+ out: '/dev/null',
24
+ }
25
+ system(*(%w{git} + args), opts)
26
+ git_exit_status = $?.exitstatus
27
+ system(*([APP_PATH] + args), opts)
28
+ absgit_exit_status = $?.exitstatus
29
+
30
+ # Then
31
+
32
+ assert_equal(git_exit_status, absgit_exit_status)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,60 @@
1
+ require 'fileutils'
2
+ require 'shellwords'
3
+ require 'tmpdir'
4
+
5
+ module AbsgitCommon
6
+ APP_PATH = File.expand_path(
7
+ "../../../bin/#{Absgit::PROGRAM_NAME}",
8
+ __FILE__
9
+ )
10
+ APP_PATH_ESC = Shellwords.escape(APP_PATH)
11
+
12
+ def setup
13
+ @saved_dir = Dir.pwd
14
+
15
+ @temp_dir = Dir.mktmpdir
16
+
17
+ Dir.chdir(@temp_dir)
18
+ end
19
+
20
+ def teardown
21
+ Dir.chdir(@saved_dir)
22
+
23
+ FileUtils.rm_r(@temp_dir, secure: true)
24
+ end
25
+
26
+ private
27
+
28
+ def files_in_index(repo)
29
+ Dir.chdir(repo) do
30
+ %x{git ls-files}.split("\n")
31
+ end
32
+ end
33
+
34
+ def num_commits(repo_dir)
35
+ Dir.chdir(repo_dir) {
36
+ `git rev-list --count HEAD`.match(/\A\d+\n\z/) { |m|
37
+ m[0].to_i
38
+ }
39
+ }
40
+ end
41
+
42
+ def get_repo
43
+ dir = Dir.mktmpdir(nil, '.')
44
+ system('git', 'init', '--quiet', dir)
45
+ dir
46
+ end
47
+ end
48
+
49
+ 0.times do
50
+ module Kernel
51
+ alias old_system system
52
+
53
+ def system(*a)
54
+ puts "\ndebug: about to call #{__method__} with " +
55
+ "these parameters: #{a.inspect}"
56
+ old_system(*a)
57
+ puts "\ndebug: call to #{__method__} completed"
58
+ end
59
+ end
60
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: absgit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruafozy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-01 00:00:00.000000000 Z
11
+ date: 2013-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: methadone
@@ -101,7 +101,9 @@ files:
101
101
  - lib/absgit/version.rb
102
102
  - lib/utils.rb
103
103
  - rakelib/utils.rake
104
- - test/absgit_test.rb
104
+ - test/absgit_above_repo_test.rb
105
+ - test/absgit_within_repo_test.rb
106
+ - test/lib/absgit_common.rb
105
107
  - test/utils_test.rb
106
108
  homepage: https://github.com/ruafozy/absgit
107
109
  licenses:
@@ -128,3 +130,4 @@ signing_key:
128
130
  specification_version: 4
129
131
  summary: Allow manipulating Git repository files outside a repository
130
132
  test_files: []
133
+ has_rdoc: false