Skip to content

Commit 547e7e9

Browse files
committed
Avoid repoContr#show 404 if "Fetch changesets automatically"; fixes dergachev#6
1 parent 2cfde78 commit 547e7e9

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

app/models/repository/git_remote.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,32 @@ def clone_host
3636
return p[:host]
3737
end
3838

39-
# hook into Repository.fetch_changesets to also run 'git fetch'
39+
# Hook into Repository.fetch_changesets to also run 'git fetch'.
4040
def fetch_changesets
41+
# ensure we don't fetch twice during the same request
42+
return if @already_fetched
43+
@already_fetched = true
44+
4145
puts "Calling fetch changesets on #{clone_path}"
4246
# runs git fetch
4347
self.fetch
4448
super
4549
end
4650

51+
# Override default_branch to fetch, otherwise caching problems in
52+
# find_project_repository prevent Repository::Git#fetch_changesets from running.
53+
#
54+
# Ideally this would only be run for RepositoriesController#show.
55+
def default_branch
56+
if self.branches == [] && self.project.active? && Setting.autofetch_changesets?
57+
# git_adapter#branches caches @branches incorrectly, reset it
58+
scm.instance_variable_set :@branches, nil
59+
# NB: fetch_changesets is idemptotent during a given request, so OK to call it 2x
60+
self.fetch_changesets
61+
end
62+
super
63+
end
64+
4765
# called in before_validate handler, sets form errors
4866
def initialize_clone
4967
# avoids crash in RepositoriesController#destroy

0 commit comments

Comments
 (0)