Skip to content

Commit

Permalink
[SourcesManager] Ignore repos with unreachable sources on update
Browse files Browse the repository at this point in the history
  • Loading branch information
joshkalpin committed Nov 14, 2013
1 parent 9f03ab9 commit afd42d7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/cocoapods/sources_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def update(source_name = nil, show_output = false)
raise Informative, "The `#{source_name}` repo is not a git repo." unless git_repo?(specified_source.repo)
sources = [specified_source]
else
sources = aggregate.all.select { |source| git_repo?(source.repo) }
sources = aggregate.all.select { |source| git_repo?(source.repo) && git_remote_reachable?(source.repo) }

This comment has been minimized.

Copy link
@jollychang

jollychang Feb 17, 2014

@kapin every time when pod install/update will check git_remote_reachable?
but git ls-remote is very slow, so can this feature be switch by options?

[jollychang@WilliamMBP CocoaPods]$ time git ls-remote
From git@github.com:CocoaPods/CocoaPods.git
real 0m10.546s

This comment has been minimized.

Copy link
@kylef

kylef Feb 17, 2014

Contributor

You can disable this (and performing any git pull's) with pod install --no-repo-update.

This comment has been minimized.

Copy link
@joshkalpin

joshkalpin Feb 18, 2014

Author Member

What @kylef said will work. I tried to figure out a faster way to do this at the time but I'm not a git master by any means. If you have a faster way I highly encourage you to make a pull request 😄

This comment has been minimized.

Copy link
@jollychang

jollychang Feb 18, 2014

pod install --no-repo-update is fine,Thanks
but why need to check git_remote_reachable or git ls-remote?
if what you need is update repo ,why not just git pull?

This comment has been minimized.

Copy link
@joshkalpin

joshkalpin Feb 18, 2014

Author Member

If I recall correctly the issue was when there was a custom firewalled specs repo, pod install broke. So we check if the repo is reachable before trying to get at it.

This comment has been minimized.

Copy link
@kylef

kylef Feb 18, 2014

Contributor

@kapin Is this the same thing as https://github.com/kylef/CocoaPods/commit/567b74c47dbc4e23cee098acaa8f433554523ba1 ?

That uses git remote which is quicker than git ls-remote.

This comment has been minimized.

Copy link
@jollychang

jollychang Feb 18, 2014

I am not familiar with pod's logic, so why not check(throw out error) the remote/branch of repo by git itself?

jenkins@jolly1 /tmp $ git pull aaa
fatal: 'aaa' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
jenkins@jolly1 /tmp $ echo $?
1
jenkins@jolly1 /tmp $ git pull origin tttt
fatal: Couldn't find remote ref tttt
Unexpected end of command stream
jenkins@jolly1 /tmp $ echo $?
1

This comment has been minimized.

Copy link
@kylef

kylef Feb 18, 2014

Contributor

@kapin Thinking about this more, a safer solution would be to check that there is an upstream setup for the branch.

$ git config --get branch.$(git rev-parse --abbrev-ref HEAD).remote
origin

Since I could have a remote but not configure for the current branch. As shown in the following example:

$ git checkout -b testing_branch
Switched to a new branch 'testing_branch'
$ git push
fatal: The current branch testing_branch has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin testing_branch

This comment has been minimized.

Copy link
@joshkalpin

joshkalpin Feb 20, 2014

Author Member

@kylef I found the original issue here #1571. The issue with that one was that pod install was exploding if a repo's remote was unreachable. I'm not sure if that's the same case, but that might provide a bit more insight.

end

sources.each do |source|
Expand All @@ -159,12 +159,24 @@ def update(source_name = nil, show_output = false)
end
end

# Returns whether a git repo's remote is reachable.
#
# @param [Pathname] dir
# The directory where the source is stored.
#
# @return [Bool] Whether the given source's remote is reachable.
#
def git_remote_reachable?(dir)
Dir.chdir(dir) { `git ls-remote` }
$?.exitstatus.zero?
end

# Returns whether a source is a GIT repo.
#
# @param [Pathname] dir
# The directory where the source is stored.
#
# @return [Bool] Wether the given source is a GIT repo.
# @return [Bool] Whether the given source is a GIT repo.
#
def git_repo?(dir)
Dir.chdir(dir) { `git rev-parse >/dev/null 2>&1` }
Expand Down
5 changes: 5 additions & 0 deletions spec/unit/sources_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ module Pod
UI.output.should.match /Already up-to-date/
end

it 'returns whether a source has a reachable git remote' do
SourcesManager.git_remote_reachable?(repo_make('a_new_repo_that_is_new')).should.be.false
SourcesManager.git_remote_reachable?(SourcesManager.master_repo_dir).should.be.true
end

it "returns whether a source is backed by a git repo" do
SourcesManager.git_repo?(SourcesManager.master_repo_dir).should.be.true
SourcesManager.git_repo?(Pathname.new('/tmp')).should.be.false
Expand Down

0 comments on commit afd42d7

Please sign in to comment.