2
2
from subprocess import Popen , PIPE
3
3
from unittest import TestCase , main
4
4
from shutil import rmtree
5
+ from os .path import join
6
+ from uuid import uuid4
5
7
6
8
from git import Repo
9
+ import bizarro
7
10
8
11
#
9
12
# Tarball of a single-commit Git repo with files index.md and sub/index.md
14
17
class TestRepo (TestCase ):
15
18
16
19
def setUp (self ):
17
- dirname = mkdtemp ()
20
+ dirname = mkdtemp (prefix = 'bizarro-' )
18
21
19
22
tar = Popen (('tar' , '-C' , dirname , '-xzf' , '-' ), stdin = PIPE )
20
23
tar .stdin .write (_tarball )
21
24
tar .stdin .close ()
22
25
tar .wait ()
23
26
24
- self .repo = Repo (dirname )
27
+ self .origin = Repo (dirname )
28
+ self .clone1 = self .origin .clone (mkdtemp (prefix = 'bizarro-' ))
29
+ self .clone2 = self .origin .clone (mkdtemp (prefix = 'bizarro-' ))
25
30
26
31
def test_repo_features (self ):
27
- self .assertTrue (self .repo .bare )
32
+ self .assertTrue (self .origin .bare )
28
33
29
- branch_names = [b .name for b in self .repo .branches ]
34
+ branch_names = [b .name for b in self .origin .branches ]
30
35
self .assertEqual (set (branch_names ), set (['master' , 'title' , 'body' ]))
31
36
37
+ def test_start_branch (self ):
38
+ branch1 = bizarro .repo .start_branch (self .clone1 , 'master' , 'hello' )
39
+
40
+ self .assertTrue ('hello' in self .clone1 .branches )
41
+ self .assertTrue ('hello' in self .origin .branches )
42
+
43
+ #
44
+ # Make a change to the branch and push it.
45
+ #
46
+ branch1 .checkout ()
47
+ message = str (uuid4 ())
48
+
49
+ with open (join (self .clone1 .working_dir , 'index.md' ), 'a' ) as file :
50
+ file .write ('\n \n ...' )
51
+
52
+ bizarro .repo .save_working_file (self .clone1 , 'index.md' , message , branch1 .commit .hexsha )
53
+
54
+ #
55
+ # See if the branch made it to clone 2
56
+ #
57
+ branch2 = bizarro .repo .start_branch (self .clone2 , 'master' , 'hello' )
58
+
59
+ self .assertTrue ('hello' in self .clone2 .branches )
60
+ self .assertEquals (branch2 .commit .hexsha , branch1 .commit .hexsha )
61
+ self .assertEquals (branch2 .commit .message , message )
62
+
32
63
def tearDown (self ):
33
- rmtree (self .repo .git_dir )
64
+ rmtree (self .origin .git_dir )
65
+ rmtree (self .clone1 .working_dir )
66
+ rmtree (self .clone2 .working_dir )
34
67
35
68
if __name__ == '__main__' :
36
69
main ()
0 commit comments