schacon-git 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README +238 -0
- data/lib/git/author.rb +14 -0
- data/lib/git/base.rb +464 -0
- data/lib/git/branch.rb +106 -0
- data/lib/git/branches.rb +57 -0
- data/lib/git/diff.rb +143 -0
- data/lib/git/index.rb +5 -0
- data/lib/git/lib.rb +638 -0
- data/lib/git/log.rb +94 -0
- data/lib/git/object.rb +296 -0
- data/lib/git/path.rb +27 -0
- data/lib/git/remote.rb +42 -0
- data/lib/git/repository.rb +4 -0
- data/lib/git/stash.rb +26 -0
- data/lib/git/stashes.rb +49 -0
- data/lib/git/status.rb +118 -0
- data/lib/git/working_directory.rb +4 -0
- data/lib/git.rb +96 -0
- data/tests/all_tests.rb +4 -0
- data/tests/test_helper.rb +77 -0
- metadata +72 -0
data/lib/git.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
|
2
|
+
# Add the directory containing this file to the start of the load path if it
|
3
|
+
# isn't there already.
|
4
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
5
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
6
|
+
|
7
|
+
require 'git/base'
|
8
|
+
require 'git/path'
|
9
|
+
require 'git/lib'
|
10
|
+
|
11
|
+
require 'git/repository'
|
12
|
+
require 'git/index'
|
13
|
+
require 'git/working_directory'
|
14
|
+
|
15
|
+
require 'git/log'
|
16
|
+
require 'git/object'
|
17
|
+
|
18
|
+
require 'git/branches'
|
19
|
+
require 'git/branch'
|
20
|
+
require 'git/remote'
|
21
|
+
|
22
|
+
require 'git/diff'
|
23
|
+
require 'git/status'
|
24
|
+
require 'git/author'
|
25
|
+
|
26
|
+
require 'git/stashes'
|
27
|
+
require 'git/stash'
|
28
|
+
|
29
|
+
|
30
|
+
# Git/Ruby Library
|
31
|
+
#
|
32
|
+
# This provides bindings for working with git in complex
|
33
|
+
# interactions, including branching and merging, object
|
34
|
+
# inspection and manipulation, history, patch generation
|
35
|
+
# and more. You should be able to do most fundamental git
|
36
|
+
# operations with this library.
|
37
|
+
#
|
38
|
+
# This module provides the basic functions to open a git
|
39
|
+
# reference to work with. You can open a working directory,
|
40
|
+
# open a bare repository, initialize a new repo or clone an
|
41
|
+
# existing remote repository.
|
42
|
+
#
|
43
|
+
# Author:: Scott Chacon (mailto:schacon@gmail.com)
|
44
|
+
# License:: MIT License
|
45
|
+
module Git
|
46
|
+
|
47
|
+
VERSION = '1.0.4'
|
48
|
+
|
49
|
+
# open a bare repository
|
50
|
+
#
|
51
|
+
# this takes the path to a bare git repo
|
52
|
+
# it expects not to be able to use a working directory
|
53
|
+
# so you can't checkout stuff, commit things, etc.
|
54
|
+
# but you can do most read operations
|
55
|
+
def self.bare(git_dir, options = {})
|
56
|
+
Base.bare(git_dir, options)
|
57
|
+
end
|
58
|
+
|
59
|
+
# open an existing git working directory
|
60
|
+
#
|
61
|
+
# this will most likely be the most common way to create
|
62
|
+
# a git reference, referring to a working directory.
|
63
|
+
# if not provided in the options, the library will assume
|
64
|
+
# your git_dir and index are in the default place (.git/, .git/index)
|
65
|
+
#
|
66
|
+
# options
|
67
|
+
# :repository => '/path/to/alt_git_dir'
|
68
|
+
# :index => '/path/to/alt_index_file'
|
69
|
+
def self.open(working_dir, options = {})
|
70
|
+
Base.open(working_dir, options)
|
71
|
+
end
|
72
|
+
|
73
|
+
# initialize a new git repository, defaults to the current working directory
|
74
|
+
#
|
75
|
+
# options
|
76
|
+
# :repository => '/path/to/alt_git_dir'
|
77
|
+
# :index => '/path/to/alt_index_file'
|
78
|
+
def self.init(working_dir = '.', options = {})
|
79
|
+
Base.init(working_dir, options)
|
80
|
+
end
|
81
|
+
|
82
|
+
# clones a remote repository
|
83
|
+
#
|
84
|
+
# options
|
85
|
+
# :bare => true (does a bare clone)
|
86
|
+
# :repository => '/path/to/alt_git_dir'
|
87
|
+
# :index => '/path/to/alt_index_file'
|
88
|
+
#
|
89
|
+
# example
|
90
|
+
# Git.clone('git://repo.or.cz/rubygit.git', 'clone.git', :bare => true)
|
91
|
+
#
|
92
|
+
def self.clone(repository, name, options = {})
|
93
|
+
Base.clone(repository, name, options)
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
data/tests/all_tests.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'logger'
|
4
|
+
require File.dirname(__FILE__) + '/../lib/git'
|
5
|
+
|
6
|
+
class Test::Unit::TestCase
|
7
|
+
|
8
|
+
def set_file_paths
|
9
|
+
cwd = `pwd`.chomp
|
10
|
+
if File.directory?(File.join(cwd, 'files'))
|
11
|
+
@test_dir = File.join(cwd, 'files')
|
12
|
+
elsif File.directory?(File.join(cwd, '..', 'files'))
|
13
|
+
@test_dir = File.join(cwd, '..', 'files')
|
14
|
+
elsif File.directory?(File.join(cwd, 'tests', 'files'))
|
15
|
+
@test_dir = File.join(cwd, 'tests', 'files')
|
16
|
+
end
|
17
|
+
|
18
|
+
@wdir_dot = File.expand_path(File.join(@test_dir, 'working'))
|
19
|
+
@wbare = File.expand_path(File.join(@test_dir, 'working.git'))
|
20
|
+
@index = File.expand_path(File.join(@test_dir, 'index'))
|
21
|
+
|
22
|
+
@wdir = create_temp_repo(@wdir_dot)
|
23
|
+
end
|
24
|
+
|
25
|
+
def teardown
|
26
|
+
if @tmp_path
|
27
|
+
#puts "teardown #{@tmp_path}"
|
28
|
+
FileUtils.rm_r(@tmp_path)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def with_temp_bare
|
34
|
+
in_temp_dir do |path|
|
35
|
+
g = Git.clone(@wbare, 'new')
|
36
|
+
Dir.chdir('new') do
|
37
|
+
yield g
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def create_temp_repo(clone_path)
|
43
|
+
filename = 'git_test' + Time.now.to_i.to_s + rand(300).to_s.rjust(3, '0')
|
44
|
+
@tmp_path = File.join("/tmp/", filename)
|
45
|
+
FileUtils.mkdir_p(@tmp_path)
|
46
|
+
FileUtils.cp_r(clone_path, @tmp_path)
|
47
|
+
tmp_path = File.join(@tmp_path, 'working')
|
48
|
+
Dir.chdir(tmp_path) do
|
49
|
+
FileUtils.mv('dot_git', '.git')
|
50
|
+
end
|
51
|
+
tmp_path
|
52
|
+
end
|
53
|
+
|
54
|
+
def in_temp_dir(remove_after = true)
|
55
|
+
filename = 'git_test' + Time.now.to_i.to_s + rand(300).to_s.rjust(3, '0')
|
56
|
+
tmp_path = File.join("/tmp/", filename)
|
57
|
+
FileUtils.mkdir(tmp_path)
|
58
|
+
Dir.chdir tmp_path do
|
59
|
+
yield tmp_path
|
60
|
+
end
|
61
|
+
FileUtils.rm_r(tmp_path) if remove_after
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
def new_file(name, contents)
|
66
|
+
File.open(name, 'w') do |f|
|
67
|
+
f.puts contents
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def append_file(name, contents)
|
72
|
+
File.open(name, 'a') do |f|
|
73
|
+
f.puts contents
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: schacon-git
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Scott Chacon
|
8
|
+
autorequire: git
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-05-14 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: schacon@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
files:
|
25
|
+
- lib/git
|
26
|
+
- lib/git/author.rb
|
27
|
+
- lib/git/base.rb
|
28
|
+
- lib/git/branch.rb
|
29
|
+
- lib/git/branches.rb
|
30
|
+
- lib/git/diff.rb
|
31
|
+
- lib/git/index.rb
|
32
|
+
- lib/git/lib.rb
|
33
|
+
- lib/git/log.rb
|
34
|
+
- lib/git/object.rb
|
35
|
+
- lib/git/path.rb
|
36
|
+
- lib/git/remote.rb
|
37
|
+
- lib/git/repository.rb
|
38
|
+
- lib/git/stash.rb
|
39
|
+
- lib/git/stashes.rb
|
40
|
+
- lib/git/status.rb
|
41
|
+
- lib/git/working_directory.rb
|
42
|
+
- lib/git.rb
|
43
|
+
- README
|
44
|
+
has_rdoc: true
|
45
|
+
homepage:
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
version:
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
version:
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.0.1
|
67
|
+
signing_key:
|
68
|
+
specification_version: 2
|
69
|
+
summary: A package for using Git in Ruby code.
|
70
|
+
test_files:
|
71
|
+
- tests/all_tests.rb
|
72
|
+
- tests/test_helper.rb
|