ruby-git-lacravate 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +242 -0
- data/lib/git/author.rb +14 -0
- data/lib/git/base.rb +485 -0
- data/lib/git/branch.rb +111 -0
- data/lib/git/branches.rb +48 -0
- data/lib/git/diff.rb +146 -0
- data/lib/git/index.rb +5 -0
- data/lib/git/lib.rb +765 -0
- data/lib/git/log.rb +126 -0
- data/lib/git/object.rb +273 -0
- data/lib/git/path.rb +27 -0
- data/lib/git/remote.rb +40 -0
- data/lib/git/repository.rb +4 -0
- data/lib/git/stash.rb +27 -0
- data/lib/git/stashes.rb +44 -0
- data/lib/git/status.rb +110 -0
- data/lib/git/working_directory.rb +4 -0
- data/lib/git.rb +156 -0
- data/tests/all_tests.rb +5 -0
- data/tests/test_helper.rb +67 -0
- metadata +68 -0
data/lib/git.rb
ADDED
@@ -0,0 +1,156 @@
|
|
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
|
+
lib = Git::Lib.new(nil, nil)
|
30
|
+
unless lib.meets_required_version?
|
31
|
+
$stderr.puts "[WARNING] The git gem requires git #{lib.required_command_version.join('.')} or later, but only found #{lib.current_command_version.join('.')}. You should probably upgrade."
|
32
|
+
end
|
33
|
+
|
34
|
+
# Git/Ruby Library
|
35
|
+
#
|
36
|
+
# This provides bindings for working with git in complex
|
37
|
+
# interactions, including branching and merging, object
|
38
|
+
# inspection and manipulation, history, patch generation
|
39
|
+
# and more. You should be able to do most fundamental git
|
40
|
+
# operations with this library.
|
41
|
+
#
|
42
|
+
# This module provides the basic functions to open a git
|
43
|
+
# reference to work with. You can open a working directory,
|
44
|
+
# open a bare repository, initialize a new repo or clone an
|
45
|
+
# existing remote repository.
|
46
|
+
#
|
47
|
+
# Author:: Scott Chacon (mailto:schacon@gmail.com)
|
48
|
+
# License:: MIT License
|
49
|
+
module Git
|
50
|
+
|
51
|
+
VERSION = '1.0.4'
|
52
|
+
|
53
|
+
# open a bare repository
|
54
|
+
#
|
55
|
+
# this takes the path to a bare git repo
|
56
|
+
# it expects not to be able to use a working directory
|
57
|
+
# so you can't checkout stuff, commit things, etc.
|
58
|
+
# but you can do most read operations
|
59
|
+
def self.bare(git_dir, options = {})
|
60
|
+
Base.bare(git_dir, options)
|
61
|
+
end
|
62
|
+
|
63
|
+
# open an existing git working directory
|
64
|
+
#
|
65
|
+
# this will most likely be the most common way to create
|
66
|
+
# a git reference, referring to a working directory.
|
67
|
+
# if not provided in the options, the library will assume
|
68
|
+
# your git_dir and index are in the default place (.git/, .git/index)
|
69
|
+
#
|
70
|
+
# options
|
71
|
+
# :repository => '/path/to/alt_git_dir'
|
72
|
+
# :index => '/path/to/alt_index_file'
|
73
|
+
def self.open(working_dir, options = {})
|
74
|
+
Base.open(working_dir, options)
|
75
|
+
end
|
76
|
+
|
77
|
+
# initialize a new git repository, defaults to the current working directory
|
78
|
+
#
|
79
|
+
# options
|
80
|
+
# :repository => '/path/to/alt_git_dir'
|
81
|
+
# :index => '/path/to/alt_index_file'
|
82
|
+
def self.init(working_dir = '.', options = {})
|
83
|
+
Base.init(working_dir, options)
|
84
|
+
end
|
85
|
+
|
86
|
+
# clones a remote repository
|
87
|
+
#
|
88
|
+
# options
|
89
|
+
# :bare => true (does a bare clone)
|
90
|
+
# :repository => '/path/to/alt_git_dir'
|
91
|
+
# :index => '/path/to/alt_index_file'
|
92
|
+
#
|
93
|
+
# example
|
94
|
+
# Git.clone('git://repo.or.cz/rubygit.git', 'clone.git', :bare => true)
|
95
|
+
#
|
96
|
+
def self.clone(repository, name, options = {})
|
97
|
+
Base.clone(repository, name, options)
|
98
|
+
end
|
99
|
+
|
100
|
+
# Export the current HEAD (or a branch, if <tt>options[:branch]</tt>
|
101
|
+
# is specified) into the +name+ directory, then remove all traces of git from the
|
102
|
+
# directory.
|
103
|
+
#
|
104
|
+
# See +clone+ for options. Does not obey the <tt>:remote</tt> option,
|
105
|
+
# since the .git info will be deleted anyway; always uses the default
|
106
|
+
# remote, 'origin.'
|
107
|
+
def self.export(repository, name, options = {})
|
108
|
+
options.delete(:remote)
|
109
|
+
repo = clone(repository, name, {:depth => 1}.merge(options))
|
110
|
+
repo.checkout("origin/#{options[:branch]}") if options[:branch]
|
111
|
+
Dir.chdir(repo.dir.to_s) { FileUtils.rm_r '.git' }
|
112
|
+
end
|
113
|
+
|
114
|
+
#g.config('user.name', 'Scott Chacon') # sets value
|
115
|
+
#g.config('user.email', 'email@email.com') # sets value
|
116
|
+
#g.config('user.name') # returns 'Scott Chacon'
|
117
|
+
#g.config # returns whole config hash
|
118
|
+
def config(name = nil, value = nil)
|
119
|
+
lib = Git::Lib.new
|
120
|
+
if(name && value)
|
121
|
+
# set value
|
122
|
+
lib.config_set(name, value)
|
123
|
+
elsif (name)
|
124
|
+
# return value
|
125
|
+
lib.config_get(name)
|
126
|
+
else
|
127
|
+
# return hash
|
128
|
+
lib.config_list
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
# Same as g.config, but forces it to be at the global level
|
133
|
+
#
|
134
|
+
#g.config('user.name', 'Scott Chacon') # sets value
|
135
|
+
#g.config('user.email', 'email@email.com') # sets value
|
136
|
+
#g.config('user.name') # returns 'Scott Chacon'
|
137
|
+
#g.config # returns whole config hash
|
138
|
+
def self.global_config(name = nil, value = nil)
|
139
|
+
lib = Git::Lib.new(nil, nil)
|
140
|
+
if(name && value)
|
141
|
+
# set value
|
142
|
+
lib.global_config_set(name, value)
|
143
|
+
elsif (name)
|
144
|
+
# return value
|
145
|
+
lib.global_config_get(name)
|
146
|
+
else
|
147
|
+
# return hash
|
148
|
+
lib.global_config_list
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def global_config(name = nil, value = nil)
|
153
|
+
self.class.global_config(name, value)
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
data/tests/all_tests.rb
ADDED
@@ -0,0 +1,67 @@
|
|
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
|
+
def create_temp_repo(clone_path)
|
33
|
+
filename = 'git_test' + Time.now.to_i.to_s + rand(300).to_s.rjust(3, '0')
|
34
|
+
@tmp_path = File.join("/tmp/", filename)
|
35
|
+
FileUtils.mkdir_p(@tmp_path)
|
36
|
+
FileUtils.cp_r(clone_path, @tmp_path)
|
37
|
+
tmp_path = File.join(@tmp_path, 'working')
|
38
|
+
Dir.chdir(tmp_path) do
|
39
|
+
FileUtils.mv('dot_git', '.git')
|
40
|
+
end
|
41
|
+
tmp_path
|
42
|
+
end
|
43
|
+
|
44
|
+
def in_temp_dir(remove_after = true) # :yields: the temporary dir's path
|
45
|
+
filename = 'git_test' + Time.now.to_i.to_s + rand(300).to_s.rjust(3, '0')
|
46
|
+
tmp_path = File.join("/tmp/", filename)
|
47
|
+
FileUtils.mkdir(tmp_path)
|
48
|
+
Dir.chdir tmp_path do
|
49
|
+
yield tmp_path
|
50
|
+
end
|
51
|
+
FileUtils.rm_r(tmp_path) if remove_after
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
def new_file(name, contents)
|
56
|
+
File.open(name, 'w') do |f|
|
57
|
+
f.puts contents
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def append_file(name, contents)
|
62
|
+
File.open(name, 'a') do |f|
|
63
|
+
f.puts contents
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-git-lacravate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- lacravate
|
9
|
+
autorequire: git
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-09 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description:
|
15
|
+
email: lacravate@lacravate.fr
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files:
|
19
|
+
- README
|
20
|
+
files:
|
21
|
+
- lib/git/author.rb
|
22
|
+
- lib/git/base.rb
|
23
|
+
- lib/git/branch.rb
|
24
|
+
- lib/git/branches.rb
|
25
|
+
- lib/git/diff.rb
|
26
|
+
- lib/git/index.rb
|
27
|
+
- lib/git/lib.rb
|
28
|
+
- lib/git/log.rb
|
29
|
+
- lib/git/object.rb
|
30
|
+
- lib/git/path.rb
|
31
|
+
- lib/git/remote.rb
|
32
|
+
- lib/git/repository.rb
|
33
|
+
- lib/git/stash.rb
|
34
|
+
- lib/git/stashes.rb
|
35
|
+
- lib/git/status.rb
|
36
|
+
- lib/git/working_directory.rb
|
37
|
+
- lib/git.rb
|
38
|
+
- README
|
39
|
+
- tests/all_tests.rb
|
40
|
+
- tests/test_helper.rb
|
41
|
+
homepage: ''
|
42
|
+
licenses: []
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 1.8.24
|
62
|
+
signing_key:
|
63
|
+
specification_version: 3
|
64
|
+
summary: ! 'a fork of: ''A package for using Git in Ruby code.''. Don''t use that,
|
65
|
+
i use this gem for other gems proper issuing'
|
66
|
+
test_files:
|
67
|
+
- tests/all_tests.rb
|
68
|
+
- tests/test_helper.rb
|