winton-externals 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/bin/externals CHANGED
@@ -3,12 +3,5 @@
3
3
  require 'rubygems'
4
4
  require 'externals'
5
5
 
6
- action = ARGV[0]
7
- available_actions = %w(status freeze unfreeze)
8
- unless available_actions.include?(action)
9
- puts "Usage: externals (#{available_actions.join(':')})"
10
- exit 1
11
- end
12
-
13
6
  app = Externals::App.new(FileUtils.pwd)
14
- app.run(action)
7
+ app.run(ARGV[0])
data/externals.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'externals'
3
- s.version = '0.1.4'
4
- s.date = '2008-03-11'
3
+ s.version = '0.1.5'
4
+ s.date = '2008-03-12'
5
5
 
6
6
  s.summary = "Work on git externals without affecting others"
7
7
  s.description = "Work on git externals without affecting others"
data/lib/externals/app.rb CHANGED
@@ -8,22 +8,20 @@ module Externals
8
8
  config.each_repo {|r| r.status }
9
9
  end
10
10
 
11
- def freezify
12
- config.each_repo {|r| r.freezify }
11
+ def freeze
12
+ config.each_repo {|r| r.freeze }
13
13
  end
14
14
 
15
- def unfreezify
16
- config.each_repo {|r| r.unfreezify }
15
+ def unfreeze
16
+ config.each_repo {|r| r.unfreeze }
17
17
  end
18
18
 
19
19
  def run(action)
20
- case action
21
- when "status"
22
- status
23
- when "freeze"
24
- freezify
25
- when "unfreeze"
26
- unfreezify
20
+ available_actions = %w(status freeze unfreeze)
21
+ if available_actions.include?(action)
22
+ send(action)
23
+ else
24
+ puts "Usage: externals (#{available_actions.join(':')})"
27
25
  end
28
26
  end
29
27
 
@@ -36,10 +34,9 @@ module Externals
36
34
 
37
35
  if config_file.nil?
38
36
  $stderr.puts "config/externals.yml is missing"
39
- exit 1
37
+ else
38
+ @config = YamlConfig.new(@base_dir, File.read(config_file))
40
39
  end
41
-
42
- @config = YamlConfig.new(@base_dir, File.read(config_file))
43
40
  end
44
41
  end
45
42
  end
@@ -11,71 +11,97 @@ module Externals
11
11
  end
12
12
 
13
13
  def install
14
- FileUtils.mkdir_p checkout_path unless File.exist?(checkout_path)
15
- `cd #{checkout_path} && rm -Rf #{@name} && git clone #{@repo_url} #{@name}`
16
- puts "#{@name} unfrozen"
17
- true
14
+ # Create directory that we will clone into
15
+ unless File.exist?(checkout_path)
16
+ FileUtils.mkdir_p(checkout_path)
17
+ end
18
+ Dir.chdir(checkout_path) do
19
+ # Remove repository if exists
20
+ FileUtils.rm_rf(@name)
21
+ # Clone repository
22
+ `git clone #{@repo_url} #{@name}`
23
+ end
18
24
  end
19
25
 
20
- def freezify
21
- install unless File.exist?(repo_path)
22
- if frozen?
26
+ def freeze
27
+ install unless exists?
28
+ if is_not_a_git_repo?
23
29
  puts "#{@name} is already frozen"
24
- elsif can_be_frozen?
30
+ elsif is_a_git_repo?
31
+ overwrite = true
32
+ # Conditionally destroy compressed repo
33
+ if is_compressed?
34
+ puts "You already have a frozen git snapshot. Overwrite?"
35
+ overwrite = STDIN.gets.downcase[0..0] == 'y'
36
+ end
25
37
  Dir.chdir(repo_path) do
26
- `rm #{temp_path}/#{@name}.git.tgz` if can_be_unfrozen?
27
- `mkdir -p #{temp_path}`
28
- `tar czf #{temp_path}/#{@name}.git.tgz .git`
38
+ if overwrite
39
+ # Make temp directory
40
+ FileUtils.mkdir_p(temp_path)
41
+ # Compress .git folder to temp
42
+ `tar czf #{temp_path}/#{@name}.git.tgz .git`
43
+ end
44
+ # Remove repository's .git folder
29
45
  FileUtils.rm_r('.git')
