peterwald-git 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ module Git
2
+ class Repository < Path
3
+ end
4
+ 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,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,109 @@
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 << file.path
31
+ out << "\n\tsha(r) " + file.sha_repo.to_s + ' ' + file.mode_repo.to_s
32
+ out << "\n\tsha(i) " + file.sha_index.to_s + ' ' + file.mode_index.to_s
33
+ out << "\n\ttype " + file.type.to_s
34
+ out << "\n\tstage " + file.stage.to_s
35
+ out << "\n\tuntrac " + file.untracked.to_s
36
+ out << "\n"
37
+ end
38
+ out << "\n"
39
+ out
40
+ end
41
+
42
+ # enumerable method
43
+
44
+ def [](file)
45
+ @files[file]
46
+ end
47
+
48
+ def each(&block)
49
+ @files.values.each(&block)
50
+ end
51
+
52
+ class StatusFile
53
+ attr_accessor :path, :type, :stage, :untracked
54
+ attr_accessor :mode_index, :mode_repo
55
+ attr_accessor :sha_index, :sha_repo
56
+
57
+ def initialize(base, hash)
58
+ @base = base
59
+ @path = hash[:path]
60
+ @type = hash[:type]
61
+ @stage = hash[:stage]
62
+ @mode_index = hash[:mode_index]
63
+ @mode_repo = hash[:mode_repo]
64
+ @sha_index = hash[:sha_index]
65
+ @sha_repo = hash[:sha_repo]
66
+ @untracked = hash[:untracked]
67
+ end
68
+
69
+ def blob(type = :index)
70
+ if type == :repo
71
+ @base.object(@sha_repo)
72
+ else
73
+ @base.object(@sha_index) rescue @base.object(@sha_repo)
74
+ end
75
+ end
76
+
77
+
78
+ end
79
+
80
+ private
81
+
82
+ def construct_status
83
+ @files = @base.lib.ls_files
84
+
85
+ # find untracked in working dir
86
+ Dir.chdir(@base.dir.path) do
87
+ Dir.glob('**/*') do |file|
88
+ @files[file] = {:path => file, :untracked => true} unless @files[file] || File.directory?(file)
89
+ end
90
+ end
91
+
92
+ # find modified in tree
93
+ @base.lib.diff_files.each do |path, data|
94
+ @files[path] ? @files[path].merge!(data) : @files[path] = data
95
+ end
96
+
97
+ # find added but not committed - new files
98
+ @base.lib.diff_index('HEAD').each do |path, data|
99
+ @files[path] ? @files[path].merge!(data) : @files[path] = data
100
+ end
101
+
102
+ @files.each do |k, file_hash|
103
+ @files[k] = StatusFile.new(@base, file_hash)
104
+ end
105
+ end
106
+
107
+ end
108
+
109
+ end
@@ -0,0 +1,4 @@
1
+ module Git
2
+ class WorkingDirectory < Git::Path
3
+ end
4
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: peterwald-git
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Scott Chacon
8
+ autorequire: git
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-13 00:00:00 -08: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.2.0
67
+ signing_key:
68
+ specification_version: 2
69
+ summary: A package for using Git in Ruby code.
70
+ test_files: []
71
+