# Path: vilya/libs/git.py
# PULL_REF_H = 'refs/pulls/%s/head'
# 
# PULL_REF_M = 'refs/pulls/%s/merge'
# 
# def make_git_env(user=None, is_anonymous=False):
#     env = {}
#     if is_anonymous:
#         env['GIT_AUTHOR_NAME'] = 'anonymous'
#         env['GIT_AUTHOR_EMAIL'] = 'anonymous@douban.com'
#         env['GIT_COMMITTER_NAME'] = 'anonymous'
#         env['GIT_COMMITTER_EMAIL'] = 'anonymous@douban.com'
#     else:
#         env['GIT_AUTHOR_NAME'] = user.name
#         env['GIT_AUTHOR_EMAIL'] = user.email
#         env['GIT_COMMITTER_NAME'] = user.name
#         env['GIT_COMMITTER_EMAIL'] = user.email
#     return env
# 
# Path: vilya/settings.py
# TEMP_PATH = './temp'


import os
import shutil
        import tempfile
from ..libs.git import PULL_REF_H, PULL_REF_M, make_git_env
from ..settings import TEMP_PATH
        # TODO origin_remote_name
        return 'refs/remotes/%s/%s' % (self.origin_project.remote_name,
                                       reference)

    @property
    def upstream_head_reference(self):
        return 'refs/heads/%s' % self.pullrequest.upstream_project_ref

    def sync_pull_reference(self):
        repo = self.upstream_project.repository
        repo.update_reference(self.pull_upstream_reference,
                              self.upstream_head_reference)
        repo.update_reference(self.pull_origin_reference,
                              self.origin_head_reference)

    def fetch(self, repo=None):
        if self.pullrequest.is_local():
            return

        origin = self.origin_project
        if not repo:
            repo = self.repository

        remotes = repo.list_remotes()
        rs = [r.name for r in remotes]
        if origin.remote_name not in rs:
            repo.create_remote(origin.remote_name,
                               origin.repository.path)
        repo.fetch(origin.remote_name)


# Path: vilya/libs/git.py
# PULL_REF_H = 'refs/pulls/%s/head'
# 
# PULL_REF_M = 'refs/pulls/%s/merge'
# 
# def make_git_env(user=None, is_anonymous=False):
#     env = {}
#     if is_anonymous:
#         env['GIT_AUTHOR_NAME'] = 'anonymous'
#         env['GIT_AUTHOR_EMAIL'] = 'anonymous@douban.com'
#         env['GIT_COMMITTER_NAME'] = 'anonymous'
#         env['GIT_COMMITTER_EMAIL'] = 'anonymous@douban.com'
#     else:
#         env['GIT_AUTHOR_NAME'] = user.name
#         env['GIT_AUTHOR_EMAIL'] = user.email
#         env['GIT_COMMITTER_NAME'] = user.name
#         env['GIT_COMMITTER_EMAIL'] = user.email
#     return env
# 
# Path: vilya/settings.py
# TEMP_PATH = './temp'


# Path: vilya/pullrequests/repository.py
import os
import shutil
        import tempfile
from ..libs.git import PULL_REF_H, PULL_REF_M, make_git_env
from ..settings import TEMP_PATH

        # TODO origin_remote_name
        return 'refs/remotes/%s/%s' % (self.origin_project.remote_name,
                                       reference)

    @property
    def upstream_head_reference(self):
        return 'refs/heads/%s' % self.pullrequest.upstream_project_ref

    def sync_pull_reference(self):
        repo = self.upstream_project.repository
        repo.update_reference(self.pull_upstream_reference,
                              self.upstream_head_reference)
        repo.update_reference(self.pull_origin_reference,
                              self.origin_head_reference)

    def fetch(self, repo=None):
        if self.pullrequest.is_local():
            return

        origin = self.origin_project
        if not repo:
            repo = self.repository

        remotes = repo.list_remotes()
        rs = [r.name for r in remotes]
        if origin.remote_name not in rs:
            repo.create_remote(origin.remote_name,
                               origin.repository.path)
        repo.fetch(origin.remote_name)


    def sync(self):