Skip to content
This repository has been archived by the owner on Nov 30, 2020. It is now read-only.

Commit

Permalink
Add test for git_push function
Browse files Browse the repository at this point in the history
  • Loading branch information
jlesquembre committed Jan 27, 2016
1 parent 9fcc6c5 commit 9ccbdda
Showing 1 changed file with 38 additions and 7 deletions.
45 changes: 38 additions & 7 deletions tests/git_test.py
@@ -1,3 +1,7 @@
import tempfile

from pathlib import Path

import pytest

from git import Repo
Expand All @@ -7,7 +11,6 @@
from autopilot.exceptions import FatalError



def test_init_repo(dir_with_file):
git.init_repo(dir_with_file)

Expand Down Expand Up @@ -43,13 +46,13 @@ def test_init_repo_with_user(dir_with_file):


def test_is_repo_clean(git_dir):
assert git.is_repo_clean(repo_path=str(git_dir)) == None
assert git.is_repo_clean(repo_path=str(git_dir)) is None

new_file = git_dir / 'new_file.txt'
with new_file.open('w') as f:
f.write('Some text')

p = capture_stdout('git add new_file.txt', cwd=str(git_dir))
run('git add new_file.txt', cwd=str(git_dir))
with pytest.raises(FatalError) as excinfo:
git.is_repo_clean(repo_path=str(git_dir))
assert 'working tree contains modifications' in str(excinfo.value)
Expand All @@ -68,7 +71,7 @@ def test_is_repo_clean_no_master(git_dir):
git.is_repo_clean(repo_path=str(git_dir))
assert 'branch should be master' in str(excinfo.value)

assert git.is_repo_clean(repo_path=str(git_dir), master=False) == None
assert git.is_repo_clean(repo_path=str(git_dir), master=False) is None


def test_git_checkout_tag(git_dir):
Expand All @@ -81,9 +84,37 @@ def test_git_checkout_tag(git_dir):
run('git add {}'.format(new_file), cwd=git_dir.as_posix())
run('git commit -m "message"', cwd=git_dir.as_posix())

assert new_file.exists() == True
assert new_file.exists() is True

with git.checkout_tag(Repo(git_dir.as_posix()), 'v1'):
assert new_file.exists() == False
assert new_file.exists() is False

assert new_file.exists() is True


def test_git_push(git_dir):

with tempfile.TemporaryDirectory() as tempdir:

bare_dir = Path(tempdir)
run('git --bare init', cwd=bare_dir.as_posix())
run('git remote add origin {}'.format(bare_dir), cwd=git_dir.as_posix())
run('git push --set-upstream origin master', cwd=git_dir.as_posix())

# create tag, add file and do commit
run('git tag v1', cwd=git_dir.as_posix())
new_file = git_dir / 'new_file.txt'
with new_file.open('w') as f:
f.write('Some text')
run('git add {}'.format(new_file), cwd=git_dir.as_posix())
run('git commit -m "message"', cwd=git_dir.as_posix())

git.git_push(Repo(git_dir.as_posix()), 'v1')

p = capture_stdout('git ls-tree -r HEAD --name-only', cwd=str(bare_dir.as_posix()))
files = p.stdout.text.splitlines()

assert 'new_file.txt' in files

assert new_file.exists() == True
p = capture_stdout('git describe --abbrev=0 --tags', cwd=bare_dir.as_posix())
assert p.stdout.text == 'v1\n'

0 comments on commit 9ccbdda

Please sign in to comment.