ed 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +20 -0
- data/README.md +2 -5
- data/lib/ed.rb +53 -14
- data/lib/ed/config.rb +75 -0
- data/lib/ed/env.rb +40 -0
- data/lib/ed/repository.rb +14 -7
- data/lib/ed/version.rb +1 -1
- metadata +12 -14
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (C) 2011 by Robert Gleeson
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
20
|
+
|
data/README.md
CHANGED
data/lib/ed.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'observe'
|
2
2
|
require 'ed/version'
|
3
|
+
require 'ed/env'
|
4
|
+
require 'ed/config'
|
3
5
|
require 'ed/repository'
|
4
6
|
require 'ed/context'
|
5
7
|
require 'ed/core_ext/object'
|
@@ -8,6 +10,25 @@ class Ed
|
|
8
10
|
|
9
11
|
include Observe
|
10
12
|
|
13
|
+
class << self
|
14
|
+
|
15
|
+
#
|
16
|
+
# @example
|
17
|
+
# Ed.configure do |config|
|
18
|
+
# config.fork = true
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# @yieldparam config
|
22
|
+
# (see Ed::Config.change)
|
23
|
+
#
|
24
|
+
# @return [void]
|
25
|
+
#
|
26
|
+
def configure &block
|
27
|
+
Ed::Config.change(&block)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
11
32
|
#
|
12
33
|
# @param [String] path
|
13
34
|
# The path to a git repository.
|
@@ -21,7 +42,7 @@ class Ed
|
|
21
42
|
@repo = Ed::Repository.new(path)
|
22
43
|
|
23
44
|
if block_given?
|
24
|
-
yield
|
45
|
+
yield self
|
25
46
|
end
|
26
47
|
end
|
27
48
|
|
@@ -29,6 +50,9 @@ class Ed
|
|
29
50
|
# @param [Proc] block
|
30
51
|
# A block executed before {#commit}, {#branch}, or {#tag} is called.
|
31
52
|
#
|
53
|
+
# @yieldparam [String] path
|
54
|
+
# The path to the repository on local disk.
|
55
|
+
#
|
32
56
|
# @return [void]
|
33
57
|
#
|
34
58
|
def before &block
|
@@ -37,29 +61,44 @@ class Ed
|
|
37
61
|
|
38
62
|
#
|
39
63
|
# @param [String] commit
|
40
|
-
#
|
64
|
+
# A string you can pass to 'git checkout'.
|
41
65
|
#
|
42
66
|
# @param [Proc] block
|
43
67
|
# A block executed while the repository has switched to 'commit'.
|
44
68
|
#
|
69
|
+
# @yieldparam [String] path
|
70
|
+
# The path to the repository on local disk.
|
71
|
+
#
|
72
|
+
# @return [void]
|
73
|
+
#
|
45
74
|
def commit commit, &block
|
46
|
-
|
75
|
+
if Ed::Config.fork?
|
76
|
+
pid = fork {
|
77
|
+
switch(commit, &block)
|
78
|
+
}
|
79
|
+
|
80
|
+
Process.wait(pid)
|
81
|
+
else
|
82
|
+
switch(commit, &block)
|
83
|
+
end
|
47
84
|
end
|
48
85
|
alias_method :tag , :commit
|
49
86
|
alias_method :branch, :commit
|
50
|
-
|
51
|
-
|
87
|
+
|
88
|
+
#
|
89
|
+
# Switches to 'commit', and runs &block.
|
90
|
+
#
|
91
|
+
# @param commit
|
92
|
+
# (see Ed#commit)
|
93
|
+
#
|
94
|
+
# @param block
|
95
|
+
# (see Ed#commit)
|
96
|
+
#
|
52
97
|
def switch(commit, &block)
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
block.call(@repo.path)
|
57
|
-
end
|
58
|
-
|
59
|
-
Process.wait(pid)
|
98
|
+
@repo.checkout '-q', commit
|
99
|
+
notify_observers(:before_filter, @repo.path)
|
100
|
+
block.call(@repo.path)
|
60
101
|
end
|
61
102
|
private :switch
|
62
103
|
|
63
104
|
end
|
64
|
-
|
65
|
-
|
data/lib/ed/config.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
module Ed::Config
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
#
|
8
|
+
# @yieldparam [Ed::Config] config
|
9
|
+
# Yields {Ed::Config}.
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
#
|
13
|
+
# Ed::Config.change do |config|
|
14
|
+
# config.fork = false
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
def change
|
18
|
+
yield self
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
# @param [String, #to_s] path
|
23
|
+
# The path to use when storing cloned repositories.
|
24
|
+
#
|
25
|
+
# @return [Pathname]
|
26
|
+
#
|
27
|
+
def repo_dir= path
|
28
|
+
@repo_dir = Pathname.new path.to_s
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# @return [Pathname]
|
33
|
+
# The path being used to store cloned repositories.
|
34
|
+
#
|
35
|
+
def repo_dir
|
36
|
+
@repo_dir
|
37
|
+
end
|
38
|
+
|
39
|
+
#
|
40
|
+
# @param [Boolean] value
|
41
|
+
# Enable or disable the creation of a subprocess before checking out a commit.
|
42
|
+
#
|
43
|
+
# @return [Boolean]
|
44
|
+
#
|
45
|
+
def fork= value
|
46
|
+
if value && Ed::Env.fork_unavailable?
|
47
|
+
raise ArgumentError, 'Kernel#fork is not available on your platform.'
|
48
|
+
end
|
49
|
+
|
50
|
+
@fork = value
|
51
|
+
end
|
52
|
+
|
53
|
+
#
|
54
|
+
# @return [Boolean]
|
55
|
+
# Returns true if a subprocess is created before checking out a commit.
|
56
|
+
#
|
57
|
+
def fork
|
58
|
+
@fork
|
59
|
+
end
|
60
|
+
alias_method :fork?, :fork
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
change do |config|
|
65
|
+
config.fork = false
|
66
|
+
|
67
|
+
if Ed::Env.windows?
|
68
|
+
config.repo_dir = ::ENV["TEMP"]
|
69
|
+
else
|
70
|
+
config.repo_dir = ::ENV["TMPDIR"] || "/tmp"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
data/lib/ed/env.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module Ed::Env
|
2
|
+
|
3
|
+
class << self
|
4
|
+
#
|
5
|
+
# @return [Boolean]
|
6
|
+
# Are we on Windows?
|
7
|
+
#
|
8
|
+
def windows?
|
9
|
+
RUBY_PLATFORM['mswin32'] ||
|
10
|
+
RUBY_PLATFORM['mingw'] ||
|
11
|
+
RUBY_PLATFORM['cygwin']
|
12
|
+
end
|
13
|
+
|
14
|
+
#
|
15
|
+
# @return [Boolean]
|
16
|
+
# Are we on JRuby?
|
17
|
+
#
|
18
|
+
def jruby?
|
19
|
+
RUBY_PLATFORM == 'java'
|
20
|
+
end
|
21
|
+
|
22
|
+
#
|
23
|
+
# @return [Boolean]
|
24
|
+
# Are we on MacRuby?
|
25
|
+
#
|
26
|
+
def macruby?
|
27
|
+
defined?(RUBY_ENGINE) && RUBY_ENGINE == 'macruby'
|
28
|
+
end
|
29
|
+
|
30
|
+
#
|
31
|
+
# @return [Boolean]
|
32
|
+
# Returns true if Kernel#fork is unavailable.
|
33
|
+
#
|
34
|
+
def fork_unavailable?
|
35
|
+
macruby? || jruby? || windows?
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
data/lib/ed/repository.rb
CHANGED
@@ -30,6 +30,14 @@ class Ed::Repository
|
|
30
30
|
@path = path.to_s
|
31
31
|
@copy = false
|
32
32
|
end
|
33
|
+
|
34
|
+
parent = Process.pid
|
35
|
+
|
36
|
+
ObjectSpace.define_finalizer(self) do
|
37
|
+
if parent == Process.pid
|
38
|
+
FileUtils.rm_rf(@path)
|
39
|
+
end
|
40
|
+
end
|
33
41
|
end
|
34
42
|
|
35
43
|
#
|
@@ -38,26 +46,25 @@ class Ed::Repository
|
|
38
46
|
#
|
39
47
|
# @return [void]
|
40
48
|
#
|
41
|
-
def checkout *
|
42
|
-
git "checkout", *
|
49
|
+
def checkout *args
|
50
|
+
git "checkout", *args
|
43
51
|
end
|
44
52
|
|
45
53
|
#
|
46
54
|
# @param [String] from
|
47
55
|
# The path to copy from.
|
48
56
|
#
|
49
|
-
# @param [String] to
|
50
|
-
# The path to copy to.
|
51
|
-
#
|
52
57
|
# @return [String]
|
53
58
|
# The path to the copied repository.
|
54
59
|
#
|
55
|
-
def copy! from
|
60
|
+
def copy! from
|
61
|
+
to = File.join(Ed::Config.repo_dir, "ed/#{Process.pid}/#{object_id}")
|
62
|
+
|
56
63
|
unless File.exists? to
|
57
64
|
FileUtils.mkdir_p(to)
|
58
65
|
system 'git', 'clone', '-q', from, to
|
59
66
|
end
|
60
|
-
|
67
|
+
|
61
68
|
to
|
62
69
|
end
|
63
70
|
private :copy!
|
data/lib/ed/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-01-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: observe
|
16
|
-
requirement: &
|
16
|
+
requirement: &70173273170720 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.2.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70173273170720
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &70173273169240 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.9.2
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70173273169240
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: minitest
|
38
|
-
requirement: &
|
38
|
+
requirement: &70173273168380 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '2.6'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70173273168380
|
47
47
|
description: A Domain Specific Language(DSL) that you can use to talk to Git from
|
48
48
|
Ruby.
|
49
49
|
email:
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- .gitignore
|
56
56
|
- .travis.yml
|
57
57
|
- Gemfile
|
58
|
+
- LICENSE.txt
|
58
59
|
- README.md
|
59
60
|
- Rakefile
|
60
61
|
- ed.gemspec
|
@@ -62,8 +63,10 @@ files:
|
|
62
63
|
- examples/pry.rb
|
63
64
|
- examples/test-suite.rb
|
64
65
|
- lib/ed.rb
|
66
|
+
- lib/ed/config.rb
|
65
67
|
- lib/ed/context.rb
|
66
68
|
- lib/ed/core_ext/object.rb
|
69
|
+
- lib/ed/env.rb
|
67
70
|
- lib/ed/repository.rb
|
68
71
|
- lib/ed/version.rb
|
69
72
|
- test/setup.rb
|
@@ -80,18 +83,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
80
83
|
- - ! '>='
|
81
84
|
- !ruby/object:Gem::Version
|
82
85
|
version: '0'
|
83
|
-
segments:
|
84
|
-
- 0
|
85
|
-
hash: -643359230186522538
|
86
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
87
|
none: false
|
88
88
|
requirements:
|
89
89
|
- - ! '>='
|
90
90
|
- !ruby/object:Gem::Version
|
91
91
|
version: '0'
|
92
|
-
segments:
|
93
|
-
- 0
|
94
|
-
hash: -643359230186522538
|
95
92
|
requirements: []
|
96
93
|
rubyforge_project: Ed
|
97
94
|
rubygems_version: 1.8.11
|
@@ -101,3 +98,4 @@ summary: A Domain Specific Language(DSL) that you can use to talk to Git from Ru
|
|
101
98
|
test_files:
|
102
99
|
- test/setup.rb
|
103
100
|
- test/test_ed.rb
|
101
|
+
has_rdoc:
|