amp-git 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +23 -0
- data/Gemfile +15 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +68 -0
- data/VERSION +1 -0
- data/features/amp-git.feature +9 -0
- data/features/step_definitions/amp-git_steps.rb +0 -0
- data/features/support/env.rb +4 -0
- data/lib/amp-git/encoding/binary_delta.rb +171 -0
- data/lib/amp-git/repo_format/changeset.rb +348 -0
- data/lib/amp-git/repo_format/commit_object.rb +87 -0
- data/lib/amp-git/repo_format/index.rb +169 -0
- data/lib/amp-git/repo_format/loose_object.rb +78 -0
- data/lib/amp-git/repo_format/packfile.rb +263 -0
- data/lib/amp-git/repo_format/packfile_index.rb +196 -0
- data/lib/amp-git/repo_format/raw_object.rb +56 -0
- data/lib/amp-git/repo_format/staging_area.rb +215 -0
- data/lib/amp-git/repo_format/tag_object.rb +87 -0
- data/lib/amp-git/repo_format/tree_object.rb +98 -0
- data/lib/amp-git/repo_format/versioned_file.rb +133 -0
- data/lib/amp-git/repositories/local_repository.rb +192 -0
- data/lib/amp-git/repository.rb +57 -0
- data/lib/amp-git.rb +49 -0
- data/lib/amp_plugin.rb +1 -0
- data/spec/amp-git_spec.rb +15 -0
- data/spec/repository_spec.rb +74 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +29 -0
- data/test/index_tests/index +0 -0
- data/test/index_tests/test_helper.rb +16 -0
- data/test/index_tests/test_index.rb +69 -0
- data/test/packfile_tests/hasindex.idx +0 -0
- data/test/packfile_tests/hasindex.pack +0 -0
- data/test/packfile_tests/pack-4e1941122fd346526b0a3eee2d92f3277a0092cd.pack +0 -0
- data/test/packfile_tests/pack-d23ff2538f970371144ae7182c28730b11eb37c1.idx +0 -0
- data/test/packfile_tests/test_helper.rb +16 -0
- data/test/packfile_tests/test_packfile.rb +75 -0
- data/test/packfile_tests/test_packfile_index_v2.rb +90 -0
- data/test/packfile_tests/test_packfile_with_index.rb +76 -0
- data/test/test_commit_object.rb +60 -0
- data/test/test_git_delta.rb +67 -0
- data/test/test_helper.rb +71 -0
- data/test/test_loose_object.rb +51 -0
- data/test/test_tag_object.rb +72 -0
- data/test/test_tree_object.rb +55 -0
- metadata +215 -0
@@ -0,0 +1,133 @@
|
|
1
|
+
##################################################################
|
2
|
+
# Licensing Information #
|
3
|
+
# #
|
4
|
+
# The following code is licensed, as standalone code, under #
|
5
|
+
# the Ruby License, unless otherwise directed within the code. #
|
6
|
+
# #
|
7
|
+
# For information on the license of this code when distributed #
|
8
|
+
# with and used in conjunction with the other modules in the #
|
9
|
+
# Amp project, please see the root-level LICENSE file. #
|
10
|
+
# #
|
11
|
+
# © Michael J. Edgar and Ari Brown, 2009-2010 #
|
12
|
+
# #
|
13
|
+
##################################################################
|
14
|
+
|
15
|
+
module Amp
|
16
|
+
module Git
|
17
|
+
|
18
|
+
##
|
19
|
+
# This class allows you to access a file at a given revision in the repo's
|
20
|
+
# history. You can compare them, sort them, access the changeset, and
|
21
|
+
# all sorts of stuff.
|
22
|
+
class VersionedFile < Amp::Core::Repositories::AbstractVersionedFile
|
23
|
+
|
24
|
+
attr_accessor :revision
|
25
|
+
attr_accessor :path
|
26
|
+
attr_accessor :repo
|
27
|
+
|
28
|
+
def initialize(repo, path, opts={})
|
29
|
+
@repo = repo
|
30
|
+
@path = path
|
31
|
+
@revision = opts[:revision]
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
# The changeset to which this versioned file belongs.
|
36
|
+
#
|
37
|
+
# @return [AbstractChangeset]
|
38
|
+
def changeset
|
39
|
+
@changeset ||= Changeset.new @repo, @revision
|
40
|
+
end
|
41
|
+
|
42
|
+
##
|
43
|
+
# The size of this file
|
44
|
+
#
|
45
|
+
# @return [Integer]
|
46
|
+
def size
|
47
|
+
@size ||= data.size
|
48
|
+
end
|
49
|
+
|
50
|
+
##
|
51
|
+
# The contents of a file at the given revision
|
52
|
+
#
|
53
|
+
# @return [String] the data at the current revision
|
54
|
+
def data
|
55
|
+
@data ||= `git show #{revision}:#{path} 2> /dev/null`
|
56
|
+
end
|
57
|
+
|
58
|
+
##
|
59
|
+
# The hash value for sticking this fucker in a hash.
|
60
|
+
#
|
61
|
+
# @return [Integer]
|
62
|
+
def hash
|
63
|
+
"#{size}--#{path}--#{repo.root}--#{revision} 2> /dev/null".hash
|
64
|
+
end
|
65
|
+
|
66
|
+
##
|
67
|
+
# Has this file been renamed? If so, return some useful info
|
68
|
+
def renamed?
|
69
|
+
nil
|
70
|
+
end
|
71
|
+
|
72
|
+
##
|
73
|
+
# Compares to either a bit of text or another versioned file.
|
74
|
+
# Returns true if different, false for the same.
|
75
|
+
# (much like <=> == 0 for the same)
|
76
|
+
#
|
77
|
+
# @param [AbstractVersionedFile, String] item what we're being compared to
|
78
|
+
# @return [Boolean] true if different, false if same.
|
79
|
+
def cmp(item)
|
80
|
+
return data == item if item.is_a? String
|
81
|
+
|
82
|
+
not (data == item.data &&
|
83
|
+
size == item.size &&
|
84
|
+
revision == item.revision &&
|
85
|
+
repo.root == item.repo.root )
|
86
|
+
end
|
87
|
+
|
88
|
+
##
|
89
|
+
# Are two versioned files the same? This means same path and revision indexes.
|
90
|
+
#
|
91
|
+
# @param [AbstractVersionedFile] vfile what we're being compared to
|
92
|
+
# @return [Boolean]
|
93
|
+
def ==(vfile)
|
94
|
+
!cmp(vfile)
|
95
|
+
end
|
96
|
+
|
97
|
+
##
|
98
|
+
# Gets the flags for this file ('x', 'l', or '')
|
99
|
+
#
|
100
|
+
# @return [String] 'x', 'l', or ''
|
101
|
+
def flags
|
102
|
+
'' # because git doesn't track them
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
##
|
108
|
+
# This is a VersionedFile, except it's in the working directory, so its data
|
109
|
+
# is stored on disk in the actual file. Other than that, it's basically the
|
110
|
+
# same in its interface!
|
111
|
+
class VersionedWorkingFile < VersionedFile
|
112
|
+
|
113
|
+
##
|
114
|
+
# Initializes a new working dir file - slightly different semantics here
|
115
|
+
def initialize(repo, path, opts={})
|
116
|
+
super(repo, path, opts)
|
117
|
+
end
|
118
|
+
|
119
|
+
def size
|
120
|
+
File.stat(repo.join(path)).size
|
121
|
+
end
|
122
|
+
|
123
|
+
def data
|
124
|
+
File.read repo.working_join(path)
|
125
|
+
end
|
126
|
+
|
127
|
+
def changeset
|
128
|
+
WorkingDirectoryChangeset.new repo
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,192 @@
|
|
1
|
+
##################################################################
|
2
|
+
# Licensing Information #
|
3
|
+
# #
|
4
|
+
# The following code is licensed, as standalone code, under #
|
5
|
+
# the Ruby License, unless otherwise directed within the code. #
|
6
|
+
# #
|
7
|
+
# For information on the license of this code when distributed #
|
8
|
+
# with and used in conjunction with the other modules in the #
|
9
|
+
# Amp project, please see the root-level LICENSE file. #
|
10
|
+
# #
|
11
|
+
# © Michael J. Edgar and Ari Brown, 2009-2010 #
|
12
|
+
# #
|
13
|
+
##################################################################
|
14
|
+
|
15
|
+
module Amp
|
16
|
+
module Core
|
17
|
+
module Repositories
|
18
|
+
module Git
|
19
|
+
|
20
|
+
class LocalRepository < Amp::Core::Repositories::AbstractLocalRepository
|
21
|
+
|
22
|
+
attr_accessor :root
|
23
|
+
attr_accessor :config
|
24
|
+
attr_accessor :file_opener
|
25
|
+
attr_accessor :git_opener
|
26
|
+
attr_accessor :staging_area
|
27
|
+
|
28
|
+
def initialize(path="", create=false, config=nil)
|
29
|
+
super(path, create, config)
|
30
|
+
|
31
|
+
@config = config
|
32
|
+
|
33
|
+
@file_opener = Support::RootedOpener.new @root # This will open relative to the repo root
|
34
|
+
@file_opener.default = :open_file # these two are the same, pretty much
|
35
|
+
@git_opener = Support::RootedOpener.new @root # this will open relative to root/.git
|
36
|
+
@git_opener.default = :open_git # just with different defaults
|
37
|
+
|
38
|
+
@staging_area = Amp::Core::Repositories::Git::StagingArea.new self
|
39
|
+
|
40
|
+
if create
|
41
|
+
init
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def init(config=@config)
|
46
|
+
super(config)
|
47
|
+
|
48
|
+
`cd #{@root} && git init 2> /dev/null`
|
49
|
+
true
|
50
|
+
end
|
51
|
+
|
52
|
+
##
|
53
|
+
# Regarding branch support.
|
54
|
+
#
|
55
|
+
# For each repository format, you begin in a default branch. Each repo format, of
|
56
|
+
# course, starts with a different default branch. Git's is "master".
|
57
|
+
#
|
58
|
+
# @api
|
59
|
+
# @return [String] the default branch name
|
60
|
+
def default_branch_name
|
61
|
+
"master"
|
62
|
+
end
|
63
|
+
|
64
|
+
def commit(opts={})
|
65
|
+
add_all_files
|
66
|
+
string = "git commit #{opts[:user] ? "--author #{opts[:user].inspect}" : "" }" +
|
67
|
+
" #{opts[:empty_ok] ? "--allow-empty" : "" }" +
|
68
|
+
" #{opts[:message] ? "-m #{opts[:message].inspect}" : "" } 2> /dev/null"
|
69
|
+
string.strip!
|
70
|
+
|
71
|
+
system string
|
72
|
+
end
|
73
|
+
|
74
|
+
def add_all_files
|
75
|
+
staging_area.add status[:modified]
|
76
|
+
end
|
77
|
+
|
78
|
+
def forget(*files)
|
79
|
+
staging_area.forget *files
|
80
|
+
end
|
81
|
+
|
82
|
+
def [](rev)
|
83
|
+
case rev
|
84
|
+
when String
|
85
|
+
Amp::Git::Changeset.new self, rev
|
86
|
+
when nil
|
87
|
+
Amp::Git::WorkingDirectoryChangeset.new self
|
88
|
+
when 'tip', :tip
|
89
|
+
Amp::Git::Changeset.new self, parents[0]
|
90
|
+
when Integer
|
91
|
+
revs = `git log --pretty=oneline 2> /dev/null`.split("\n")
|
92
|
+
short_name = revs[revs.size - 1 - rev].split(' ').first
|
93
|
+
Amp::Git::Changeset.new self, short_name
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def size
|
98
|
+
`git log --pretty=oneline 2> /dev/null`.split("\n").size
|
99
|
+
end
|
100
|
+
|
101
|
+
##
|
102
|
+
# Write +text+ to +filename+, where +filename+
|
103
|
+
# is local to the root.
|
104
|
+
#
|
105
|
+
# @param [String] filename The file as relative to the root
|
106
|
+
# @param [String] text The text to write to said file
|
107
|
+
def working_write(filename, text)
|
108
|
+
file_opener.open filename, 'w' do |f|
|
109
|
+
f.write text
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
##
|
114
|
+
# Determines if a file has been modified from :node1 to :node2.
|
115
|
+
#
|
116
|
+
# @return [Boolean] has it been modified
|
117
|
+
def file_modified?(file, opts={})
|
118
|
+
file_status(file, opts) == :included
|
119
|
+
end
|
120
|
+
|
121
|
+
##
|
122
|
+
# Returns a Symbol.
|
123
|
+
# Possible results:
|
124
|
+
# :added (subset of :included)
|
125
|
+
# :removed
|
126
|
+
# :untracked
|
127
|
+
# :included (aka :modified)
|
128
|
+
# :normal
|
129
|
+
#
|
130
|
+
# If you call localrepo#status from this method... well...
|
131
|
+
# I DARE YOU!
|
132
|
+
def file_status(filename, opts={})
|
133
|
+
parse_status! opts
|
134
|
+
inverted = @status.inject({}) do |h, (k, v)|
|
135
|
+
v.each {|v_| h[v_] = k }
|
136
|
+
h
|
137
|
+
end
|
138
|
+
|
139
|
+
# Now convert it so it uses the same jargon
|
140
|
+
# we REALLY need to get the dirstate and localrepo on
|
141
|
+
# the same page here.
|
142
|
+
case inverted[filename]
|
143
|
+
when :modified
|
144
|
+
:included
|
145
|
+
when :added
|
146
|
+
:added
|
147
|
+
when :removed
|
148
|
+
:removed
|
149
|
+
when :unknown
|
150
|
+
:untracked
|
151
|
+
else
|
152
|
+
:normal
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
def parse_status!(opts={})
|
158
|
+
return if @parsed
|
159
|
+
|
160
|
+
data = `git status #{opts[:node1]}..#{opts[:node2]} 2> /dev/null`.split("\n")
|
161
|
+
@status = data.inject({}) do |h, line| # yeah i know stfu
|
162
|
+
case line
|
163
|
+
when /^#\s+(\w+):\s(.+)$/
|
164
|
+
h[$1.to_sym] = $2; h
|
165
|
+
when /^#\s+([^ ]+)$/
|
166
|
+
h[:unknown] = $1; h
|
167
|
+
else
|
168
|
+
h
|
169
|
+
end
|
170
|
+
end
|
171
|
+
@parsed = true
|
172
|
+
end
|
173
|
+
|
174
|
+
def parents
|
175
|
+
first = `git log -1 HEAD 2> /dev/null`
|
176
|
+
dad = first[/^commit (.+)$/, 1]
|
177
|
+
dad = dad ? dad[0..6] : nil
|
178
|
+
mom = nil
|
179
|
+
|
180
|
+
if first =~ /Merge: (.+)\.\.\. (.+)\.\.\.$/ # Merge: 1c002dd... 35cfb2b...
|
181
|
+
dad = $1 # just have them both use the short name, nbd
|
182
|
+
mom = $2
|
183
|
+
end
|
184
|
+
|
185
|
+
[dad, mom]
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
##################################################################
|
2
|
+
# Licensing Information #
|
3
|
+
# #
|
4
|
+
# The following code is licensed, as standalone code, under #
|
5
|
+
# the Ruby License, unless otherwise directed within the code. #
|
6
|
+
# #
|
7
|
+
# For information on the license of this code when distributed #
|
8
|
+
# with and used in conjunction with the other modules in the #
|
9
|
+
# Amp project, please see the root-level LICENSE file. #
|
10
|
+
# #
|
11
|
+
# © Michael J. Edgar and Ari Brown, 2009-2010 #
|
12
|
+
# #
|
13
|
+
##################################################################
|
14
|
+
|
15
|
+
module Amp
|
16
|
+
module Core
|
17
|
+
module Repositories
|
18
|
+
module Git
|
19
|
+
|
20
|
+
class GitPicker < Amp::Core::Repositories::GenericRepoPicker
|
21
|
+
|
22
|
+
def pick(config, path='', create=false)
|
23
|
+
# hot path so we don't load the HTTP repos!
|
24
|
+
unless path[0,4] == "http"
|
25
|
+
return LocalRepository.new(find_repo(path), create, config)
|
26
|
+
end
|
27
|
+
raise "Unknown repository format for Git"
|
28
|
+
end
|
29
|
+
|
30
|
+
def repo_in_dir?(path)
|
31
|
+
return true if path[0, 4] == "http"
|
32
|
+
until File.directory? File.join(path, ".git")
|
33
|
+
old_path, path = path, File.dirname(path)
|
34
|
+
if path == old_path
|
35
|
+
return false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
true
|
39
|
+
end
|
40
|
+
|
41
|
+
################################
|
42
|
+
private
|
43
|
+
################################
|
44
|
+
def find_repo(path)
|
45
|
+
until File.directory? File.join(path, ".git")
|
46
|
+
old_path, path = path, File.dirname(path)
|
47
|
+
if path == old_path
|
48
|
+
raise ArgumentError.new("No Repository Found")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
path
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/amp-git.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
class Amp::Plugins::Git < Amp::Plugins::Base
|
2
|
+
@loader = lambda {
|
3
|
+
module ::Amp
|
4
|
+
module Git
|
5
|
+
autoload :Changeset, "amp-git/repo_format/changeset.rb"
|
6
|
+
autoload :WorkingDirectoryChangeset, "amp-git/repo_format/changeset.rb"
|
7
|
+
autoload :VersionedFile, "amp-git/repo_format/versioned_file.rb"
|
8
|
+
autoload :VersionedWorkingFile, "amp-git/repo_format/versioned_file.rb"
|
9
|
+
end
|
10
|
+
module Core
|
11
|
+
module Repositories
|
12
|
+
module Git
|
13
|
+
include Support
|
14
|
+
autoload :LocalRepository, "amp-git/repositories/local_repository.rb"
|
15
|
+
autoload :GitPicker, "amp-git/repository.rb"
|
16
|
+
autoload :StagingArea, "amp-git/repo_format/staging_area.rb"
|
17
|
+
autoload :RawObject, "amp-git/repo_format/raw_object.rb"
|
18
|
+
autoload :LooseObject, "amp-git/repo_format/loose_object.rb"
|
19
|
+
autoload :TreeObject, "amp-git/repo_format/tree_object.rb"
|
20
|
+
autoload :CommitObject, "amp-git/repo_format/commit_object.rb"
|
21
|
+
autoload :TagObject, "amp-git/repo_format/tag_object.rb"
|
22
|
+
autoload :PackFile, "amp-git/repo_format/packfile.rb"
|
23
|
+
autoload :PackFileIndex, "amp-git/repo_format/packfile_index.rb"
|
24
|
+
autoload :PackFileIndexV1, "amp-git/repo_format/packfile_index.rb"
|
25
|
+
autoload :PackFileIndexV2, "amp-git/repo_format/packfile_index.rb"
|
26
|
+
autoload :Index, "amp-git/repo_format/index.rb"
|
27
|
+
module Encoding
|
28
|
+
autoload :BinaryDelta, "amp-git/encoding/binary_delta.rb"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
require 'zlib'
|
35
|
+
require 'stringio'
|
36
|
+
}
|
37
|
+
class << self
|
38
|
+
attr_reader :loader
|
39
|
+
end
|
40
|
+
def initialize(opts = {})
|
41
|
+
@opts = opts
|
42
|
+
end
|
43
|
+
|
44
|
+
def load!
|
45
|
+
puts "Loading amp-git..."
|
46
|
+
require 'zlib'
|
47
|
+
self.class.loader.call
|
48
|
+
end
|
49
|
+
end
|
data/lib/amp_plugin.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'amp-git'))
|
@@ -0,0 +1,15 @@
|
|
1
|
+
##################################################################
|
2
|
+
# Licensing Information #
|
3
|
+
# #
|
4
|
+
# The following code is licensed, as standalone code, under #
|
5
|
+
# the Ruby License, unless otherwise directed within the code. #
|
6
|
+
# #
|
7
|
+
# For information on the license of this code when distributed #
|
8
|
+
# with and used in conjunction with the other modules in the #
|
9
|
+
# Amp project, please see the root-level LICENSE file. #
|
10
|
+
# #
|
11
|
+
# © Michael J. Edgar and Ari Brown, 2009-2010 #
|
12
|
+
# #
|
13
|
+
##################################################################
|
14
|
+
|
15
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
@@ -0,0 +1,74 @@
|
|
1
|
+
##################################################################
|
2
|
+
# Licensing Information #
|
3
|
+
# #
|
4
|
+
# The following code is licensed, as standalone code, under #
|
5
|
+
# the Ruby License, unless otherwise directed within the code. #
|
6
|
+
# #
|
7
|
+
# For information on the license of this code when distributed #
|
8
|
+
# with and used in conjunction with the other modules in the #
|
9
|
+
# Amp project, please see the root-level LICENSE file. #
|
10
|
+
# #
|
11
|
+
# © Michael J. Edgar and Ari Brown, 2009-2010 #
|
12
|
+
# #
|
13
|
+
##################################################################
|
14
|
+
|
15
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
16
|
+
|
17
|
+
describe Amp::Core::Repositories::Git::GitPicker do
|
18
|
+
include ::Construct::Helpers
|
19
|
+
describe '#repo_in_dir?' do
|
20
|
+
it 'returns true if there is a .git directory' do
|
21
|
+
within_construct do |c|
|
22
|
+
c.directory 'my_repo' do |dir|
|
23
|
+
dir.directory '.git' do |final|
|
24
|
+
Amp::Core::Repositories::Git::GitPicker.new.repo_in_dir?(final.to_s).should be_true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'returns false if there is no .git directory' do
|
31
|
+
within_construct do |c|
|
32
|
+
c.directory 'my_repo' do |dir|
|
33
|
+
dir.directory '.hg'
|
34
|
+
dir.directory '.svn'
|
35
|
+
Amp::Core::Repositories::Git::GitPicker.new.repo_in_dir?(dir.to_s).should be_false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#pick' do
|
42
|
+
it 'returns a LocalRepository object' do
|
43
|
+
within_construct do |c|
|
44
|
+
c.directory 'my_repo' do |dir|
|
45
|
+
dir.directory '.git'
|
46
|
+
repo = Amp::Core::Repositories::Git::GitPicker.new.pick({}, dir.to_s)
|
47
|
+
repo.should be_a(Amp::Core::Repositories::Git::LocalRepository)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'returns nil when no .hg found' do
|
53
|
+
within_construct do |c|
|
54
|
+
c.directory 'my_repo' do |dir|
|
55
|
+
dir.directory '.hg'
|
56
|
+
dir.directory '.svn'
|
57
|
+
lambda {
|
58
|
+
repo = Amp::Core::Repositories::Git::GitPicker.new.pick({}, dir.to_s)
|
59
|
+
}.should raise_error(ArgumentError)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'is used by Amp::Core::Repositories.pick' do
|
66
|
+
within_construct do |c|
|
67
|
+
c.directory 'my_repo' do |dir|
|
68
|
+
dir.directory '.git'
|
69
|
+
repo = Amp::Core::Repositories.pick({}, dir.to_s)
|
70
|
+
repo.should be_a(Amp::Core::Repositories::Git::LocalRepository)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
##################################################################
|
2
|
+
# Licensing Information #
|
3
|
+
# #
|
4
|
+
# The following code is licensed, as standalone code, under #
|
5
|
+
# the Ruby License, unless otherwise directed within the code. #
|
6
|
+
# #
|
7
|
+
# For information on the license of this code when distributed #
|
8
|
+
# with and used in conjunction with the other modules in the #
|
9
|
+
# Amp project, please see the root-level LICENSE file. #
|
10
|
+
# #
|
11
|
+
# © Michael J. Edgar and Ari Brown, 2009-2010 #
|
12
|
+
# #
|
13
|
+
##################################################################
|
14
|
+
|
15
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
16
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
17
|
+
require 'rubygems'
|
18
|
+
require 'amp-front'
|
19
|
+
require 'amp-core'
|
20
|
+
require 'amp-git'
|
21
|
+
require 'spec'
|
22
|
+
require 'spec/autorun'
|
23
|
+
require 'construct'
|
24
|
+
|
25
|
+
Amp::Plugins::Core.new.load!
|
26
|
+
Amp::Plugins::Git.new.load!
|
27
|
+
Spec::Runner.configure do |config|
|
28
|
+
|
29
|
+
end
|
Binary file
|
@@ -0,0 +1,16 @@
|
|
1
|
+
##################################################################
|
2
|
+
# Licensing Information #
|
3
|
+
# #
|
4
|
+
# The following code is licensed, as standalone code, under #
|
5
|
+
# the Ruby License, unless otherwise directed within the code. #
|
6
|
+
# #
|
7
|
+
# For information on the license of this code when distributed #
|
8
|
+
# with and used in conjunction with the other modules in the #
|
9
|
+
# Amp project, please see the root-level LICENSE file. #
|
10
|
+
# #
|
11
|
+
# © Michael J. Edgar and Ari Brown, 2009-2010 #
|
12
|
+
# #
|
13
|
+
##################################################################
|
14
|
+
|
15
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper'))
|
16
|
+
|
@@ -0,0 +1,69 @@
|
|
1
|
+
##################################################################
|
2
|
+
# Licensing Information #
|
3
|
+
# #
|
4
|
+
# The following code is licensed, as standalone code, under #
|
5
|
+
# the Ruby License, unless otherwise directed within the code. #
|
6
|
+
# #
|
7
|
+
# For information on the license of this code when distributed #
|
8
|
+
# with and used in conjunction with the other modules in the #
|
9
|
+
# Amp project, please see the root-level LICENSE file. #
|
10
|
+
# #
|
11
|
+
# © Michael J. Edgar and Ari Brown, 2009-2010 #
|
12
|
+
# #
|
13
|
+
##################################################################
|
14
|
+
|
15
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
|
16
|
+
|
17
|
+
class TestGitIndex < AmpTestCase
|
18
|
+
include Amp::Core::Repositories::Git
|
19
|
+
INPUT_FILE = "index"
|
20
|
+
|
21
|
+
def setup
|
22
|
+
super
|
23
|
+
@opener = Amp::Core::Support::RootedOpener.new(File.expand_path(File.dirname(__FILE__)))
|
24
|
+
@opener.default = :open_file # for testing purposes!
|
25
|
+
@index = Amp::Core::Repositories::Git::Index.parse(INPUT_FILE, @opener)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_open_index
|
29
|
+
assert_not_nil @index
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_lookup_fails
|
33
|
+
assert_nil @index["roflkopterz"]
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_failed_fourcc
|
37
|
+
self.write_file "fakeindex" do |io|
|
38
|
+
io << "DIRT\x00\x00\x00\x02"
|
39
|
+
end
|
40
|
+
opener = Amp::Core::Support::RootedOpener.new(tempdir)
|
41
|
+
opener.default = :open_file
|
42
|
+
assert_raises Index::IndexParseError do
|
43
|
+
Amp::Core::Repositories::Git::Index.parse("fakeindex", opener)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_lookup_succeeds
|
48
|
+
assert_not_nil @index["Rakefile"]
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_info_loads
|
52
|
+
rakefile_info = @index["Rakefile"]
|
53
|
+
assert_equal 0x4be39e30, rakefile_info.ctime
|
54
|
+
assert_equal 0, rakefile_info.ctime_ns
|
55
|
+
assert_equal 0x4be39e30, rakefile_info.mtime
|
56
|
+
assert_equal 0, rakefile_info.mtime_ns
|
57
|
+
assert_equal 0x0e000003, rakefile_info.dev
|
58
|
+
assert_equal 0x01d75ecc, rakefile_info.inode
|
59
|
+
assert_equal 0x81a4, rakefile_info.mode
|
60
|
+
assert_equal 0x01f5, rakefile_info.uid
|
61
|
+
assert_equal 0x14, rakefile_info.gid
|
62
|
+
assert_equal 0x05c5, rakefile_info.size
|
63
|
+
assert_equal "53bbb0b38868a1bd2059a1174f54de63764013af", hexlify(rakefile_info.hash_id)
|
64
|
+
assert_false rakefile_info.assume_valid
|
65
|
+
assert_false rakefile_info.update_needed
|
66
|
+
assert_equal 0, rakefile_info.stage
|
67
|
+
assert_equal "Rakefile", rakefile_info.name
|
68
|
+
end
|
69
|
+
end
|
Binary file
|
Binary file
|
@@ -0,0 +1,16 @@
|
|
1
|
+
##################################################################
|
2
|
+
# Licensing Information #
|
3
|
+
# #
|
4
|
+
# The following code is licensed, as standalone code, under #
|
5
|
+
# the Ruby License, unless otherwise directed within the code. #
|
6
|
+
# #
|
7
|
+
# For information on the license of this code when distributed #
|
8
|
+
# with and used in conjunction with the other modules in the #
|
9
|
+
# Amp project, please see the root-level LICENSE file. #
|
10
|
+
# #
|
11
|
+
# © Michael J. Edgar and Ari Brown, 2009-2010 #
|
12
|
+
# #
|
13
|
+
##################################################################
|
14
|
+
|
15
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper'))
|
16
|
+
|