p-mongo-git 1.8.1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,6 @@
1
+ module Git
2
+
3
+ class Repository < Path
4
+ end
5
+
6
+ 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
@@ -0,0 +1,55 @@
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
+ #
18
+ # Returns an multi-dimensional Array of elements that have been stash saved.
19
+ # Array is based on position and name. See Example
20
+ #
21
+ # @example Returns Array of items that have been stashed
22
+ # .all - [0, "testing-stash-all"]]
23
+ # @return [Array]
24
+ def all
25
+ @base.lib.stashes_all
26
+ end
27
+
28
+ def save(message)
29
+ s = Git::Stash.new(@base, message)
30
+ @stashes.unshift(s) if s.saved?
31
+ end
32
+
33
+ def apply(index=nil)
34
+ @base.lib.stash_apply(index)
35
+ end
36
+
37
+ def clear
38
+ @base.lib.stash_clear
39
+ @stashes = []
40
+ end
41
+
42
+ def size
43
+ @stashes.size
44
+ end
45
+
46
+ def each(&block)
47
+ @stashes.each(&block)
48
+ end
49
+
50
+ def [](index)
51
+ @stashes[index.to_i]
52
+ end
53
+
54
+ end
55
+ end
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
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
@@ -0,0 +1,5 @@
1
+ module Git
2
+ # The current gem version
3
+ # @return [String] the current gem version.
4
+ VERSION='1.8.1'
5
+ end
@@ -0,0 +1,4 @@
1
+ module Git
2
+ class WorkingDirectory < Git::Path
3
+ end
4
+ end
@@ -0,0 +1,38 @@
1
+ require 'git/path'
2
+
3
+ module Git
4
+
5
+ class Worktree < Path
6
+
7
+ attr_accessor :full, :dir, :gcommit
8
+
9
+ def initialize(base, dir, gcommit = nil)
10
+ @full = dir
11
+ @full += ' ' + gcommit if !gcommit.nil?
12
+ @base = base
13
+ @dir = dir
14
+ @gcommit = gcommit
15
+ end
16
+
17
+ def gcommit
18
+ @gcommit ||= @base.gcommit(@full)
19
+ @gcommit
20
+ end
21
+
22
+ def add
23
+ @base.lib.worktree_add(@dir, @gcommit)
24
+ end
25
+
26
+ def remove
27
+ @base.lib.worktree_remove(@dir)
28
+ end
29
+
30
+ def to_a
31
+ [@full]
32
+ end
33
+
34
+ def to_s
35
+ @full
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,47 @@
1
+ module Git
2
+ # object that holds all the available worktrees
3
+ class Worktrees
4
+
5
+ include Enumerable
6
+
7
+ def initialize(base)
8
+ @worktrees = {}
9
+
10
+ @base = base
11
+
12
+ # Array contains [dir, git_hash]
13
+ @base.lib.worktrees_all.each do |w|
14
+ @worktrees[w[0]] = Git::Worktree.new(@base, w[0], w[1])
15
+ end
16
+ end
17
+
18
+ # array like methods
19
+
20
+ def size
21
+ @worktrees.size
22
+ end
23
+
24
+ def each(&block)
25
+ @worktrees.values.each(&block)
26
+ end
27
+
28
+ def [](worktree_name)
29
+ @worktrees.values.inject(@worktrees) do |worktrees, worktree|
30
+ worktrees[worktree.full] ||= worktree
31
+ worktrees
32
+ end[worktree_name.to_s]
33
+ end
34
+
35
+ def to_s
36
+ out = ''
37
+ @worktrees.each do |k, b|
38
+ out << b.to_s << "\n"
39
+ end
40
+ out
41
+ end
42
+
43
+ def prune
44
+ @base.lib.worktree_prune
45
+ end
46
+ end
47
+ end
metadata ADDED
@@ -0,0 +1,186 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: p-mongo-git
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.8.1
5
+ platform: ruby
6
+ authors:
7
+ - Scott Chacon and others
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-06-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rchardet
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitar
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '13.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: redcarpet
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.5'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.9'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.9'
97
+ - !ruby/object:Gem::Dependency
98
+ name: yardstick
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.9'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.9'
111
+ description: |
112
+ The Git Gem provides an API that can be used to create, read, and manipulate
113
+ Git repositories by wrapping system calls to the `git` binary. The API can be
114
+ used for working with Git in complex interactions including branching and
115
+ merging, object inspection and manipulation, history, patch generation and
116
+ more.
117
+ email: schacon@gmail.com
118
+ executables: []
119
+ extensions: []
120
+ extra_rdoc_files: []
121
+ files:
122
+ - ".github/stale.yml"
123
+ - ".github/workflows/continuous_integration.yml"
124
+ - ".gitignore"
125
+ - ".yardopts"
126
+ - CHANGELOG.md
127
+ - CONTRIBUTING.md
128
+ - Gemfile
129
+ - ISSUE_TEMPLATE.md
130
+ - LICENSE
131
+ - MAINTAINERS.md
132
+ - PULL_REQUEST_TEMPLATE.md
133
+ - README.md
134
+ - RELEASING.md
135
+ - Rakefile
136
+ - git.gemspec
137
+ - lib/git.rb
138
+ - lib/git/author.rb
139
+ - lib/git/base.rb
140
+ - lib/git/base/factory.rb
141
+ - lib/git/branch.rb
142
+ - lib/git/branches.rb
143
+ - lib/git/config.rb
144
+ - lib/git/diff.rb
145
+ - lib/git/index.rb
146
+ - lib/git/lib.rb
147
+ - lib/git/log.rb
148
+ - lib/git/object.rb
149
+ - lib/git/path.rb
150
+ - lib/git/remote.rb
151
+ - lib/git/repository.rb
152
+ - lib/git/stash.rb
153
+ - lib/git/stashes.rb
154
+ - lib/git/status.rb
155
+ - lib/git/version.rb
156
+ - lib/git/working_directory.rb
157
+ - lib/git/worktree.rb
158
+ - lib/git/worktrees.rb
159
+ homepage: http://github.com/ruby-git/ruby-git
160
+ licenses:
161
+ - MIT
162
+ metadata:
163
+ homepage_uri: http://github.com/ruby-git/ruby-git
164
+ source_code_uri: http://github.com/ruby-git/ruby-git
165
+ changelog_uri: http://rubydoc.info/gems/git/file.CHANGELOG.html
166
+ post_install_message:
167
+ rdoc_options: []
168
+ require_paths:
169
+ - lib
170
+ required_ruby_version: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '2.3'
175
+ required_rubygems_version: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ requirements:
181
+ - git 1.6.0.0, or greater
182
+ rubygems_version: 3.1.6
183
+ signing_key:
184
+ specification_version: 4
185
+ summary: An API to create, read, and manipulate Git repositories
186
+ test_files: []