iownbey-git 1.0.7.1

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.
@@ -0,0 +1,4 @@
1
+ module Git
2
+ class Repository < Path
3
+ end
4
+ end
data/lib/git/stash.rb ADDED
@@ -0,0 +1,26 @@
1
+ module Git
2
+ class Stash
3
+ def initialize(base, message, existing=false)
4
+ @base = base
5
+ @message = message
6
+ save if existing == false
7
+ end
8
+
9
+ def save
10
+ @saved = @base.lib.stash_save(@message)
11
+ end
12
+
13
+ def saved?
14
+ @saved
15
+ end
16
+
17
+ def message
18
+ @message
19
+ end
20
+
21
+ def to_s
22
+ message
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,49 @@
1
+ module Git
2
+
3
+ # object that holds all the available stashes
4
+ class Stashes
5
+ include Enumerable
6
+
7
+ @base = nil
8
+ @stashes = nil
9
+
10
+ def initialize(base)
11
+ @stashes = []
12
+
13
+ @base = base
14
+
15
+ @base.lib.stashes_all.each do |id, message|
16
+ @stashes.unshift(Git::Stash.new(@base, message, true))
17
+ end
18
+ end
19
+
20
+ def save(message)
21
+ s = Git::Stash.new(@base, message)
22
+ @stashes.unshift(s) if s.saved?
23
+ end
24
+
25
+ def apply(index=0)
26
+ @base.lib.stash_apply(index.to_i)
27
+ end
28
+
29
+ def clear
30
+ @base.lib.stash_clear
31
+ @stashes = []
32
+ end
33
+
34
+ def size
35
+ @stashes.size
36
+ end
37
+
38
+ def each
39
+ @stashes.each do |s|
40
+ yield s
41
+ end
42
+ end
43
+
44
+ def [](index)
45
+ @stashes[index.to_i]
46
+ end
47
+
48
+ end
49
+ end
data/lib/git/status.rb ADDED
@@ -0,0 +1,118 @@
1
+ module Git
2
+
3
+ class Status
4
+ include Enumerable
5
+
6
+ @base = nil
7
+ @files = nil
8
+
9
+ def initialize(base)
10
+ @base = base
11
+ construct_status
12
+ end
13
+
14
+ def changed
15
+ @files.select { |k, f| f.type == 'M' }
16
+ end
17
+
18
+ def added
19
+ @files.select { |k, f| f.type == 'A' }
20
+ end
21
+
22
+ def deleted
23
+ @files.select { |k, f| f.type == 'D' }
24
+ end
25
+
26
+ def untracked
27
+ @files.select { |k, f| f.untracked }
28
+ end
29
+
30
+ def pretty
31
+ out = ''
32
+ self.each do |file|
33
+ out << file.path
34
+ out << "\n\tsha(r) " + file.sha_repo.to_s + ' ' + file.mode_repo.to_s
35
+ out << "\n\tsha(i) " + file.sha_index.to_s + ' ' + file.mode_index.to_s
36
+ out << "\n\ttype " + file.type.to_s
37
+ out << "\n\tstage " + file.stage.to_s
38
+ out << "\n\tuntrac " + file.untracked.to_s
39
+ out << "\n"
40
+ end
41
+ out << "\n"
42
+ out
43
+ end
44
+
45
+ # enumerable method
46
+
47
+ def [](file)
48
+ @files[file]
49
+ end
50
+
51
+ def each
52
+ @files.each do |k, file|
53
+ yield file
54
+ end
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
+ @base = nil
63
+
64
+ def initialize(base, hash)
65
+ @base = base
66
+ @path = hash[:path]
67
+ @type = hash[:type]
68
+ @stage = hash[:stage]
69
+ @mode_index = hash[:mode_index]
70
+ @mode_repo = hash[:mode_repo]
71
+ @sha_index = hash[:sha_index]
72
+ @sha_repo = hash[:sha_repo]
73
+ @untracked = hash[:untracked]
74
+ end
75
+
76
+ def blob(type = :index)
77
+ if type == :repo
78
+ @base.object(@sha_repo)
79
+ else
80
+ @base.object(@sha_index) rescue @base.object(@sha_repo)
81
+ end
82
+ end
83
+
84
+
85
+ end
86
+
87
+ private
88
+
89
+ def construct_status
90
+ @files = @base.lib.ls_files
91
+
92
+ # find untracked in working dir
93
+ Dir.chdir(@base.dir.path) do
94
+ Dir.glob('**/*') do |file|
95
+ if !@files[file]
96
+ @files[file] = {:path => file, :untracked => true} if !File.directory?(file)
97
+ end
98
+ end
99
+ end
100
+
101
+ # find modified in tree
102
+ @base.lib.diff_files.each do |path, data|
103
+ @files[path] ? @files[path].merge!(data) : @files[path] = data
104
+ end
105
+
106
+ # find added but not committed - new files
107
+ @base.lib.diff_index('HEAD').each do |path, data|
108
+ @files[path] ? @files[path].merge!(data) : @files[path] = data
109
+ end
110
+
111
+ @files.each do |k, file_hash|
112
+ @files[k] = StatusFile.new(@base, file_hash)
113
+ end
114
+ end
115
+
116
+ end
117
+
118
+ end
@@ -0,0 +1,4 @@
1
+ module Git
2
+ class WorkingDirectory < Git::Path
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ Dir.chdir(File.dirname(__FILE__)) do
2
+ Dir.glob('**/test_*.rb') { |test_case| require test_case }
3
+ #Dir.glob('**/test_index.rb') { |test_case| require test_case }
4
+ end
@@ -0,0 +1,77 @@
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
+
33
+ def with_temp_bare
34
+ in_temp_dir do |path|
35
+ g = Git.clone(@wbare, 'new')
36
+ Dir.chdir('new') do
37
+ yield g
38
+ end
39
+ end
40
+ end
41
+
42
+ def create_temp_repo(clone_path)
43
+ filename = 'git_test' + Time.now.to_i.to_s + rand(300).to_s.rjust(3, '0')
44
+ @tmp_path = File.join("/tmp/", filename)
45
+ FileUtils.mkdir_p(@tmp_path)
46
+ FileUtils.cp_r(clone_path, @tmp_path)
47
+ tmp_path = File.join(@tmp_path, 'working')
48
+ Dir.chdir(tmp_path) do
49
+ FileUtils.mv('dot_git', '.git')
50
+ end
51
+ tmp_path
52
+ end
53
+
54
+ def in_temp_dir(remove_after = true)
55
+ filename = 'git_test' + Time.now.to_i.to_s + rand(300).to_s.rjust(3, '0')
56
+ tmp_path = File.join("/tmp/", filename)
57
+ FileUtils.mkdir(tmp_path)
58
+ Dir.chdir tmp_path do
59
+ yield tmp_path
60
+ end
61
+ FileUtils.rm_r(tmp_path) if remove_after
62
+ end
63
+
64
+
65
+ def new_file(name, contents)
66
+ File.open(name, 'w') do |f|
67
+ f.puts contents
68
+ end
69
+ end
70
+
71
+ def append_file(name, contents)
72
+ File.open(name, 'a') do |f|
73
+ f.puts contents
74
+ end
75
+ end
76
+
77
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iownbey-git
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.7.1
5
+ platform: ruby
6
+ authors:
7
+ - Scott Chacon
8
+ autorequire: git
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-06-25 00:00:00 -07: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
+ - tests/all_tests.rb
72
+ - tests/test_helper.rb