From 9257b34c25359a58093654d405212683a0617ef4 Mon Sep 17 00:00:00 2001 From: Eric Holscher Date: Mon, 10 Dec 2018 12:14:37 -0500 Subject: [PATCH 1/3] Only use remote branches for our syncing. We don't care about branches local to us. This causes bugs where a local and remote branch have the same name, and we sync `stable` in and endless loop. Fixes #4980 --- readthedocs/vcs_support/backends/git.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/readthedocs/vcs_support/backends/git.py b/readthedocs/vcs_support/backends/git.py index 32e711a7e7d..f20631cad0e 100644 --- a/readthedocs/vcs_support/backends/git.py +++ b/readthedocs/vcs_support/backends/git.py @@ -178,11 +178,8 @@ def branches(self): repo = git.Repo(self.working_dir) versions = [] - # ``repo.branches`` returns local branches and - branches = repo.branches # ``repo.remotes.origin.refs`` returns remote branches - if repo.remotes: - branches += repo.remotes.origin.refs + branches = repo.remotes.origin.refs for branch in branches: verbose_name = branch.name From 9b4937a60f92fd2c90f4364e5f59f815c5a3c45e Mon Sep 17 00:00:00 2001 From: Eric Holscher Date: Mon, 10 Dec 2018 12:24:55 -0500 Subject: [PATCH 2/3] Check for remotes before we add them --- readthedocs/vcs_support/backends/git.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/readthedocs/vcs_support/backends/git.py b/readthedocs/vcs_support/backends/git.py index f20631cad0e..c645966bb1f 100644 --- a/readthedocs/vcs_support/backends/git.py +++ b/readthedocs/vcs_support/backends/git.py @@ -177,9 +177,11 @@ def tags(self): def branches(self): repo = git.Repo(self.working_dir) versions = [] + branches = [] # ``repo.remotes.origin.refs`` returns remote branches - branches = repo.remotes.origin.refs + if repo.remotes: + branches += repo.remotes.origin.refs for branch in branches: verbose_name = branch.name From bedfb31a1723b1679c57e7a2b41df16f6bedef1f Mon Sep 17 00:00:00 2001 From: Eric Holscher Date: Mon, 10 Dec 2018 12:49:58 -0500 Subject: [PATCH 3/3] Support local git branches in tests --- readthedocs/settings/test.py | 1 + readthedocs/vcs_support/backends/git.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/readthedocs/settings/test.py b/readthedocs/settings/test.py index f49dc8584b1..398f8664b7e 100644 --- a/readthedocs/settings/test.py +++ b/readthedocs/settings/test.py @@ -16,6 +16,7 @@ class CommunityTestSettings(CommunityDevSettings): DEBUG = False TEMPLATE_DEBUG = False + LOCAL_GIT_BRANCHES = True @property def LOGGING(self): # noqa - avoid pep8 N802 diff --git a/readthedocs/vcs_support/backends/git.py b/readthedocs/vcs_support/backends/git.py index c645966bb1f..8da10bb4617 100644 --- a/readthedocs/vcs_support/backends/git.py +++ b/readthedocs/vcs_support/backends/git.py @@ -15,6 +15,7 @@ import git from builtins import str from django.core.exceptions import ValidationError +from django.conf import settings from git.exc import BadName from readthedocs.config import ALL @@ -182,6 +183,8 @@ def branches(self): # ``repo.remotes.origin.refs`` returns remote branches if repo.remotes: branches += repo.remotes.origin.refs + if getattr(settings, 'LOCAL_GIT_BRANCHES', False): + branches += repo.branches for branch in branches: verbose_name = branch.name