ruby-git-yz 1.3.3
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 +84 -0
- data/LICENSE +21 -0
- data/README.md +297 -0
- data/VERSION +2 -0
- data/lib/git/author.rb +14 -0
- data/lib/git/base.rb +540 -0
- data/lib/git/base/factory.rb +75 -0
- data/lib/git/branch.rb +122 -0
- data/lib/git/branches.rb +71 -0
- data/lib/git/config.rb +22 -0
- data/lib/git/diff.rb +158 -0
- data/lib/git/index.rb +5 -0
- data/lib/git/lib.rb +1018 -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 +44 -0
- data/lib/git/status.rb +117 -0
- data/lib/git/version.rb +7 -0
- data/lib/git/working_directory.rb +4 -0
- data/lib/ruby-git-yz.rb +166 -0
- metadata +120 -0
data/lib/git/remote.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module Git
|
2
|
+
class Remote < Path
|
3
|
+
|
4
|
+
attr_accessor :name, :url, :fetch_opts
|
5
|
+
|
6
|
+
def initialize(base, name)
|
7
|
+
@base = base
|
8
|
+
config = @base.lib.config_remote(name)
|
9
|
+
@name = name
|
10
|
+
@url = config['url']
|
11
|
+
@fetch_opts = config['fetch']
|
12
|
+
end
|
13
|
+
|
14
|
+
def fetch(opts={})
|
15
|
+
@base.fetch(@name, opts)
|
16
|
+
end
|
17
|
+
|
18
|
+
# merge this remote locally
|
19
|
+
def merge(branch = 'master')
|
20
|
+
@base.merge("#{@name}/#{branch}")
|
21
|
+
end
|
22
|
+
|
23
|
+
def branch(branch = 'master')
|
24
|
+
Git::Branch.new(@base, "#{@name}/#{branch}")
|
25
|
+
end
|
26
|
+
|
27
|
+
def remove
|
28
|
+
@base.lib.remote_remove(@name)
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_s
|
32
|
+
@name
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
data/lib/git/stash.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Git
|
2
|
+
class Stash
|
3
|
+
|
4
|
+
def initialize(base, message, existing=false)
|
5
|
+
@base = base
|
6
|
+
@message = message
|
7
|
+
save unless existing
|
8
|
+
end
|
9
|
+
|
10
|
+
def save
|
11
|
+
@saved = @base.lib.stash_save(@message)
|
12
|
+
end
|
13
|
+
|
14
|
+
def saved?
|
15
|
+
@saved
|
16
|
+
end
|
17
|
+
|
18
|
+
def message
|
19
|
+
@message
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_s
|
23
|
+
message
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
data/lib/git/stashes.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
module Git
|
2
|
+
|
3
|
+
# object that holds all the available stashes
|
4
|
+
class Stashes
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
def initialize(base)
|
8
|
+
@stashes = []
|
9
|
+
|
10
|
+
@base = base
|
11
|
+
|
12
|
+
@base.lib.stashes_all.each do |id, message|
|
13
|
+
@stashes.unshift(Git::Stash.new(@base, message, true))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def save(message)
|
18
|
+
s = Git::Stash.new(@base, message)
|
19
|
+
@stashes.unshift(s) if s.saved?
|
20
|
+
end
|
21
|
+
|
22
|
+
def apply(index=nil)
|
23
|
+
@base.lib.stash_apply(index)
|
24
|
+
end
|
25
|
+
|
26
|
+
def clear
|
27
|
+
@base.lib.stash_clear
|
28
|
+
@stashes = []
|
29
|
+
end
|
30
|
+
|
31
|
+
def size
|
32
|
+
@stashes.size
|
33
|
+
end
|
34
|
+
|
35
|
+
def each(&block)
|
36
|
+
@stashes.each(&block)
|
37
|
+
end
|
38
|
+
|
39
|
+
def [](index)
|
40
|
+
@stashes[index.to_i]
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
data/lib/git/status.rb
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
module Git
|
2
|
+
|
3
|
+
class Status
|
4
|
+
include Enumerable
|
5
|
+
|
6
|
+
def initialize(base)
|
7
|
+
@base = base
|
8
|
+
construct_status
|
9
|
+
end
|
10
|
+
|
11
|
+
def changed
|
12
|
+
@files.select { |k, f| f.type == 'M' }
|
13
|
+
end
|
14
|
+
|
15
|
+
def added
|
16
|
+
@files.select { |k, f| f.type == 'A' }
|
17
|
+
end
|
18
|
+
|
19
|
+
def deleted
|
20
|
+
@files.select { |k, f| f.type == 'D' }
|
21
|
+
end
|
22
|
+
|
23
|
+
def untracked
|
24
|
+
@files.select { |k, f| f.untracked }
|
25
|
+
end
|
26
|
+
|
27
|
+
def pretty
|
28
|
+
out = ''
|
29
|
+
self.each do |file|
|
30
|
+
out << pretty_file(file)
|
31
|
+
end
|
32
|
+
out << "\n"
|
33
|
+
out
|
34
|
+
end
|
35
|
+
|
36
|
+
def pretty_file(file)
|
37
|
+
<<FILE
|
38
|
+
#{file.path}
|
39
|
+
\tsha(r) #{file.sha_repo.to_s} #{file.mode_repo.to_s}
|
40
|
+
\tsha(i) #{file.sha_index.to_s} #{file.mode_index.to_s}
|
41
|
+
\ttype #{file.type.to_s}
|
42
|
+
\tstage #{file.stage.to_s}
|
43
|
+
\tuntrac #{file.untracked.to_s}
|
44
|
+
FILE
|
45
|
+
end
|
46
|
+
|
47
|
+
# enumerable method
|
48
|
+
|
49
|
+
def [](file)
|
50
|
+
@files[file]
|
51
|
+
end
|
52
|
+
|
53
|
+
def each(&block)
|
54
|
+
@files.values.each(&block)
|
55
|
+
end
|
56
|
+
|
57
|
+
class StatusFile
|
58
|
+
attr_accessor :path, :type, :stage, :untracked
|
59
|
+
attr_accessor :mode_index, :mode_repo
|
60
|
+
attr_accessor :sha_index, :sha_repo
|
61
|
+
|
62
|
+
def initialize(base, hash)
|
63
|
+
@base = base
|
64
|
+
@path = hash[:path]
|
65
|
+
@type = hash[:type]
|
66
|
+
@stage = hash[:stage]
|
67
|
+
@mode_index = hash[:mode_index]
|
68
|
+
@mode_repo = hash[:mode_repo]
|
69
|
+
@sha_index = hash[:sha_index]
|
70
|
+
@sha_repo = hash[:sha_repo]
|
71
|
+
@untracked = hash[:untracked]
|
72
|
+
end
|
73
|
+
|
74
|
+
def blob(type = :index)
|
75
|
+
if type == :repo
|
76
|
+
@base.object(@sha_repo)
|
77
|
+
else
|
78
|
+
@base.object(@sha_index) rescue @base.object(@sha_repo)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def construct_status
|
88
|
+
@files = @base.lib.ls_files
|
89
|
+
ignore = @base.lib.ignored_files
|
90
|
+
|
91
|
+
# find untracked in working dir
|
92
|
+
Dir.chdir(@base.dir.path) do
|
93
|
+
Dir.glob('**/*', File::FNM_DOTMATCH) do |file|
|
94
|
+
next if @files[file] || File.directory?(file) || ignore.include?(file) || file =~ /^.git\/.+/
|
95
|
+
|
96
|
+
@files[file] = {:path => file, :untracked => true}
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# find modified in tree
|
101
|
+
@base.lib.diff_files.each do |path, data|
|
102
|
+
@files[path] ? @files[path].merge!(data) : @files[path] = data
|
103
|
+
end
|
104
|
+
|
105
|
+
# find added but not committed - new files
|
106
|
+
@base.lib.diff_index('HEAD').each do |path, data|
|
107
|
+
@files[path] ? @files[path].merge!(data) : @files[path] = data
|
108
|
+
end
|
109
|
+
|
110
|
+
@files.each do |k, file_hash|
|
111
|
+
@files[k] = StatusFile.new(@base, file_hash)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
data/lib/git/version.rb
ADDED
data/lib/ruby-git-yz.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: ruby-git-yz
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.3.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Scott Chacon
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-07-31 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
|
69
|
+
- LICENSE
|
70
|
+
- README.md
|
71
|
+
- VERSION
|
72
|
+
- lib/git/author.rb
|
73
|
+
- lib/git/base.rb
|
74
|
+
- lib/git/base/factory.rb
|
75
|
+
- lib/git/branch.rb
|
76
|
+
- lib/git/branches.rb
|
77
|
+
- lib/git/config.rb
|
78
|
+
- lib/git/diff.rb
|
79
|
+
- lib/git/index.rb
|
80
|
+
- lib/git/lib.rb
|
81
|
+
- lib/git/log.rb
|
82
|
+
- lib/git/object.rb
|
83
|
+
- lib/git/path.rb
|
84
|
+
- lib/git/remote.rb
|
85
|
+
- lib/git/repository.rb
|
86
|
+
- lib/git/stash.rb
|
87
|
+
- lib/git/stashes.rb
|
88
|
+
- lib/git/status.rb
|
89
|
+
- lib/git/version.rb
|
90
|
+
- lib/git/working_directory.rb
|
91
|
+
- lib/ruby-git-yz.rb
|
92
|
+
homepage: http://github.com/schacon/ruby-git
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options:
|
98
|
+
- "--charset=UTF-8"
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '1.9'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements:
|
112
|
+
- git 1.6.0.0, or greater
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 2.6.12
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: Ruby/Git is a Ruby library that can be used to create, read and manipulate
|
118
|
+
Git repositories by wrapping system calls to the git binary.
|
119
|
+
test_files: []
|
120
|
+
has_rdoc:
|