fake_git 0.1.0
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 +7 -0
- data/.gitignore +16 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +21 -0
- data/Makefile +9 -0
- data/README.md +72 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/fakegit +47 -0
- data/fake_git.gemspec +36 -0
- data/lib/fake_git.rb +37 -0
- data/lib/fake_git/cat_file.rb +27 -0
- data/lib/fake_git/commit_tree.rb +24 -0
- data/lib/fake_git/fetch_object.rb +30 -0
- data/lib/fake_git/hash_object.rb +15 -0
- data/lib/fake_git/init.rb +12 -0
- data/lib/fake_git/list_objects.rb +19 -0
- data/lib/fake_git/log.rb +25 -0
- data/lib/fake_git/priv/object.rb +55 -0
- data/lib/fake_git/update_index.rb +29 -0
- data/lib/fake_git/update_ref.rb +8 -0
- data/lib/fake_git/version.rb +3 -0
- data/lib/fake_git/write_tree.rb +38 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8cb8de5b4db23fa53c1ab63c3bd091d5cf01c9a6
|
4
|
+
data.tar.gz: 98bf019ca950e50a22878fe0e1c0dbc2ca8a4e5e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9653d9b04109385c5933deb39cfd3984807778065465bb05cbdbbf203880c1bfcde37d9b9a9e4e1b922b582eb6d7358e188f2c8ca9ff368970543555bfa9ddfb
|
7
|
+
data.tar.gz: 3e942eabc2daf09de27c93860e9aadc0a0c085fb8345e50d6e2200ef29f53843055535dddaa10dcaa1f5177c1123dbcad56839ff9522d6a03fdba9186620c97d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
fake_git (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
rake (10.4.2)
|
11
|
+
rspec (3.6.0)
|
12
|
+
rspec-core (~> 3.6.0)
|
13
|
+
rspec-expectations (~> 3.6.0)
|
14
|
+
rspec-mocks (~> 3.6.0)
|
15
|
+
rspec-core (3.6.0)
|
16
|
+
rspec-support (~> 3.6.0)
|
17
|
+
rspec-expectations (3.6.0)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.6.0)
|
20
|
+
rspec-mocks (3.6.0)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.6.0)
|
23
|
+
rspec-support (3.6.0)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.16)
|
30
|
+
fake_git!
|
31
|
+
rake (~> 10.0)
|
32
|
+
rspec (~> 3.0)
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 pauloancheta
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/Makefile
ADDED
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# FakeGit
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/fake/git`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'fake-git'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install fake-git
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Create a manual fakegit commit by following these steps:
|
26
|
+
|
27
|
+
1. hash-object
|
28
|
+
```
|
29
|
+
echo "hello world [or your fancy string to commit]" | fakegit hash-object -w --stdin
|
30
|
+
```
|
31
|
+
|
32
|
+
1. write-tree
|
33
|
+
```
|
34
|
+
$ fakegit write-tree
|
35
|
+
# output is a sha1 (index) of the tree object
|
36
|
+
```
|
37
|
+
|
38
|
+
1. update-ref
|
39
|
+
```
|
40
|
+
$ fakegit update-ref
|
41
|
+
```
|
42
|
+
|
43
|
+
1. commit-tree
|
44
|
+
```
|
45
|
+
fakegit <tree object sha to commit> -m "your message"
|
46
|
+
```
|
47
|
+
|
48
|
+
1. log
|
49
|
+
```
|
50
|
+
fakegit log
|
51
|
+
```
|
52
|
+
|
53
|
+
Verify your objects by using cat-file
|
54
|
+
```
|
55
|
+
fakegit cat-file -s <OBJECT SHA (INDEX)> # to see the filesize
|
56
|
+
fakegit cat-file -t <OBJECT SHA (INDEX)> # to see the object type
|
57
|
+
fakegit cat-file -p <OBJECT SHA (INDEX)> # to see the print the content
|
58
|
+
```
|
59
|
+
|
60
|
+
## Development
|
61
|
+
|
62
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
63
|
+
|
64
|
+
To install this gem onto your local machine, run `make install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
65
|
+
|
66
|
+
## Contributing
|
67
|
+
|
68
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/pauloancheta/fake-git.
|
69
|
+
|
70
|
+
## License
|
71
|
+
|
72
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "fake/git"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/fakegit
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "fake/git"
|
4
|
+
require "optparse"
|
5
|
+
|
6
|
+
# Parse options
|
7
|
+
$OPTIONS = Hash.new
|
8
|
+
OptionParser.new do |opts|
|
9
|
+
opts.set_banner "Welcome to FakeGit"
|
10
|
+
opts.on("--stdin", "Get output from stdin") do
|
11
|
+
$OPTIONS[:stdin] = true
|
12
|
+
end
|
13
|
+
|
14
|
+
opts.on("-w", "Introduce writeable") do
|
15
|
+
$OPTIONS[:stdin] = true
|
16
|
+
end
|
17
|
+
|
18
|
+
opts.on("-s", "get size for catfile") { $OPTIONS[:cat_file_size] = true }
|
19
|
+
opts.on("-p", "print for catfile") { $OPTIONS[:cat_file_print] = true }
|
20
|
+
opts.on("-t", "type for catfile") { $OPTIONS[:cat_file_type] = true }
|
21
|
+
|
22
|
+
opts.on("--add", "silence option for update-index") { $OPTIONS[:update_index_add] = true }
|
23
|
+
opts.on("--cache-info", "get file info for object") { |v| $OPTIONS[:update_index_cache_info] = v }
|
24
|
+
|
25
|
+
opts.on("-m", "--message [message]", "commit message") { |msg| $OPTIONS[:commit_message] = msg }
|
26
|
+
end.parse!
|
27
|
+
|
28
|
+
# begin exe
|
29
|
+
|
30
|
+
cmd, _ = ARGV
|
31
|
+
if cmd.nil? || !$OPTIONS[:stdin]
|
32
|
+
FakeGit.call(ARGV)
|
33
|
+
return
|
34
|
+
end
|
35
|
+
|
36
|
+
# with stdin
|
37
|
+
while input = STDIN.gets
|
38
|
+
input.each_line do |line|
|
39
|
+
begin
|
40
|
+
full_cmd = [cmd, line].flatten
|
41
|
+
|
42
|
+
FakeGit.call( full_cmd )
|
43
|
+
rescue Errno::EPIPE
|
44
|
+
exit(74)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/fake_git.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "fake_git/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "fake_git"
|
8
|
+
spec.version = FakeGit::VERSION
|
9
|
+
spec.authors = ["pauloancheta"]
|
10
|
+
spec.email = ["paulo.ancheta@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Fake git using ruby"
|
13
|
+
spec.description = "Trying to replicate git using ruby"
|
14
|
+
spec.homepage = "https://www.github.com/pauloancheta/fake-git"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
# else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
# "public gem pushes."
|
24
|
+
# end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
36
|
+
end
|
data/lib/fake_git.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require "fake/git/version"
|
2
|
+
|
3
|
+
require_relative "git/cat_file"
|
4
|
+
require_relative "git/commit_tree"
|
5
|
+
require_relative "git/fetch_object"
|
6
|
+
require_relative "git/hash_object"
|
7
|
+
require_relative "git/init"
|
8
|
+
require_relative "git/list_objects"
|
9
|
+
require_relative "git/log"
|
10
|
+
require_relative "git/update_index"
|
11
|
+
require_relative "git/update_ref"
|
12
|
+
require_relative "git/write_tree"
|
13
|
+
|
14
|
+
require_relative "git/priv/object"
|
15
|
+
|
16
|
+
HELP = """
|
17
|
+
WELCOME TO FAKEGIT
|
18
|
+
|
19
|
+
usage:
|
20
|
+
$> echo 'hello world' | fakegit hash-object
|
21
|
+
"""
|
22
|
+
|
23
|
+
module FakeGit
|
24
|
+
def self.call(*args)
|
25
|
+
cmds = args.flatten
|
26
|
+
|
27
|
+
if cmds.empty?
|
28
|
+
puts HELP
|
29
|
+
return
|
30
|
+
end
|
31
|
+
|
32
|
+
klass = cmds.first.split("-").map(&:capitalize).join
|
33
|
+
sub_cmd = cmds[1..-1].join(" ")
|
34
|
+
|
35
|
+
const_get("#{klass}").new.call(sub_cmd)
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative 'priv/object'
|
2
|
+
require_relative 'fetch_object'
|
3
|
+
|
4
|
+
class FakeGit::CatFile
|
5
|
+
def call(*args)
|
6
|
+
obj = FakeGit::FetchObject.new.call(args.first)
|
7
|
+
|
8
|
+
return file_size(obj) if $OPTIONS[:cat_file_size]
|
9
|
+
return file_print(obj) if $OPTIONS[:cat_file_print]
|
10
|
+
return file_type(obj) if $OPTIONS[:cat_file_type]
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def file_size(obj)
|
15
|
+
result = `du -h #{obj.path}`
|
16
|
+
puts result.split.first
|
17
|
+
end
|
18
|
+
|
19
|
+
def file_print(obj)
|
20
|
+
puts obj.content
|
21
|
+
end
|
22
|
+
|
23
|
+
def file_type(obj)
|
24
|
+
puts obj.type
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative 'fetch_object'
|
2
|
+
require_relative 'update_ref'
|
3
|
+
require 'digest'
|
4
|
+
|
5
|
+
class FakeGit::CommitTree
|
6
|
+
def call(*args)
|
7
|
+
# make sure that the object exists
|
8
|
+
obj = FakeGit::FetchObject.new.call(args.first)
|
9
|
+
|
10
|
+
raise TypeError.new("#{args.first} is not a tree") if obj.type != "tree"
|
11
|
+
|
12
|
+
commit = FakeGit::Priv::Object.new(
|
13
|
+
type: "commit",
|
14
|
+
message: $OPTIONS[:commit_message],
|
15
|
+
tree: obj.index,
|
16
|
+
index: Digest::SHA1.hexdigest(obj.index), # just hash the index of the tree
|
17
|
+
)
|
18
|
+
|
19
|
+
commit.write!
|
20
|
+
FakeGit::UpdateRef.new.call(commit.index)
|
21
|
+
end
|
22
|
+
|
23
|
+
class TypeError < StandardError; end
|
24
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require_relative 'priv/object'
|
2
|
+
|
3
|
+
class FakeGit::FetchObject
|
4
|
+
OBJ_PATH = ".fakegit/objects"
|
5
|
+
|
6
|
+
def call(*args)
|
7
|
+
index, _ = args.first.split(" ")
|
8
|
+
path = file_path(index)
|
9
|
+
build_obj(path)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
def build_obj(path)
|
14
|
+
content = File.read(path)
|
15
|
+
attributes = Hash.new
|
16
|
+
|
17
|
+
content.split(",").each do |c|
|
18
|
+
key, val = c.split("=")
|
19
|
+
attributes[key.to_sym] = val
|
20
|
+
end
|
21
|
+
|
22
|
+
FakeGit::Priv::Object.new(
|
23
|
+
attributes.merge(path: path)
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def file_path(arg)
|
28
|
+
"#{OBJ_PATH}/#{arg[0..1]}/#{arg[2..-1]}"
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'digest'
|
2
|
+
require_relative 'priv/object'
|
3
|
+
|
4
|
+
class FakeGit::HashObject
|
5
|
+
def call(*args)
|
6
|
+
obj = FakeGit::Priv::Object.new(
|
7
|
+
type: "blob",
|
8
|
+
content: args.first,
|
9
|
+
index: Digest::SHA1.hexdigest(args.first)
|
10
|
+
)
|
11
|
+
|
12
|
+
obj.write!
|
13
|
+
obj
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class Init
|
2
|
+
def call(*args)
|
3
|
+
new_folder = "#{args.first}/" if args.nil? || args.empty?
|
4
|
+
|
5
|
+
`mkdir -p #{new_folder}.fakegit/objects/`
|
6
|
+
`mkdir -p #{new_folder}.fakegit/refs/heads/`
|
7
|
+
`touch #{new_folder}.fakegit/refs/heads/master`
|
8
|
+
|
9
|
+
base_folder = !!new_folder ? new_folder : "fakegit"
|
10
|
+
puts "#{base_folder} has been initialized"
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative "fetch_object"
|
2
|
+
|
3
|
+
class FakeGit::ListObjects
|
4
|
+
def call(*args)
|
5
|
+
collection = []
|
6
|
+
file_names.each do |file|
|
7
|
+
pruned = file.gsub(".fakegit/objects/", "")
|
8
|
+
index = pruned.split("/").join
|
9
|
+
collection << FakeGit::FetchObject.new.call(index)
|
10
|
+
end
|
11
|
+
|
12
|
+
collection
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def file_names
|
17
|
+
`find .fakegit/objects -type f`.split("\n")
|
18
|
+
end
|
19
|
+
end
|
data/lib/fake_git/log.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative "list_objects"
|
2
|
+
|
3
|
+
class FakeGit::Log
|
4
|
+
def call(*args)
|
5
|
+
commit_objects.each do |obj|
|
6
|
+
logger(obj)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
def commit_objects
|
12
|
+
FakeGit::ListObjects.new.call.select do |obj|
|
13
|
+
obj.type == "commit"
|
14
|
+
end.sort { |a, b| a.date <=> b.date }
|
15
|
+
end
|
16
|
+
|
17
|
+
def logger(obj)
|
18
|
+
puts """
|
19
|
+
commit #{obj.index}
|
20
|
+
Date: #{obj.date}
|
21
|
+
|
22
|
+
#{obj.message}
|
23
|
+
"""
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module FakeGit::Priv
|
2
|
+
class Object
|
3
|
+
ALLOWED_TYPES = ["blob", "tree", "commit", "tag", nil]
|
4
|
+
OBJ_PATH = ".fakegit/objects"
|
5
|
+
|
6
|
+
attr_accessor :type, :content, :index, :path, :file_name, :message, :tree, :date
|
7
|
+
|
8
|
+
def initialize(type: nil,
|
9
|
+
content: nil,
|
10
|
+
index: nil,
|
11
|
+
path: nil,
|
12
|
+
file_name: nil,
|
13
|
+
message: nil,
|
14
|
+
tree: nil,
|
15
|
+
date: nil)
|
16
|
+
@type = type
|
17
|
+
@content = content
|
18
|
+
@index = index
|
19
|
+
@path = path
|
20
|
+
@file_name = file_name
|
21
|
+
@message = message
|
22
|
+
@tree = tree
|
23
|
+
@date = Time.now
|
24
|
+
|
25
|
+
raise TypeError.new("#{type} must be one of #{ALLOWED_TYPES}") if !ALLOWED_TYPES.include?(@type)
|
26
|
+
end
|
27
|
+
|
28
|
+
def write!
|
29
|
+
write_top_index
|
30
|
+
write_new_index
|
31
|
+
puts index
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def write_top_index
|
36
|
+
`mkdir -p #{OBJ_PATH}/#{index[0..1]}`
|
37
|
+
end
|
38
|
+
|
39
|
+
def write_new_index
|
40
|
+
path = "#{OBJ_PATH}/#{index[0..1]}/#{index[2..-1]}"
|
41
|
+
|
42
|
+
File.open(path, 'w') do |file|
|
43
|
+
file.write("type=#{type},")
|
44
|
+
file.write("index=#{index},")
|
45
|
+
file.write("file_name=#{file_name},")
|
46
|
+
file.write("path=#{path},")
|
47
|
+
file.write("content=#{content},")
|
48
|
+
file.write("message=#{message},")
|
49
|
+
file.write("tree=#{tree},")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class TypeError < StandardError; end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# git update-index --add --cache-info 100644 3b18e512dba79e4c8300dd08aeb37f8e728b8dad hello.txt
|
2
|
+
|
3
|
+
require_relative 'priv/object'
|
4
|
+
require_relative 'fetch_object'
|
5
|
+
|
6
|
+
class FakeGit::UpdateIndex
|
7
|
+
def call(*args)
|
8
|
+
get_obj_type $OPTIONS[:update_index_cache_info]
|
9
|
+
index, file_name = args.first.split(" ")
|
10
|
+
|
11
|
+
obj = FakeGit::FetchObject.new.call(index)
|
12
|
+
update_filename(obj, file_name)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def get_obj_type(cache_info)
|
17
|
+
case cache_info.to_i
|
18
|
+
when 100644
|
19
|
+
"blob"
|
20
|
+
else
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def update_filename(obj, file_name)
|
26
|
+
obj.file_name = file_name
|
27
|
+
obj.write!
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'digest'
|
2
|
+
|
3
|
+
class FakeGit::WriteTree
|
4
|
+
OBJ_PATH = ".fakegit/objects"
|
5
|
+
def call(*args)
|
6
|
+
obj = FakeGit::Priv::Object.new(
|
7
|
+
type: "tree",
|
8
|
+
content: tree,
|
9
|
+
index: Digest::SHA1.hexdigest(tree)
|
10
|
+
)
|
11
|
+
puts obj.index
|
12
|
+
write(obj)
|
13
|
+
obj.index
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def tree
|
18
|
+
`find .fakegit -type f`
|
19
|
+
end
|
20
|
+
|
21
|
+
def write(obj)
|
22
|
+
write_top_index(obj)
|
23
|
+
write_new_index(obj)
|
24
|
+
end
|
25
|
+
|
26
|
+
def write_top_index(obj)
|
27
|
+
`mkdir -p #{OBJ_PATH}/#{obj.index[0..1]}`
|
28
|
+
end
|
29
|
+
|
30
|
+
def write_new_index(obj)
|
31
|
+
path = "#{OBJ_PATH}/#{obj.index[0..1]}/#{obj.index[2..-1]}"
|
32
|
+
File.open(path, 'w') do |file|
|
33
|
+
file.write("index=#{obj.index},")
|
34
|
+
file.write("type=#{obj.type},")
|
35
|
+
file.write("content=#{obj.content}")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fake_git
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- pauloancheta
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: Trying to replicate git using ruby
|
56
|
+
email:
|
57
|
+
- paulo.ancheta@gmail.com
|
58
|
+
executables:
|
59
|
+
- fakegit
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- Gemfile
|
67
|
+
- Gemfile.lock
|
68
|
+
- LICENSE.txt
|
69
|
+
- Makefile
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- bin/console
|
73
|
+
- bin/setup
|
74
|
+
- exe/fakegit
|
75
|
+
- fake_git.gemspec
|
76
|
+
- lib/fake_git.rb
|
77
|
+
- lib/fake_git/cat_file.rb
|
78
|
+
- lib/fake_git/commit_tree.rb
|
79
|
+
- lib/fake_git/fetch_object.rb
|
80
|
+
- lib/fake_git/hash_object.rb
|
81
|
+
- lib/fake_git/init.rb
|
82
|
+
- lib/fake_git/list_objects.rb
|
83
|
+
- lib/fake_git/log.rb
|
84
|
+
- lib/fake_git/priv/object.rb
|
85
|
+
- lib/fake_git/update_index.rb
|
86
|
+
- lib/fake_git/update_ref.rb
|
87
|
+
- lib/fake_git/version.rb
|
88
|
+
- lib/fake_git/write_tree.rb
|
89
|
+
homepage: https://www.github.com/pauloancheta/fake-git
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.6.11
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Fake git using ruby
|
113
|
+
test_files: []
|