Skip to content
This repository
Browse code

Merge branch 'master' into improved-search

* master:
  [#184] fix for documentation options
  [#180] check appledoc exit status
  [#112] Refactoring based on suggestions by @alloy
  [#112] Improved remote url detection for spec repo
  [#132, #183] Fix to make repo update tolerant of stray files ~./cocoapods
  [#112] Introduced --push option for setup command
  • Loading branch information...
commit 9d87bf4023abbdff8a56c08953c8054f7b9a23bf 2 parents 53b7113 + 18bc2ab
Fabio Pelosin authored March 22, 2012
1  cocoapods.gemspec
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
29 29
                            "you are upgrading, first run: $ pod setup"
30 30
 
31 31
   s.add_runtime_dependency 'xcodeproj', '~> 0.1.0'
  32
+  s.add_runtime_dependency 'popen4', '~> 0.1.2'
32 33
   s.add_development_dependency 'bacon', '~> 1.1'
33 34
 
34 35
   ## Make sure you can build the gem on older versions of RubyGems too:
16  lib/cocoapods/command/repo.rb
@@ -14,11 +14,7 @@ def self.banner
14 14
     $ pod repo update NAME
15 15
 
16 16
       Updates the local clone of the spec-repo `NAME'. If `NAME' is omitted
17  
-      this will update all spec-repos in `~/.cocoapods'.
18  
-
19  
-    $ pod repo set-url NAME URL
20  
-
21  
-      Updates the remote `URL' of the spec-repo `NAME'.}
  17
+      this will update all spec-repos in `~/.cocoapods'.}
22 18
       end
23 19
 
24 20
       extend Executable
@@ -26,7 +22,7 @@ def self.banner
26 22
 
27 23
       def initialize(argv)
28 24
         case @action = argv.arguments[0]
29  
-        when 'add', 'set-url'
  25
+        when 'add'
30 26
           unless (@name = argv.arguments[1]) && (@url = argv.arguments[2])
31 27
             raise Informative, "#{@action == 'add' ? 'Adding' : 'Updating the remote of'} a repo needs a `name' and a `url'."
32 28
           end
@@ -52,18 +48,12 @@ def add
52 48
       end
53 49
 
54 50
       def update
55  
-        dirs = @name ? [dir] : config.repos_dir.children
  51
+        dirs = @name ? [dir] : config.repos_dir.children.select {|c| c.directory?}
56 52
         dirs.each do |dir|
57 53
           puts "Updating spec repo `#{dir.basename}'" unless config.silent?
58 54
           Dir.chdir(dir) { git("pull") }
59 55
         end
60 56
       end
61  
-
62  
-      def set_url
63  
-        Dir.chdir(dir) do
64  
-          git("remote set-url origin '#{@url}'")
65  
-        end
66  
-      end
67 57
     end
68 58
   end
69 59
 end
53  lib/cocoapods/command/setup.rb
@@ -14,20 +14,58 @@ def self.banner
14 14
       If the clone already exists, it will ensure that it is up-to-date.}
15 15
       end
16 16
 
  17
+      def self.options
  18
+        "    --push      Use this option to enable push access once granted\n" +
  19
+        super
  20
+      end
  21
+
  22
+      extend Executable
  23
+      executable :git
  24
+
17 25
       def initialize(argv)
  26
+        @push_option  = argv.option('--push')
18 27
         super unless argv.empty?
19 28
       end
20 29
 
21  
-      def master_repo_url
  30
+      def dir
  31
+        config.repos_dir + 'master'
  32
+      end
  33
+
  34
+      def read_only_url
22 35
         'git://github.com/CocoaPods/Specs.git'
23 36
       end
24 37
 
25  
-      def add_master_repo_command
26  
-        @command ||= Repo.new(ARGV.new(['add', 'master', master_repo_url]))
  38
+      def read_write_url
  39
+        'git@github.com:CocoaPods/Specs.git'
  40
+      end
  41
+
  42
+      def url
  43
+        if push?
  44
+          read_write_url
  45
+        else
  46
+          read_only_url
  47
+        end
27 48
       end
28 49
 
29  
-      def update_master_repo_remote_command
30  
-        Repo.new(ARGV.new(['set-url', 'master', master_repo_url]))
  50
+      def origin_url_push?
  51
+        Dir.chdir(dir) do
  52
+          origin_url = git('config --get remote.origin.url')
  53
+          origin_url.chomp == read_write_url
  54
+        end
  55
+      end
  56
+
  57
+      def push?
  58
+       @push_option || (dir.exist? && origin_url_push?)
  59
+      end
  60
+
  61
+      def set_master_repo_url
  62
+        Dir.chdir(dir) do
  63
+          git("remote set-url origin '#{url}'")
  64
+        end
  65
+      end
  66
+
  67
+      def add_master_repo_command
  68
+        @command ||= Repo.new(ARGV.new(['add', 'master', url]))
31 69
       end
32 70
 
33 71
       def update_master_repo_command
@@ -35,8 +73,9 @@ def update_master_repo_command
35 73
       end
36 74
 
37 75
       def run
38  
-        if (config.repos_dir + 'master').exist?
39  
-          update_master_repo_remote_command.run
  76
+        puts "Using push access" if push? && !config.silent
  77
+        if dir.exist?
  78
+          set_master_repo_url
40 79
           update_master_repo_command.run
41 80
         else
42 81
           add_master_repo_command.run
33  lib/cocoapods/generator/documentation.rb
... ...
@@ -1,4 +1,4 @@
1  
-require 'open3'
  1
+require 'open4'
2 2
 
3 3
 module Pod
4 4
   module Generator
@@ -15,7 +15,7 @@ def self.appledoc_installed?
15 15
       def initialize(pod)
16 16
         @pod = pod
17 17
         @specification = pod.specification
18  
-        @target_path = pod.sandbox.root + "Documentation" + pod.name
  18
+        @target_path = pod.sandbox.root + 'Documentation' + pod.name
19 19
         @options = pod.specification.documentation || {}
20 20
       end
21 21
 
@@ -36,7 +36,7 @@ def copyright
36 36
       end
37 37
 
38 38
       def description
39  
-        @specification.description || "Generated by CocoaPods."
  39
+        @specification.description || 'Generated by CocoaPods.'
40 40
       end
41 41
 
42 42
       def docs_id
@@ -49,7 +49,7 @@ def files
49 49
 
50 50
       def index_file
51 51
         @pod.chdir do
52  
-          Dir.glob("README*", File::FNM_CASEFOLD).first
  52
+          Dir.glob('README*', File::FNM_CASEFOLD).first
53 53
         end
54 54
       end
55 55
 
@@ -76,10 +76,12 @@ def generate(install = false)
76 76
           puts "[!] Skipping documentation generation because appledoc can't be found." if config.verbose?
77 77
           return
78 78
         end
  79
+
79 80
         options = generate_appledoc_options
80 81
         options += ['--output', @target_path.to_s]
81 82
         options += ['--keep-intermediate-files']
82  
-        options += install ? ['-create-docset'] : ['--no-create-docset']
  83
+        options += install ? ['--create-docset'] : ['--no-create-docset']
  84
+
83 85
         @target_path.mkpath
84 86
         @pod.chdir do
85 87
           appledoc(options)
@@ -91,22 +93,19 @@ def appledoc(options)
91 93
         arguments += options
92 94
         arguments += ['--print-settings'] if config.verbose?
93 95
         arguments += files.map(&:to_s)
94  
-        Open3.popen3('appledoc', *arguments) do |i, o, e|
  96
+
  97
+        process = Open4.popen4('appledoc', *arguments) do |_, _, output, error|
95 98
           if config.verbose?
96  
-            puts o.read.chomp
97  
-            puts e.read.chomp
98  
-          else
99  
-            # TODO: This is needed otherwise appledoc may not install the doc set
100  
-            # This is a work around related to poor understanding of the IO class.
101  
-            #
102  
-            # I think we can use the non-block version here, which should read
103  
-            # everything till the end and then return.
104  
-            o.read
105  
-            e.read
  99
+            puts output.read.chomp
  100
+            puts error.read.chomp
106 101
           end
107 102
         end
108  
-      end
109 103
 
  104
+        # appledoc exits with 1 if a warning was logged
  105
+        if (process.exitstatus >= 2) && !config.silent?
  106
+          puts "[!] Appledoc encountered an error. Run 'pod install --verbose' for details."
  107
+        end
  108
+      end
110 109
     end
111 110
   end
112 111
 end
12  spec/functional/command_spec.rb
@@ -6,11 +6,21 @@
6 6
 
7 7
   it "creates the local spec-repos directory and creates a clone of the `master' repo" do
8 8
     command = Pod::Command.parse('setup', '--silent')
9  
-    def command.master_repo_url; SpecHelper.fixture('spec-repos/master'); end
  9
+    def command.url; SpecHelper.fixture('spec-repos/master'); end
10 10
     command.run
11 11
     git_config('master', 'remote.origin.url').should == fixture('spec-repos/master').to_s
12 12
   end
13 13
 
  14
+  it "preserve push access for the `master' repo" do
  15
+    command = Pod::Command.parse('setup', '--silent')
  16
+    def command.url; SpecHelper.fixture('spec-repos/master'); end
  17
+    command.run
  18
+    command2 = Pod::Command.parse('setup', '--silent')
  19
+    command2.url.should == 'git://github.com/CocoaPods/Specs.git'
  20
+    git('master', 'remote set-url origin git@github.com:CocoaPods/Specs.git')
  21
+    command2.url.should == 'git@github.com:CocoaPods/Specs.git'
  22
+  end
  23
+
14 24
   it "adds a spec-repo" do
15 25
     add_repo('private', fixture('spec-repos/master'))
16 26
     git_config('private', 'remote.origin.url').should == fixture('spec-repos/master').to_s
11  spec/unit/command_spec.rb
@@ -2,6 +2,7 @@
2 2
 
3 3
 describe "Pod::Command" do
4 4
   it "returns the proper command class" do
  5
+    config.silent.should == true
5 6
     Pod::Command.parse('setup').should.be.instance_of Pod::Command::Setup
6 7
     #Pod::Command.parse('spec').should.be.instance_of Pod::Command::Spec
7 8
     Pod::Command.parse('repo', 'update').should.be.instance_of Pod::Command::Repo
@@ -13,9 +14,15 @@
13 14
     lambda { Pod::Command::Setup.new(argv('something')) }.should.raise Pod::Command::Help
14 15
   end
15 16
 
16  
-  it "returns the URL of the `master' spec-repo" do
  17
+  it "returns the read only URL of the `master' spec-repo" do
17 18
     command = Pod::Command::Setup.new(argv)
18  
-    command.master_repo_url.should == 'git://github.com/CocoaPods/Specs.git'
  19
+    command.url.should == 'git://github.com/CocoaPods/Specs.git'
  20
+  end
  21
+
  22
+  it "returns the push URL of the `master' spec-repo" do
  23
+    config.silent = true
  24
+    command = Pod::Command::Setup.new(argv('--push'))
  25
+    command.url.should == 'git@github.com:CocoaPods/Specs.git'
19 26
   end
20 27
 end
21 28
 

0 notes on commit 9d87bf4

Please sign in to comment.
Something went wrong with that request. Please try again.