@@ -77,6 +77,10 @@ def to_markdown(text):
7777
7878
7979def merge_pages ():
80+ if get_branch () != 'master' :
81+ print 'ERROR: Not on master'
82+ return 1
83+
8084 git = subprocess .Popen (['git' , 'status' ], stdout = subprocess .PIPE )
8185 result = git .communicate ()[0 ].strip ().split ('\n ' )
8286 if not result [- 1 ].startswith ('nothing to commit' ):
@@ -95,16 +99,14 @@ def merge_pages():
9599 shutil .copyfile ('html/index.html' , 'build/index.html' )
96100 print 'Files copied sucessfully'
97101
98- print 'Switching to gh-pages...'
99102 git = subprocess .Popen (['git' , 'checkout' , 'gh-pages' ],
100103 stdout = subprocess .PIPE )
101104
102- git = subprocess .Popen (['git' , 'branch' ], stdout = subprocess .PIPE )
103- print git .communicate ()
104- return 1
105- status = merge_git ()
105+ if get_branch () != 'gh-pages' :
106+ print 'ERROR: Failed to switch to gh-pages'
107+ return 1
106108
107- print 'Returning to master...'
109+ status = merge_git ()
108110 git = subprocess .Popen (['git' , 'checkout' , 'master' ],
109111 stdout = subprocess .PIPE )
110112
@@ -149,6 +151,14 @@ def merge():
149151 else :
150152 print 'Merge successful'
151153
154+ def get_branch ():
155+ git = subprocess .Popen (['git' , 'branch' ], stdout = subprocess .PIPE )
156+ branches = git .communicate ()[0 ].strip ().split ('\n ' )
157+ for i in branches :
158+ if i .startswith ('*' ):
159+ return i [1 :].strip ()
160+
161+ return None
152162
153163if __name__ == '__main__' :
154164 if len (sys .argv ) > 1 :
0 commit comments