absgit 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/absgit/version.rb +1 -1
- data/lib/absgit.rb +17 -7
- data/test/absgit_test.rb +116 -56
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e791e4bf577e3a1e58ac8f959f0227ed4933a595
|
4
|
+
data.tar.gz: f762c30f32481f37064411d076ce2bcaebd3ca0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bd814e27cf3029fa9c3b168b8edb0e938f419daf82c16226110d3cb5bd086d4526a2189bbb2a3094745db17cdb0cd3667ec409525d7f324ccfef0d8215d6833
|
7
|
+
data.tar.gz: 7d46df305375c76723f9a6f1eee238fdab6eea57a900aba16bb4784d954f13e95a3f2f09c975c9a4b3843b9aec8ea6e4a95109e42dcd5ec2c73bcdfc49b24843
|
data/lib/absgit/version.rb
CHANGED
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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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].
|
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
|
-
|
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
|
33
|
-
|
34
|
-
|
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
|
-
|
40
|
+
def test_options_for_git_are_left_alone
|
41
|
+
refute_match(
|
42
|
+
/--help\b/,
|
51
43
|
|
52
|
-
|
44
|
+
#> any program that consumes its input will do
|
45
|
+
# instead of "wc"
|
53
46
|
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
-
|
73
|
-
# Given
|
91
|
+
# Given
|
74
92
|
|
75
|
-
|
76
|
-
|
77
|
-
|
93
|
+
repo = 'repo'
|
94
|
+
repo_file = File.join(repo, 'file')
|
95
|
+
repo_file_abs = File.absolute_path(repo_file)
|
78
96
|
|
79
|
-
|
80
|
-
|
81
|
-
|
97
|
+
Dir.mkdir(repo)
|
98
|
+
system 'git', 'init', '--quiet', repo
|
99
|
+
IO.write(repo_file, "blah\n")
|
82
100
|
|
83
|
-
|
101
|
+
# When
|
84
102
|
|
85
|
-
|
86
|
-
|
87
|
-
|
103
|
+
system(
|
104
|
+
"#{APP_PATH_ESC} add #{repo_file_abs.shellescape}"
|
105
|
+
)
|
88
106
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
107
|
+
system(
|
108
|
+
"#{APP_PATH_ESC} commit --quiet --message blah " +
|
109
|
+
repo_file_abs.shellescape
|
110
|
+
)
|
93
111
|
|
94
|
-
|
112
|
+
# Then
|
95
113
|
|
96
|
-
|
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
|
103
|
-
|
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
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
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
|