absgit 0.1.2 → 0.1.3

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: 7f26cd5efa247302f66c97d4ef3f6118d2b6a576
4
- data.tar.gz: 2af40a800b06f4085875b6ae54935dfb0c97e53d
3
+ metadata.gz: e791e4bf577e3a1e58ac8f959f0227ed4933a595
4
+ data.tar.gz: f762c30f32481f37064411d076ce2bcaebd3ca0f
5
5
  SHA512:
6
- metadata.gz: 114ada2e52cdde5bfea375e52b75721a092a71f299089a2b6bb2350b618c4a1d1a19024b796d04dd73e741924fd9e44d139f5f6a2d92220e2bc4f52d066d3ba3
7
- data.tar.gz: 9e86941d8c7a81a97746faca2cbccb2bf0b52569a523d886bf241394a4abc4e66323ba76f2fc6dc7a9e326670cfa544f21486acfae18e26c91b957cc9a694a20
6
+ metadata.gz: 7bd814e27cf3029fa9c3b168b8edb0e938f419daf82c16226110d3cb5bd086d4526a2189bbb2a3094745db17cdb0cd3667ec409525d7f324ccfef0d8215d6833
7
+ data.tar.gz: 7d46df305375c76723f9a6f1eee238fdab6eea57a900aba16bb4784d954f13e95a3f2f09c975c9a4b3843b9aec8ea6e4a95109e42dcd5ec2c73bcdfc49b24843
@@ -1,3 +1,3 @@
1
1
  class Absgit
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
data/lib/absgit.rb CHANGED
@@ -15,12 +15,12 @@ class Absgit
15
15
  end
16
16
 
17
17
  def self.get_repo_path(file_name)
18
- path = Pathname.new(file_name)
19
-
20
- if path.exist?
21
- path.realpath.ascend do |path2|
22
- if (path2 + '.git').exist?
23
- return path2
18
+ Pathname.new(file_name).ascend do |path|
19
+ if path.exist?
20
+ path.realpath.ascend do |path2|
21
+ if (path2 + '.git').exist?
22
+ return path2
23
+ end
24
24
  end
25
25
  end
26
26
  end
@@ -68,7 +68,8 @@ class Absgit
68
68
  puts option_parser
69
69
  else
70
70
  repo_path =
