Commit 52e45e47 authored by Michal Čihař's avatar Michal Čihař

Improve git repository setup

With configured origin remote in global git config, current approach
failed as it had half existing remote (repo.remotes.origin did not
exist, but git remote did show it).

Now we do not try to add origin if git already sees it and we configure
branches to fetch, this should also prevent fetching of branches we
don't follow.

Fixes #268.
parent 7cfd690b
......@@ -394,22 +394,32 @@ class SubProject(models.Model, PercentMixin, URLMixin):
'''
if self.is_repo_link():
return self.linked_subproject.configure_repo(validate)
# Get/Create origin remote
try:
origin = self.git_repo.remotes.origin
except AttributeError:
# Create origin remote if it does not exist
if 'origin' not in self.git_repo.git.remote().split():
self.git_repo.git.remote('add', 'origin', self.repo)
origin = self.git_repo.remotes.origin
# Check remote source
if origin.url != self.repo:
self.git_repo.git.remote('set-url', 'origin', self.repo)
# Set remote URL
self.git_repo.git.remote('set-url', 'origin', self.repo)
# Set branch to track
# We first need to add one to ensure there is at least one branch
self.git_repo.git.remote('set-branches', '--add', 'origin', self.branch)
# Then we can set to track just one
self.git_repo.git.remote('set-branches', 'origin', self.branch)
# Get object for remote
origin = self.git_repo.remotes.origin
# Check push url
try:
pushurl = origin.pushurl
except AttributeError:
pushurl = ''
if pushurl != self.push:
self.git_repo.git.remote('set-url', 'origin', '--push', self.push)
# Update
self.update_remote_branch(validate)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment