<s> import os <EOL> from qisrc . git_config import Branch <EOL> def create_foo ( git_server , tmpdir , test_git ) : <EOL> foo_git = test_git ( tmpdir . join ( "<STR_LIT:foo>" ) . strpath ) <EOL> foo_repo = git_server . create_repo ( "<STR_LIT>" ) <EOL> foo_git . clone ( foo_repo . clone_url ) <EOL> return foo_git <EOL> def test_up_to_date ( git_server , tmpdir , test_git ) : <EOL> foo_git = create_foo ( git_server , tmpdir , test_git ) <EOL> branch = Branch ( ) <EOL> branch . name = "<STR_LIT>" <EOL> branch . tracks = "<STR_LIT>" <EOL> foo_git . sync_branch ( branch ) <EOL> def test_fast_forward ( git_server , tmpdir , test_git ) : <EOL> foo_git = create_foo ( git_server , tmpdir , test_git ) <EOL> branch = Branch ( ) <EOL> branch . name = "<STR_LIT>" <EOL> branch . tracks = "<STR_LIT>" <EOL> git_server . push_file ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> foo_git . sync_branch ( branch ) <EOL> assert foo_git . get_current_branch ( ) == "<STR_LIT>" <EOL> assert foo_git . read_file ( "<STR_LIT>" ) == "<STR_LIT>" <EOL> def test_rebase_by_default ( git_server , tmpdir , test_git ) : <EOL> foo_git = create_foo ( git_server , tmpdir , test_git ) <EOL> branch = Branch ( ) <EOL> branch . name = "<STR_LIT>" <EOL> branch . tracks = "<STR_LIT>" <EOL> git_server . push_file ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> foo_git . commit_file ( "<STR_LIT:bar>" , "<STR_LIT>" ) <EOL> foo_git . sync_branch ( branch ) <EOL> assert foo_git . get_current_branch ( ) == "<STR_LIT>" <EOL> assert foo_git . read_file ( "<STR_LIT>" ) == "<STR_LIT>" <EOL> assert foo_git . read_file ( "<STR_LIT:bar>" ) == "<STR_LIT>" <EOL> rc , head = foo_git . call ( "<STR_LIT>" , "<STR_LIT>" , raises = False ) <EOL> assert rc == <NUM_LIT:0> <EOL> assert "<STR_LIT>" not in head <EOL> def test_skip_if_unclean ( git_server , tmpdir , test_git ) : <EOL> foo_git = create_foo ( git_server , tmpdir , test_git ) <EOL> branch = Branch ( ) <EOL> branch . name = "<STR_LIT>" <EOL> branch . tracks = "<STR_LIT>" <EOL> git_server . push_file ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> foo_git . sync_branch ( branch ) <EOL> foo_git . root . join ( "<STR_LIT>" ) . write ( "<STR_LIT>" ) <EOL> ( res , message ) = foo_git . sync_branch ( branch ) <EOL> assert foo_git . read_file ( "<STR_LIT>" ) == "<STR_LIT>" <EOL> assert res is None <EOL> assert "<STR_LIT>" in message <EOL> def test_do_not_call_rebase_abort_when_reset_fails ( git_server , tmpdir , test_git ) : <EOL> foo_git = create_foo ( git_server , tmpdir , test_git ) <EOL> branch = Branch ( ) <EOL> branch . name = "<STR_LIT>" <EOL> branch . tracks = "<STR_LIT>" <EOL> git_server . push_file ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> foo_path = foo_git . repo <EOL> index_lock = os . path . join ( foo_path , "<STR_LIT>" , "<STR_LIT>" ) <EOL> with open ( index_lock , "<STR_LIT:w>" ) as fp : <EOL> fp . write ( "<STR_LIT>" ) <EOL> ( res , message ) = foo_git . sync_branch ( branch ) <EOL> assert res is False <EOL> assert "<STR_LIT>" not in message <EOL> def test_push_nonfastforward ( git_server , tmpdir , test_git ) : <EOL> foo_git = create_foo ( git_server , tmpdir , test_git ) <EOL> branch = Branch ( ) <EOL> branch . name = "<STR_LIT>" <EOL> branch . tracks = "<STR_LIT>" <EOL> git_server . push_file ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> foo_git . sync_branch ( branch ) <EOL> git_server . push_file ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> fast_forward = False ) <EOL> ( res , message ) = foo_git . sync_branch ( branch ) <EOL> assert res is True <EOL> assert foo_git . read_file ( "<STR_LIT>" ) == "<STR_LIT>" <EOL> def test_run_abort_when_rebase_fails ( git_server , tmpdir , test_git ) : <EOL> foo_git = create_foo ( git_server , tmpdir , test_git ) <EOL> branch = Branch ( ) <EOL> branch . name = "<STR_LIT>" <EOL> branch . tracks = "<STR_LIT>" <EOL> git_server . push_file ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> foo_git . sync_branch ( branch ) <EOL> git_server . push_file ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> fast_forward = False ) <EOL> foo_git . commit_file ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> ( res , message ) = foo_git . sync_branch ( branch ) <EOL> assert res is False <EOL> assert foo_git . get_current_branch ( ) is not None <EOL> assert "<STR_LIT>" in message <EOL> assert foo_git . read_file ( "<STR_LIT>" ) == "<STR_LIT>" <EOL> assert foo_git . read_file ( "<STR_LIT>" ) == "<STR_LIT>" <EOL> def test_fail_if_empty ( tmpdir , test_git ) : <EOL> foo_git = test_git ( tmpdir . strpath ) <EOL> branch = Branch ( ) <EOL> branch . name = "<STR_LIT>" <EOL> branch . tracks = "<STR_LIT>" <EOL> foo_git . set_tracking_branch ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> ( res , message ) = foo_git . sync_branch ( branch ) <EOL> assert res is None <EOL> assert "<STR_LIT>" in message <EOL> def test_clean_error_when_fetch_fails ( git_server , tmpdir , test_git ) : <EOL> foo_git = create_foo ( git_server , tmpdir , test_git ) <EOL> branch = Branch ( ) <EOL> branch . name = "<STR_LIT>" <EOL> branch . tracks = "<STR_LIT>" <EOL> git_server . push_file ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> git_server . srv . remove ( ) <EOL> res , message = foo_git . sync_branch ( branch ) <EOL> assert res is False <EOL> assert "<STR_LIT>" in message </s>
