Skip to content

Commit

Permalink
Handle an int SHA
Browse files Browse the repository at this point in the history
The regexp will fail if SHA is an int.
  • Loading branch information
retr0h committed Nov 16, 2016
1 parent 95931be commit af1ce2e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gilt/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,6 @@ def _get_branch(version, debug=False):
util.run_command(cmd, debug=debug)
cmd = sh.git.bake('checkout', version)
util.run_command(cmd, debug=debug)
if not re.match(r'\b[0-9a-f]{7,40}\b', version):
if not re.match(r'\b[0-9a-f]{7,40}\b', str(version)):
cmd = sh.git.bake('pull', rebase=True, ff_only=True)
util.run_command(cmd, debug=debug)
51 changes: 51 additions & 0 deletions test/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import os

import pytest
import sh

from gilt import git

Expand Down Expand Up @@ -96,3 +97,53 @@ def test_overlay(mocker, temp_dir):
assert 1 == len(glob.glob('{}/nova_quota'.format(dst_dir)))
assert 1 == len(glob.glob('{}/neutron_router.py'.format(dst_dir)))
assert 2 == len(glob.glob('{}/*'.format(os.path.join(dst_dir, 'tests'))))


@pytest.fixture()
def patched_run_command(mocker):
return mocker.patch('gilt.util.run_command')


def test_get_branch(mocker, patched_run_command):
git._get_branch('branch')
expected = [
mocker.call(
sh.git.bake('clean', '-d', '-x', '-f'), debug=False),
mocker.call(
sh.git.bake('fetch'), debug=False),
mocker.call(
sh.git.bake('checkout', 'branch'), debug=False),
mocker.call(
sh.git.bake(
'pull', rebase=True, ff_only=True), debug=False),
]

assert expected == patched_run_command.mock_calls


def test_get_branch_does_not_pull_on_sha(mocker, patched_run_command):
git._get_branch('e14ebe0')
expected = [
mocker.call(
sh.git.bake('clean', '-d', '-x', '-f'), debug=False),
mocker.call(
sh.git.bake('fetch'), debug=False),
mocker.call(
sh.git.bake('checkout', 'e14ebe0'), debug=False),
]

assert expected == patched_run_command.mock_calls


def test_get_branch_handles_int_sha(mocker, patched_run_command):
git._get_branch(1234567)
expected = [
mocker.call(
sh.git.bake('clean', '-d', '-x', '-f'), debug=False),
mocker.call(
sh.git.bake('fetch'), debug=False),
mocker.call(
sh.git.bake('checkout', '1234567'), debug=False),
]

assert expected == patched_run_command.mock_calls

0 comments on commit af1ce2e

Please sign in to comment.