gash 0.1.2 → 0.1.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.
- data/CHANGELOG +2 -0
- data/Rakefile +1 -0
- data/gash.gemspec +16 -3
- data/lib/gash.rb +47 -41
- metadata +15 -2
data/CHANGELOG
CHANGED
data/Rakefile
CHANGED
data/gash.gemspec
CHANGED
@@ -1,20 +1,33 @@
|
|
1
1
|
|
2
|
-
# Gem::Specification for Gash-0.1.
|
2
|
+
# Gem::Specification for Gash-0.1.3
|
3
3
|
# Originally generated by Echoe
|
4
4
|
|
5
5
|
--- !ruby/object:Gem::Specification
|
6
6
|
name: gash
|
7
7
|
version: !ruby/object:Gem::Version
|
8
|
-
version: 0.1.
|
8
|
+
version: 0.1.3
|
9
9
|
platform: ruby
|
10
10
|
authors:
|
11
11
|
- Magnus Holm
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
|
15
|
-
date: 2008-
|
15
|
+
date: 2008-10-02 00:00:00 +02:00
|
16
16
|
default_executable:
|
17
17
|
dependencies:
|
18
|
+
- !ruby/object:Gem::Dependency
|
19
|
+
name: open4
|
20
|
+
type: :runtime
|
21
|
+
version_requirement:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: "0"
|
27
|
+
- - "="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.9.6
|
30
|
+
version:
|
18
31
|
- !ruby/object:Gem::Dependency
|
19
32
|
name: echoe
|
20
33
|
type: :development
|
data/lib/gash.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'delegate'
|
2
|
+
require 'open4'
|
2
3
|
|
3
4
|
# == What is Gash?
|
4
5
|
#
|
@@ -7,7 +8,7 @@ require 'delegate'
|
|
7
8
|
# * Gash only cares about the data, not the commits.
|
8
9
|
# * Gash only cares about the _latest_ data.
|
9
10
|
# * Gash can commit.
|
10
|
-
# * Gash will automatically create branches if they don't
|
11
|
+
# * Gash will automatically create branches if they don't exist.
|
11
12
|
# * Gash only loads what it needs, so it handles large repos well.
|
12
13
|
# * Gash got {pretty good documentation}[http://dojo.rubyforge.org/gash].
|
13
14
|
# * Gash got {a bug tracker}[http://dojo.lighthouseapp.com/projects/17529-gash].
|
@@ -327,12 +328,10 @@ class Gash < SimpleDelegator
|
|
327
328
|
attr_accessor :branch, :repository
|
328
329
|
|
329
330
|
# Opens the +repo+ with the specified +branch+.
|
330
|
-
|
331
|
-
# <b>Please note:</b> The +repo+ must link to the actual repo,
|
332
|
-
# not the working directory!
|
333
|
-
def initialize(repo = ".git", branch = "master")
|
331
|
+
def initialize(repo = ".", branch = "master")
|
334
332
|
@branch = branch
|
335
|
-
@repository =
|
333
|
+
@repository = repo
|
334
|
+
@repository = find_repo(repo)
|
336
335
|
__setobj__(Tree.new(:parent => self))
|
337
336
|
update!
|
338
337
|
end
|
@@ -355,9 +354,6 @@ class Gash < SimpleDelegator
|
|
355
354
|
type = line[7]
|
356
355
|
sha1 = line[12, 40]
|
357
356
|
name = line[53..-1]
|
358
|
-
if name[0] == ?" && name[-1] == ?"
|
359
|
-
name = eval(name)
|
360
|
-
end
|
361
357
|
name = name[/[^\/]+$/]
|
362
358
|
parent = if $`.empty?
|
363
359
|
self
|
@@ -386,18 +382,24 @@ class Gash < SimpleDelegator
|
|
386
382
|
|
387
383
|
# Checks if the current branch exists
|
388
384
|
def branch_exists?
|
389
|
-
|
390
|
-
true
|
391
|
-
rescue Errors::Git
|
392
|
-
false
|
385
|
+
git_status('rev-parse', @branch) == 0
|
393
386
|
end
|
394
387
|
|
395
388
|
def inspect #:nodoc:
|
396
389
|
__getobj__.inspect
|
397
390
|
end
|
391
|
+
undef_method :dup
|
398
392
|
|
399
393
|
private
|
400
394
|
|
395
|
+
def find_repo(dir)
|
396
|
+
Dir.chdir(dir) do
|
397
|
+
File.expand_path(git('rev-parse', '--git-dir', :git_dir => false))
|
398
|
+
end
|
399
|
+
rescue Errno::ENOENT, Gash::Errors::Git
|
400
|
+
raise Errors::NoGitRepo.new("No Git repository at: " + @repository)
|
401
|
+
end
|
402
|
+
|
401
403
|
def cat_file(blob)
|
402
404
|
git('cat-file', 'blob', blob)
|
403
405
|
end
|
@@ -405,18 +407,17 @@ class Gash < SimpleDelegator
|
|
405
407
|
def to_tree!(from = self)
|
406
408
|
input = []
|
407
409
|
from.each do |key, value|
|
408
|
-
key = key.inspect
|
409
410
|
if value.tree?
|
410
411
|
value.sha1 ||= to_tree!(value)
|
411
412
|
value.mode ||= "040000"
|
412
|
-
input << "#{value.mode} tree #{value.sha1}\t#{key}\
|
413
|
+
input << "#{value.mode} tree #{value.sha1}\t#{key}\0"
|
413
414
|
else
|
414
415
|
value.sha1 ||= git('hash-object', '-w', '--stdin', :input => value.to_s)
|
415
416
|
value.mode ||= "100644"
|
416
|
-
input << "#{value.mode} blob #{value.sha1}\t#{key}\
|
417
|
+
input << "#{value.mode} blob #{value.sha1}\t#{key}\0"
|
417
418
|
end
|
418
419
|
end
|
419
|
-
git('mktree', :input => input)
|
420
|
+
git('mktree', '-z', :input => input)
|
420
421
|
end
|
421
422
|
|
422
423
|
def update_head(new_head)
|
@@ -435,13 +436,13 @@ class Gash < SimpleDelegator
|
|
435
436
|
end
|
436
437
|
|
437
438
|
def git_tree(&blk)
|
438
|
-
git('ls-tree', '-r', '-t', @branch
|
439
|
+
git('ls-tree', '-r', '-t', '-z', @branch).split("\0").each(&blk)
|
439
440
|
rescue Errors::Git
|
440
441
|
""
|
441
442
|
end
|
442
443
|
|
443
444
|
def git_tree_sha1(from = @branch)
|
444
|
-
git('rev-parse', @branch + '^{tree}'
|
445
|
+
git('rev-parse', @branch + '^{tree}')
|
445
446
|
rescue Errors::Git
|
446
447
|
end
|
447
448
|
|
@@ -469,14 +470,10 @@ class Gash < SimpleDelegator
|
|
469
470
|
# ==== Returns
|
470
471
|
# String:: if you didn't supply a block, the things git said on STDOUT, otherwise noting
|
471
472
|
def git(cmd, *rest, &block)
|
472
|
-
result, status = run_git(cmd, *rest, &block)
|
473
|
+
result, reserr, status = run_git(cmd, *rest, &block)
|
473
474
|
|
474
475
|
if status != 0
|
475
|
-
|
476
|
-
raise Errors::NoGitRepo.new("No Git repository at: " + @repository)
|
477
|
-
else
|
478
|
-
raise Errors::Git.new("Error: #{cmd} returned #{status}. Result: #{result}")
|
479
|
-
end
|
476
|
+
raise Errors::Git.new("Error: #{cmd} returned #{status}. STDERR: #{reserr}")
|
480
477
|
end
|
481
478
|
result
|
482
479
|
end
|
@@ -492,7 +489,7 @@ class Gash < SimpleDelegator
|
|
492
489
|
# ==== Returns
|
493
490
|
# Integer:: the return status of git
|
494
491
|
def git_status(cmd, *rest, &block)
|
495
|
-
run_git(cmd, *rest, &block)[
|
492
|
+
run_git(cmd, *rest, &block)[2]
|
496
493
|
end
|
497
494
|
|
498
495
|
# passes the command over to git (you should not call this directly)
|
@@ -504,44 +501,53 @@ class Gash < SimpleDelegator
|
|
504
501
|
#
|
505
502
|
# ==== Options
|
506
503
|
# :strip<Boolean>:: true to strip the output String#strip, false not to to it
|
504
|
+
# :git_dir<Boolean>:: true to automatically use @repository as git-dir, false to not use anything.
|
507
505
|
#
|
508
506
|
# ==== Raises
|
509
507
|
# Errors::Git:: if git returns non-null, an Exception is raised
|
510
508
|
#
|
511
509
|
# ==== Returns
|
512
|
-
# Array[String, Integer]:: the first item is the STDOUT of git, the second is the return-status
|
510
|
+
# Array[String, String, Integer]:: the first item is the STDOUT of git, the second is the STDERR, the third is the return-status
|
513
511
|
def run_git(cmd, *args, &block)
|
514
512
|
options = if args.last.kind_of?(Hash)
|
515
513
|
args.pop
|
516
514
|
else
|
517
515
|
{}
|
518
516
|
end
|
519
|
-
|
520
517
|
options[:strip] = true unless options.key?(:strip)
|
518
|
+
|
519
|
+
git_cmd = ["git"]
|
520
|
+
|
521
|
+
unless options[:git_dir] == false
|
522
|
+
git_cmd.push("--git-dir", @repository)
|
523
|
+
end
|
521
524
|
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
+
git_cmd.push(cmd, *args)
|
526
|
+
|
525
527
|
result = ""
|
526
|
-
|
528
|
+
reserr = ""
|
529
|
+
status = Open4.popen4(*git_cmd) do |pid, stdin, stdout, stderr|
|
527
530
|
if input = options.delete(:input)
|
528
|
-
|
529
|
-
f.close_write
|
531
|
+
stdin.write(input)
|
530
532
|
elsif block_given?
|
531
|
-
yield
|
532
|
-
f.close_write
|
533
|
+
yield stdin
|
533
534
|
end
|
535
|
+
stdin.close_write
|
534
536
|
|
535
537
|
result = ""
|
538
|
+
reserr = ""
|
536
539
|
|
537
|
-
while !
|
538
|
-
result <<
|
540
|
+
while !stdout.eof
|
541
|
+
result << stdout.read
|
542
|
+
end
|
543
|
+
|
544
|
+
while !stderr.eof
|
545
|
+
reserr << stderr.read
|
539
546
|
end
|
540
547
|
end
|
541
|
-
status = $?
|
542
548
|
|
543
549
|
result.strip! if options[:strip] == true
|
544
|
-
|
545
|
-
[result, status]
|
550
|
+
|
551
|
+
[result, reserr, status]
|
546
552
|
end
|
547
553
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Magnus Holm
|
@@ -9,9 +9,22 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-10-02 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: open4
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
- - "="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.9.6
|
27
|
+
version:
|
15
28
|
- !ruby/object:Gem::Dependency
|
16
29
|
name: echoe
|
17
30
|
type: :development
|