30
46
  end
31
47
  puts "#{@name} frozen"
32
- else
33
- install
34
- freezify
35
48
  end
36
- true
37
49
  end
38
50
 
39
51
  def status
40
- puts "#{@name} is #{can_be_frozen? ? "not frozen" : "frozen"}"
52
+ if exists?
53
+ puts "#{@name} is #{is_a_git_repo? ? "not frozen" : "frozen and #{is_compressed? ? "has" : "does not have"} a snapshot"}"
54
+ else
55
+ puts "#{@name} does not exist and #{is_compressed? ? "has" : "does not have"} a snapshot"
56
+ end
41
57
  end
42
58
 
43
- def unfreezify
44
- install unless File.exist?(repo_path)
45
- if unfrozen?
59
+ def unfreeze
60
+ if is_a_git_repo?
46
61
  puts "#{@name} is already unfrozen"
47
- elsif can_be_unfrozen?
48
- Dir.chdir(temp_path) do
49
- `tar xzf #{@name}.git.tgz`
50
- FileUtils.mv(".git", repo_path)
51
- FileUtils.rm("#{@name}.git.tgz")
52
- end
53
- Dir.chdir(repo_path) do
54
- `git reset --hard`
62
+ elsif !exists?
63
+ install
64
+ puts "#{@name} unfrozen"
65
+ elsif is_not_a_git_repo?
66
+ if is_compressed?
67
+ Dir.chdir(temp_path) do
68
+ # Decompress git snapshot
69
+ `tar xzf #{@name}.git.tgz`
70
+ # Move back to repo
71
+ FileUtils.mv(".git", repo_path)
72
+ # Remove snapshot
73
+ FileUtils.rm_f("#{@name}.git.tgz")
74
+ end
75
+ # Reset repository to snapshot
76
+ Dir.chdir(repo_path) do
77
+ `git reset --hard`
78
+ end
79
+ else
80
+ # Clone fresh repo if no snapshot found
81
+ install
55
82
  end
56
83
  puts "#{@name} unfrozen"
57
- else
58
- install
59
84
  end
60
- true
61
85
  end
62
86
 
63
- def can_be_frozen?
87
+ def exists?
88
+ File.exist?(repo_path)
89
+ end
90
+
91
+ def is_a_git_repo?
64
92
  File.exist?("#{repo_path}/.git")
65
93
  end
66
94
 
67
- def can_be_unfrozen?
68
- File.exists?("#{temp_path}/#{@name}.git.tgz")
95
+ def is_not_a_git_repo?
96
+ !is_a_git_repo?
69
97
  end
70
-
71
- def frozen?
72
- !File.exist?("#{repo_path}/.git") &&
98
+
99
+ def is_compressed?
73
100
  File.exists?("#{temp_path}/#{@name}.git.tgz")
74
101
  end
75
102
 
76
- def unfrozen?
77
- File.exist?("#{repo_path}/.git") &&
78
- !File.exists?("#{temp_path}/#{@name}.git.tgz")
103
+ def is_not_compressed?
104
+ !is_compressed?
79
105
  end
80
106
 
81
107
  private
@@ -86,10 +112,6 @@ module Externals
86
112
  def repo_path
87
113
  File.expand_path(checkout_path + '/' + @name)
88
114
  end
89
-
90
- def rel_repo_path
91
- @rel_path + '/' + @name
92
- end
93
115
 
94
116
  def temp_path
95
117
  @base_dir + '/tmp'
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,5 @@
1
- $TESTING=true
2
- $:.push File.join(File.dirname(__FILE__), '..', 'lib')
1
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
3
2
 
4
- Spec::Runner.configure do |config|
5
-
6
- end
3
+ require 'rubygems'
4
+ require 'externals'
5
+ require 'spec'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: winton-externals
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Winton Welsh
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-03-11 00:00:00 -07:00
12
+ date: 2008-03-12 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15