<s> import os <EOL> import unittest <EOL> import gitpy <EOL> from gitpy . branch import LocalBranchAlias <EOL> from test_commits import CommittedRepositoryTest <EOL> class TestBranching ( CommittedRepositoryTest ) : <EOL> def testBranching ( self ) : <EOL> branch_name = '<STR_LIT>' <EOL> branch = self . repo . createBranch ( branch_name ) <EOL> self . assertTrue ( branch in self . repo . getBranches ( ) ) <EOL> self . assertEquals ( branch . name , branch_name ) <EOL> self . assertEquals ( branch . getHead ( ) , self . repo . getHead ( ) ) <EOL> return branch <EOL> def testBranchDeletion ( self ) : <EOL> branch = self . testBranching ( ) <EOL> branch . delete ( ) <EOL> def testBranchingAndCommitting ( self ) : <EOL> branch = self . testBranching ( ) <EOL> new_commit = self . commitSomeChange ( ) <EOL> self . assertEquals ( self . repo . getCommits ( branch , self . repo . getCurrentBranch ( ) ) , [ new_commit ] ) <EOL> self . assertNotEquals ( self . repo . getHead ( ) , branch . getHead ( ) ) <EOL> return branch <EOL> def testNewCommits ( self ) : <EOL> branch = self . testBranching ( ) <EOL> new_commit = self . commitSomeChange ( ) <EOL> new_commits = self . repo . getCurrentBranch ( ) . getNewCommits ( branch ) <EOL> self . assertEquals ( new_commits , [ new_commit ] ) <EOL> def testMerging1 ( self ) : <EOL> branch = self . testBranchingAndCommitting ( ) <EOL> prev_head = self . repo . getHead ( ) <EOL> self . repo . merge ( branch ) <EOL> self . assertNotEquals ( self . repo . getHead ( ) , branch . getHead ( ) ) <EOL> self . assertTrue ( branch . getHead ( ) in self . repo . getHead ( ) . getParents ( ) ) <EOL> def testMerging2 ( self ) : <EOL> branch = self . testBranching ( ) <EOL> self . repo . checkout ( branch ) <EOL> self . commitSomeChange ( ) <EOL> master_branch = [ b for b in self . repo . getBranches ( ) if b . name == '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> self . assertNotEquals ( branch . getHead ( ) , master_branch . getHead ( ) ) <EOL> self . repo . checkout ( master_branch ) <EOL> self . assertEquals ( self . repo . getHead ( ) , master_branch . getHead ( ) ) <EOL> self . assertNotEquals ( self . repo . getHead ( ) , branch . getHead ( ) ) <EOL> self . assertTrue ( self . repo . getHead ( ) in branch . getHead ( ) . getParents ( ) ) <EOL> self . repo . merge ( branch ) <EOL> self . assertEquals ( self . repo . getHead ( ) , branch . getHead ( ) ) <EOL> def testBranchAliasing ( self ) : <EOL> """<STR_LIT>""" <EOL> branch = self . repo . createBranch ( '<STR_LIT>' ) <EOL> with open ( os . path . join ( self . repo . path , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , "<STR_LIT:wb>" ) as alias_branch_file : <EOL> print >> alias_branch_file , "<STR_LIT>" <EOL> branch = self . repo . getBranchByName ( '<STR_LIT>' ) <EOL> self . failUnless ( isinstance ( branch , LocalBranchAlias ) ) <EOL> self . failUnless ( branch . name == '<STR_LIT>' ) <EOL> self . failUnless ( branch . dest == '<STR_LIT>' ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
