Avoid repoContr#show 404 if "Fetch changesets automatically"; fixes #6

This commit is contained in:
Alex Dergachev 2014-12-08 22:23:05 +00:00
parent 2cfde78822
commit 547e7e9cf0

View File

@ -36,14 +36,32 @@ class Repository::GitRemote < Repository::Git
return p[:host]
end
# hook into Repository.fetch_changesets to also run 'git fetch'
# Hook into Repository.fetch_changesets to also run 'git fetch'.
def fetch_changesets
# ensure we don't fetch twice during the same request
return if @already_fetched
@already_fetched = true
puts "Calling fetch changesets on #{clone_path}"
# runs git fetch
self.fetch
super
end
# Override default_branch to fetch, otherwise caching problems in
# find_project_repository prevent Repository::Git#fetch_changesets from running.
#
# Ideally this would only be run for RepositoriesController#show.
def default_branch
if self.branches == [] && self.project.active? && Setting.autofetch_changesets?
# git_adapter#branches caches @branches incorrectly, reset it
scm.instance_variable_set :@branches, nil
# NB: fetch_changesets is idemptotent during a given request, so OK to call it 2x
self.fetch_changesets
end
super
end
# called in before_validate handler, sets form errors
def initialize_clone
# avoids crash in RepositoriesController#destroy