git-ce 1.5.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/CHANGELOG.md +94 -0
- data/CONTRIBUTING.md +135 -0
- data/LICENSE +21 -0
- data/MAINTAINERS.md +8 -0
- data/README.md +313 -0
- data/lib/git/author.rb +14 -0
- data/lib/git/base/factory.rb +75 -0
- data/lib/git/base.rb +555 -0
- data/lib/git/branch.rb +131 -0
- data/lib/git/branches.rb +71 -0
- data/lib/git/config.rb +22 -0
- data/lib/git/diff.rb +159 -0
- data/lib/git/index.rb +5 -0
- data/lib/git/lib.rb +1046 -0
- data/lib/git/log.rb +128 -0
- data/lib/git/object.rb +312 -0
- data/lib/git/path.rb +31 -0
- data/lib/git/remote.rb +36 -0
- data/lib/git/repository.rb +6 -0
- data/lib/git/stash.rb +27 -0
- data/lib/git/stashes.rb +55 -0
- data/lib/git/status.rb +199 -0
- data/lib/git/version.rb +5 -0
- data/lib/git/working_directory.rb +4 -0
- data/lib/git.rb +166 -0
- metadata +120 -0
data/lib/git/status.rb
ADDED
@@ -0,0 +1,199 @@
|
|
1
|
+
module Git
|
2
|
+
#
|
3
|
+
# A class for git status
|
4
|
+
#
|
5
|
+
class Status
|
6
|
+
include Enumerable
|
7
|
+
|
8
|
+
def initialize(base)
|
9
|
+
@base = base
|
10
|
+
construct_status
|
11
|
+
end
|
12
|
+
|
13
|
+
#
|
14
|
+
# Returns an Enumerable containing files that have changed from the
|
15
|
+
# git base directory
|
16
|
+
#
|
17
|
+
# @return [Enumerable]
|
18
|
+
def changed
|
19
|
+
@files.select { |_k, f| f.type == 'M' }
|
20
|
+
end
|
21
|
+
|
22
|
+
#
|
23
|
+
# Determines whether the given file has been changed.
|
24
|
+
# File path starts at git base directory
|
25
|
+
#
|
26
|
+
# @param file [String] The name of the file.
|
27
|
+
# @example Check if lib/git.rb has changed.
|
28
|
+
# changed?('lib/git.rb')
|
29
|
+
# @return [Boolean]
|
30
|
+
def changed?(file)
|
31
|
+
changed.member?(file)
|
32
|
+
end
|
33
|
+
|
34
|
+
#
|
35
|
+
# Returns an Enumerable containing files that have been added.
|
36
|
+
# File path starts at git base directory
|
37
|
+
#
|
38
|
+
# @return [Enumerable]
|
39
|
+
def added
|
40
|
+
@files.select { |_k, f| f.type == 'A' }
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# Determines whether the given file has been added to the repository
|
45
|
+
# File path starts at git base directory
|
46
|
+
#
|
47
|
+
# @param file [String] The name of the file.
|
48
|
+
# @example Check if lib/git.rb is added.
|
49
|
+
# added?('lib/git.rb')
|
50
|
+
# @return [Boolean]
|
51
|
+
def added?(file)
|
52
|
+
added.member?(file)
|
53
|
+
end
|
54
|
+
|
55
|
+
#
|
56
|
+
# Returns an Enumerable containing files that have been deleted.
|
57
|
+
# File path starts at git base directory
|
58
|
+
#
|
59
|
+
# @return [Enumerable]
|
60
|
+
def deleted
|
61
|
+
@files.select { |_k, f| f.type == 'D' }
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# Determines whether the given file has been deleted from the repository
|
66
|
+
# File path starts at git base directory
|
67
|
+
#
|
68
|
+
# @param file [String] The name of the file.
|
69
|
+
# @example Check if lib/git.rb is deleted.
|
70
|
+
# deleted?('lib/git.rb')
|
71
|
+
# @return [Boolean]
|
72
|
+
def deleted?(file)
|
73
|
+
deleted.member?(file)
|
74
|
+
end
|
75
|
+
|
76
|
+
#
|
77
|
+
# Returns an Enumerable containing files that are not tracked in git.
|
78
|
+
# File path starts at git base directory
|
79
|
+
#
|
80
|
+
# @return [Enumerable]
|
81
|
+
def untracked
|
82
|
+
@files.select { |_k, f| f.untracked }
|
83
|
+
end
|
84
|
+
|
85
|
+
#
|
86
|
+
# Determines whether the given file has is tracked by git.
|
87
|
+
# File path starts at git base directory
|
88
|
+
#
|
89
|
+
# @param file [String] The name of the file.
|
90
|
+
# @example Check if lib/git.rb is an untracked file.
|
91
|
+
# untracked?('lib/git.rb')
|
92
|
+
# @return [Boolean]
|
93
|
+
def untracked?(file)
|
94
|
+
untracked.member?(file)
|
95
|
+
end
|
96
|
+
|
97
|
+
def pretty
|
98
|
+
out = ''
|
99
|
+
each do |file|
|
100
|
+
out << pretty_file(file)
|
101
|
+
end
|
102
|
+
out << "\n"
|
103
|
+
out
|
104
|
+
end
|
105
|
+
|
106
|
+
def pretty_file(file)
|
107
|
+
<<-FILE.strip_heredoc
|
108
|
+
#{file.path}
|
109
|
+
\tsha(r) #{file.sha_repo} #{file.mode_repo}
|
110
|
+
\tsha(i) #{file.sha_index} #{file.mode_index}
|
111
|
+
\ttype #{file.type}
|
112
|
+
\tstage #{file.stage}
|
113
|
+
\tuntrac #{file.untracked}
|
114
|
+
FILE
|
115
|
+
end
|
116
|
+
|
117
|
+
# enumerable method
|
118
|
+
|
119
|
+
def [](file)
|
120
|
+
@files[file]
|
121
|
+
end
|
122
|
+
|
123
|
+
def each(&block)
|
124
|
+
@files.values.each(&block)
|
125
|
+
end
|
126
|
+
|
127
|
+
# subclass that does heavy lifting
|
128
|
+
class StatusFile
|
129
|
+
attr_accessor :path, :type, :stage, :untracked
|
130
|
+
attr_accessor :mode_index, :mode_repo
|
131
|
+
attr_accessor :sha_index, :sha_repo
|
132
|
+
|
133
|
+
def initialize(base, hash)
|
134
|
+
@base = base
|
135
|
+
@path = hash[:path]
|
136
|
+
@type = hash[:type]
|
137
|
+
@stage = hash[:stage]
|
138
|
+
@mode_index = hash[:mode_index]
|
139
|
+
@mode_repo = hash[:mode_repo]
|
140
|
+
@sha_index = hash[:sha_index]
|
141
|
+
@sha_repo = hash[:sha_repo]
|
142
|
+
@untracked = hash[:untracked]
|
143
|
+
end
|
144
|
+
|
145
|
+
def blob(type = :index)
|
146
|
+
if type == :repo
|
147
|
+
@base.object(@sha_repo)
|
148
|
+
else
|
149
|
+
begin
|
150
|
+
@base.object(@sha_index)
|
151
|
+
rescue
|
152
|
+
@base.object(@sha_repo)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
private
|
159
|
+
|
160
|
+
def construct_status
|
161
|
+
@files = @base.lib.ls_files
|
162
|
+
|
163
|
+
fetch_untracked
|
164
|
+
fetch_modified
|
165
|
+
fetch_added
|
166
|
+
|
167
|
+
@files.each do |k, file_hash|
|
168
|
+
@files[k] = StatusFile.new(@base, file_hash)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def fetch_untracked
|
173
|
+
ignore = @base.lib.ignored_files
|
174
|
+
|
175
|
+
Dir.chdir(@base.dir.path) do
|
176
|
+
Dir.glob('**/*', File::FNM_DOTMATCH) do |file|
|
177
|
+
next if @files[file] || File.directory?(file) ||
|
178
|
+
ignore.include?(file) || file =~ %r{^.git\/.+}
|
179
|
+
|
180
|
+
@files[file] = { path: file, untracked: true }
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def fetch_modified
|
186
|
+
# find modified in tree
|
187
|
+
@base.lib.diff_files.each do |path, data|
|
188
|
+
@files[path] ? @files[path].merge!(data) : @files[path] = data
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def fetch_added
|
193
|
+
# find added but not committed - new files
|
194
|
+
@base.lib.diff_index('HEAD').each do |path, data|
|
195
|
+
@files[path] ? @files[path].merge!(data) : @files[path] = data
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
data/lib/git/version.rb
ADDED
data/lib/git.rb
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
# Add the directory containing this file to the start of the load path if it
|
2
|
+
# isn't there already.
|
3
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
4
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
5
|
+
|
6
|
+
require 'git/author'
|
7
|
+
require 'git/base'
|
8
|
+
require 'git/branch'
|
9
|
+
require 'git/branches'
|
10
|
+
require 'git/config'
|
11
|
+
require 'git/diff'
|
12
|
+
require 'git/index'
|
13
|
+
require 'git/lib'
|
14
|
+
require 'git/log'
|
15
|
+
require 'git/object'
|
16
|
+
require 'git/path'
|
17
|
+
require 'git/remote'
|
18
|
+
require 'git/repository'
|
19
|
+
require 'git/status'
|
20
|
+
require 'git/stash'
|
21
|
+
require 'git/stashes'
|
22
|
+
require 'git/working_directory'
|
23
|
+
|
24
|
+
lib = Git::Lib.new(nil, nil)
|
25
|
+
unless lib.meets_required_version?
|
26
|
+
$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."
|
27
|
+
end
|
28
|
+
|
29
|
+
# Git/Ruby Library
|
30
|
+
#
|
31
|
+
# This provides bindings for working with git in complex
|
32
|
+
# interactions, including branching and merging, object
|
33
|
+
# inspection and manipulation, history, patch generation
|
34
|
+
# and more. You should be able to do most fundamental git
|
35
|
+
# operations with this library.
|
36
|
+
#
|
37
|
+
# This module provides the basic functions to open a git
|
38
|
+
# reference to work with. You can open a working directory,
|
39
|
+
# open a bare repository, initialize a new repo or clone an
|
40
|
+
# existing remote repository.
|
41
|
+
#
|
42
|
+
# Author:: Scott Chacon (mailto:schacon@gmail.com)
|
43
|
+
# License:: MIT License
|
44
|
+
module Git
|
45
|
+
|
46
|
+
#g.config('user.name', 'Scott Chacon') # sets value
|
47
|
+
#g.config('user.email', 'email@email.com') # sets value
|
48
|
+
#g.config('user.name') # returns 'Scott Chacon'
|
49
|
+
#g.config # returns whole config hash
|
50
|
+
def config(name = nil, value = nil)
|
51
|
+
lib = Git::Lib.new
|
52
|
+
if(name && value)
|
53
|
+
# set value
|
54
|
+
lib.config_set(name, value)
|
55
|
+
elsif (name)
|
56
|
+
# return value
|
57
|
+
lib.config_get(name)
|
58
|
+
else
|
59
|
+
# return hash
|
60
|
+
lib.config_list
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.configure
|
65
|
+
yield Base.config
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.config
|
69
|
+
return Base.config
|
70
|
+
end
|
71
|
+
|
72
|
+
def global_config(name = nil, value = nil)
|
73
|
+
self.class.global_config(name, value)
|
74
|
+
end
|
75
|
+
|
76
|
+
# open a bare repository
|
77
|
+
#
|
78
|
+
# this takes the path to a bare git repo
|
79
|
+
# it expects not to be able to use a working directory
|
80
|
+
# so you can't checkout stuff, commit things, etc.
|
81
|
+
# but you can do most read operations
|
82
|
+
def self.bare(git_dir, options = {})
|
83
|
+
Base.bare(git_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
|
+
# Same as g.config, but forces it to be at the global level
|
115
|
+
#
|
116
|
+
#g.config('user.name', 'Scott Chacon') # sets value
|
117
|
+
#g.config('user.email', 'email@email.com') # sets value
|
118
|
+
#g.config('user.name') # returns 'Scott Chacon'
|
119
|
+
#g.config # returns whole config hash
|
120
|
+
def self.global_config(name = nil, value = nil)
|
121
|
+
lib = Git::Lib.new(nil, nil)
|
122
|
+
if(name && value)
|
123
|
+
# set value
|
124
|
+
lib.global_config_set(name, value)
|
125
|
+
elsif (name)
|
126
|
+
# return value
|
127
|
+
lib.global_config_get(name)
|
128
|
+
else
|
129
|
+
# return hash
|
130
|
+
lib.global_config_list
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
# initialize a new git repository, defaults to the current working directory
|
135
|
+
#
|
136
|
+
# options
|
137
|
+
# :repository => '/path/to/alt_git_dir'
|
138
|
+
# :index => '/path/to/alt_index_file'
|
139
|
+
def self.init(working_dir = '.', options = {})
|
140
|
+
Base.init(working_dir, options)
|
141
|
+
end
|
142
|
+
|
143
|
+
# returns a Hash containing information about the references
|
144
|
+
# of the target repository
|
145
|
+
#
|
146
|
+
# @param [String|NilClass] location the target repository location or nil for '.'
|
147
|
+
# @return [{String=>Hash}] the available references of the target repo.
|
148
|
+
def self.ls_remote(location=nil)
|
149
|
+
Git::Lib.new.ls_remote(location)
|
150
|
+
end
|
151
|
+
|
152
|
+
# open an existing git working directory
|
153
|
+
#
|
154
|
+
# this will most likely be the most common way to create
|
155
|
+
# a git reference, referring to a working directory.
|
156
|
+
# if not provided in the options, the library will assume
|
157
|
+
# your git_dir and index are in the default place (.git/, .git/index)
|
158
|
+
#
|
159
|
+
# options
|
160
|
+
# :repository => '/path/to/alt_git_dir'
|
161
|
+
# :index => '/path/to/alt_index_file'
|
162
|
+
def self.open(working_dir, options = {})
|
163
|
+
Base.open(working_dir, options)
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: git-ce
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.5.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Scott Chacon and others
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-09-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rdoc
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: test-unit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2'
|
48
|
+
- - "<"
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '4'
|
51
|
+
type: :development
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '2'
|
58
|
+
- - "<"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '4'
|
61
|
+
description:
|
62
|
+
email: schacon@gmail.com
|
63
|
+
executables: []
|
64
|
+
extensions: []
|
65
|
+
extra_rdoc_files:
|
66
|
+
- README.md
|
67
|
+
files:
|
68
|
+
- CHANGELOG.md
|
69
|
+
- CONTRIBUTING.md
|
70
|
+
- LICENSE
|
71
|
+
- MAINTAINERS.md
|
72
|
+
- README.md
|
73
|
+
- lib/git.rb
|
74
|
+
- lib/git/author.rb
|
75
|
+
- lib/git/base.rb
|
76
|
+
- lib/git/base/factory.rb
|
77
|
+
- lib/git/branch.rb
|
78
|
+
- lib/git/branches.rb
|
79
|
+
- lib/git/config.rb
|
80
|
+
- lib/git/diff.rb
|
81
|
+
- lib/git/index.rb
|
82
|
+
- lib/git/lib.rb
|
83
|
+
- lib/git/log.rb
|
84
|
+
- lib/git/object.rb
|
85
|
+
- lib/git/path.rb
|
86
|
+
- lib/git/remote.rb
|
87
|
+
- lib/git/repository.rb
|
88
|
+
- lib/git/stash.rb
|
89
|
+
- lib/git/stashes.rb
|
90
|
+
- lib/git/status.rb
|
91
|
+
- lib/git/version.rb
|
92
|
+
- lib/git/working_directory.rb
|
93
|
+
homepage: http://github.com/zedtux/ruby-git-ce
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
metadata: {}
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options:
|
99
|
+
- "--charset=UTF-8"
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '1.9'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements:
|
113
|
+
- git 1.6.0.0, or greater
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 2.7.7
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: Ruby/Git is a Ruby library that can be used to create, read and manipulate
|
119
|
+
Git repositories by wrapping system calls to the git binary.
|
120
|
+
test_files: []
|