71
- @args[1..-1].grep(%r{/}).each_with_object(nil) { |arg|
71
+ @args[1..-1].find_all { |arg| repo_object_candidate?(arg) }.
72
+ each_with_object(nil) { |arg|
72
73
  repo = self.class.get_repo_path(arg)
73
74
  break repo if !repo.nil?
74
75
  }
@@ -94,6 +95,15 @@ class Absgit
94
95
  system(env, *command)
95
96
  end
96
97
  end
98
+
99
+ private
100
+
101
+ def repo_object_candidate?(arg)
102
+ !!if arg.include?('/')
103
+ path = Pathname.new(arg)
104
+ path.exist? || path.dirname.exist?
105
+ end
106
+ end
97
107
  end
98
108
 
99
109
  # vim: set syntax=ruby:
data/test/absgit_test.rb CHANGED
@@ -20,42 +20,34 @@ class AbsgitTest < MiniTest::Unit::TestCase
20
20
  APP_PATH_ESC = Shellwords.escape(APP_PATH)
21
21
 
22
22
  def setup
23
+ @saved_dir = Dir.pwd
24
+
23
25
  @temp_dir = Dir.mktmpdir
24
26
 
25
- # puts "dir: #@temp_dir"
27
+ Dir.chdir(@temp_dir)
26
28
  end
27
29
 
28
30
  def teardown
31
+ Dir.chdir(@saved_dir)
32
+
29
33
  FileUtils.rm_r(@temp_dir, secure: true)
30
34
  end
31
35
 
32
- def test_symlinks_resolved
33
- Dir.chdir(@temp_dir) do
34
- # Given
35
-
36
- repo = 'a1/a2/a3/repo'
37
- repo_abs = File.absolute_path(repo)
38
-
39
- repo_file = File.join(repo, 'b1/b2/b3/file')
40
- repo_file_abs = File.absolute_path(repo_file)
41
-
42
- symlink = 'd/symlink'
43
-
44
- FileUtils.makedirs(File.dirname(repo_file))
45
- FileUtils.touch(repo_file)
46
-
47
- Dir.mkdir(File.dirname(symlink))
48
- File.symlink(repo_file_abs, symlink)
36
+ def test_help_message_is_output
37
+ assert_match(/--help\b/, `#{APP_PATH_ESC} --help`)
38
+ end
49
39
 
50
- system 'git', 'init', '--quiet', repo
40
+ def test_options_for_git_are_left_alone
41
+ refute_match(
42
+ /--help\b/,
51
43
 
52
- # When & Then
44
+ #> any program that consumes its input will do
45
+ # instead of "wc"
53
46
 
54
- assert_equal(repo_abs, Absgit.get_repo_path(symlink).to_s)
55
- assert_equal(
56
- repo_abs, Absgit.get_repo_path(File.absolute_path(symlink)).to_s
57
- )
58
- end
47
+ %x{
48
+ PAGER=wc #{APP_PATH_ESC} log --help
49
+ }
50
+ )
59
51
  end
60
52
 
61
53
  def test_file_not_in_repo
@@ -68,49 +60,117 @@ class AbsgitTest < MiniTest::Unit::TestCase
68
60
  end
69
61
  end
70
62
 
63
+ def test_symlinks_resolved
64
+ # Given
65
+
66
+ repo = 'a1/a2/a3/repo'
67
+ repo_abs = File.absolute_path(repo)
68
+
69
+ repo_file = File.join(repo, 'b1/b2/b3/file')
70
+ repo_file_abs = File.absolute_path(repo_file)
71
+
72
+ symlink = 'd/symlink'
73
+
74
+ FileUtils.makedirs(File.dirname(repo_file))
75
+ FileUtils.touch(repo_file)
76
+
77
+ Dir.mkdir(File.dirname(symlink))
78
+ File.symlink(repo_file_abs, symlink)
79
+
80
+ system 'git', 'init', '--quiet', repo
81
+
82
+ # When & Then
83
+
84
+ assert_equal(repo_abs, Absgit.get_repo_path(symlink).to_s)
85
+ assert_equal(
86
+ repo_abs, Absgit.get_repo_path(File.absolute_path(symlink)).to_s
87
+ )
88
+ end
89
+
71
90
  def test_commit_does_not_require_chdir_to_repo
72
- Dir.chdir(@temp_dir) do
73
- # Given
91
+ # Given
74
92
 
75
- repo = 'repo'
76
- repo_file = File.join(repo, 'file')
77
- repo_file_abs = File.absolute_path(repo_file)
93
+ repo = 'repo'
94
+ repo_file = File.join(repo, 'file')
95
+ repo_file_abs = File.absolute_path(repo_file)
78
96
 
79
- Dir.mkdir(repo)
80
- system 'git', 'init', '--quiet', repo
81
- IO.write(repo_file, "blah\n")
97
+ Dir.mkdir(repo)
98
+ system 'git', 'init', '--quiet', repo
99
+ IO.write(repo_file, "blah\n")
82
100
 
83
- # When
101
+ # When
84
102
 
85
- system(
86
- "#{APP_PATH_ESC} add #{repo_file_abs.shellescape}"
87
- )
103
+ system(
104
+ "#{APP_PATH_ESC} add #{repo_file_abs.shellescape}"
105
+ )
88
106
 
89
- system(
90
- "#{APP_PATH_ESC} commit --quiet --message blah " +
91
- repo_file_abs.shellescape
92
- )
107
+ system(
108
+ "#{APP_PATH_ESC} commit --quiet --message blah " +
109
+ repo_file_abs.shellescape
110
+ )
93
111
 
94
- # Then
112
+ # Then
95
113
 
96
- Dir.chdir(repo) do
97
- assert_equal("1\n", `git rev-list --count HEAD`)
98
- end
99
- end
114
+ assert_equal(1, num_commits(repo))
100
115
  end
101
116
 
102
- def test_help_message_is_output
103
- assert_match(/--help\b/, `#{APP_PATH_ESC} --help`)
117
+ def test_commit_works_for_removed_file
118
+ # Given
119
+
120
+ repo = 'repo'
121
+ repo_file = File.join(repo, 'file')
122
+ repo_file_abs = File.absolute_path(repo_file)
123
+
124
+ Dir.mkdir(repo)
125
+ system 'git', 'init', '--quiet', repo
126
+
127
+ IO.write(repo_file, "blah\n")
128
+ system(
129
+ "#{APP_PATH_ESC} add #{repo_file_abs.shellescape}"
130
+ )
131
+ system(
132
+ "#{APP_PATH_ESC} commit --quiet --message blah " +
133
+ repo_file_abs.shellescape
134
+ )
135
+
136
+ num_commits_before = num_commits(repo)
137
+
138
+ # When
139
+
140
+ system(
141
+ "#{APP_PATH_ESC} rm --quiet " +
142
+ repo_file_abs.shellescape
143
+ )
144
+ system(
145
+ "#{APP_PATH_ESC} commit --quiet --message blah " +
146
+ repo_file_abs.shellescape
147
+ )
148
+
149
+ # Then
150
+
151
+ assert_equal(num_commits_before + 1, num_commits(repo))
104
152
  end
105
153
 
106
- def test_options_for_git_are_left_alone
107
- refute_match(
108
- /--help\b/,
109
- %x{
110
- #> any program that consumes its input will do
111
- # instead of "wc"
112
- PAGER=wc #{APP_PATH_ESC} log --help
154
+ private
155
+
156
+ def num_commits(repo_dir)
157
+ Dir.chdir(repo_dir) {
158
+ `git rev-list --count HEAD`.match(/\A\d+\n\z/) { |m|
159
+ m[0].to_i
113
160
  }
114
- )
161
+ }
162
+ end
163
+ end
164
+
165
+ if false
166
+ module Kernel
167
+ alias old_system system
168
+
169
+ def system(*a)
170
+ puts "\ndebug: about to call #{__method__} with " +
171
+ "these parameters: #{a.inspect}"
172
+ old_system(*a)
173
+ puts "\ndebug: call to #{__method__} completed"
174
+ end
115
175
  end
116
176
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: absgit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruafozy