mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-04-01 09:50:33 +08:00
Ignore entries in "git ls-remote" with "refs/remotes/origin/"
This commit is contained in:
@@ -185,6 +185,8 @@ class SCM(object):
|
||||
:returns: a string of the latest commit hash
|
||||
:raises: RuntimeError
|
||||
"""
|
||||
if ref is None:
|
||||
ref = 'master'
|
||||
if self.scheme == "git":
|
||||
log.debug("Getting/verifying commit hash for %s" % self.repository)
|
||||
# get all the branches on the remote
|
||||
@@ -195,8 +197,11 @@ class SCM(object):
|
||||
# {"master": "bf028e573e7c18533d89c7873a411de92d4d913e"...}.
|
||||
branches = {}
|
||||
for branch_and_ref in output.strip().split("\n"):
|
||||
# Only look at refs/heads/* and not refs/remotes/origin/*
|
||||
if "refs/heads/" not in branch_and_ref:
|
||||
continue
|
||||
# This grabs the last bit of text after the last "/", which is the branch name
|
||||
cur_branch = branch_and_ref.split("\t")[-1].split("/")[-1]
|
||||
cur_branch = branch_and_ref.split("\t")[-1].split("refs/heads/")[-1]
|
||||
# This grabs the text before the first tab, which is the commit hash
|
||||
cur_ref = branch_and_ref.split("\t")[0]
|
||||
branches[cur_branch] = cur_ref
|
||||
|
||||
@@ -25,6 +25,7 @@ import shutil
|
||||
import tempfile
|
||||
|
||||
import unittest
|
||||
from mock import patch
|
||||
from nose.tools import raises
|
||||
|
||||
import module_build_service.scm
|
||||
@@ -140,3 +141,15 @@ class TestSCMModule(unittest.TestCase):
|
||||
def test_get_latest_incorect_component_ref(self):
|
||||
scm = module_build_service.scm.SCM(repo_path)
|
||||
scm.get_latest('15481faa232d66589e660cc301179867fb00842c9')
|
||||
|
||||
@patch.object(module_build_service.scm.SCM, '_run')
|
||||
def test_get_latest_ignore_origin(self, mock_run):
|
||||
output = """\
|
||||
58379ef7887cbc91b215bacd32430628c92bc869\tHEAD
|
||||
58379ef7887cbc91b215bacd32430628c92bc869\trefs/heads/master
|
||||
10a651f39911a07d85fe87fcfe91999545e44ae0\trefs/remotes/origin/master
|
||||
"""
|
||||
mock_run.return_value = (0, output, '')
|
||||
scm = module_build_service.scm.SCM(repo_path)
|
||||
commit = scm.get_latest(None)
|
||||
self.assertEquals(commit, '58379ef7887cbc91b215bacd32430628c92bc869')
|
||||
|
||||
Reference in New Issue
Block a user