|
| 1 | +# System imports |
| 2 | +from os.path import join |
| 3 | + |
| 4 | +# 3rd party libs |
| 5 | +from nose.tools import * |
| 6 | +from git import * |
| 7 | + |
| 8 | +# PyGitup imports |
| 9 | +from tests import basepath, init_master, update_file, write_file |
| 10 | + |
| 11 | +test_name = 'submodule-dirty' |
| 12 | +repo_path = join(basepath, test_name + os.sep) |
| 13 | + |
| 14 | + |
| 15 | +def _read_file(path): |
| 16 | + with open(path) as f: |
| 17 | + return f.read() |
| 18 | + |
| 19 | + |
| 20 | +def setup(): |
| 21 | + master_path, master = init_master(test_name) |
| 22 | + |
| 23 | + # Prepare master repo |
| 24 | + master.git.checkout(b=test_name) |
| 25 | + |
| 26 | + # Crate test repo |
| 27 | + path = join(basepath, test_name) |
| 28 | + master.clone(path, b=test_name) |
| 29 | + repo = Repo(path, odbt=GitCmdObjectDB) |
| 30 | + # repo = Repo.init(path) |
| 31 | + # update_file(repo, 'Initial commit') |
| 32 | + |
| 33 | + os.chdir(path) |
| 34 | + assert repo.working_dir == path |
| 35 | + |
| 36 | + # Rename test repo branch |
| 37 | + repo.git.branch(test_name + '_renamed', m=True) |
| 38 | + |
| 39 | + # Add subrepo |
| 40 | + write_file(join(path, '.gitmodules'), '') |
| 41 | + repo.create_submodule('sub', 'sub', master_path) |
| 42 | + repo.git.add('.gitmodules', 'sub/') |
| 43 | + repo.git.commit(m='Added submodule') |
| 44 | + repo.git.submodule('init') |
| 45 | + |
| 46 | + # Modify file in master |
| 47 | + update_file(master, test_name) |
| 48 | + |
| 49 | + |
| 50 | +def test_submodules_dirty(): |
| 51 | + """ Run 'git up' with submodules in a dirty repo """ |
| 52 | + repo = Repo(repo_path) |
| 53 | + repo_head = repo.head.commit.hexsha |
| 54 | + submod_head = repo.submodules[0].hexsha |
| 55 | + |
| 56 | + # Change file in submodule |
| 57 | + write_file('sub/file', 'submodule changed') |
| 58 | + |
| 59 | + from PyGitUp.gitup import GitUp |
| 60 | + gitup = GitUp(testing=True) |
| 61 | + |
| 62 | + # PyGitUp uses the main repo |
| 63 | + assert_equal(repo_head, gitup.git.repo.head.commit.hexsha) |
| 64 | + |
| 65 | + gitup.run() |
| 66 | + |
| 67 | + assert_equal(len(gitup.states), 1) |
| 68 | + assert_equal(gitup.states[0], 'rebasing') |
0 commit comments