1
+ # -*- coding: utf-8 -*-
1
2
"""Git-related utilities."""
2
3
3
- from __future__ import absolute_import
4
+ from __future__ import (
5
+ absolute_import , division , print_function , unicode_literals )
4
6
5
7
import csv
6
8
import logging
13
15
from readthedocs .projects .exceptions import RepositoryError
14
16
from readthedocs .vcs_support .base import BaseVCS , VCSVersion
15
17
16
-
17
18
log = logging .getLogger (__name__ )
18
19
19
20
@@ -39,9 +40,8 @@ def _get_clone_url(self):
39
40
clone_url = 'https://%s@%s' % (self .token , hacked_url )
40
41
return clone_url
41
42
# Don't edit URL because all hosts aren't the same
42
-
43
43
# else:
44
- # clone_url = 'git://%s' % (hacked_url)
44
+ # clone_url = 'git://%s' % (hacked_url)
45
45
return self .repo_url
46
46
47
47
def set_remote_url (self , url ):
@@ -69,22 +69,24 @@ def checkout_revision(self, revision=None):
69
69
branch = self .default_branch or self .fallback_branch
70
70
revision = 'origin/%s' % branch
71
71
72
- code , out , err = self .run (
73
- 'git' , 'checkout' , '--force' , revision )
72
+ code , out , err = self .run ('git' , 'checkout' , '--force' , revision )
74
73
if code != 0 :
75
- log .warning ("Failed to checkout revision '%s': %s" ,
76
- revision , code )
74
+ log .warning ("Failed to checkout revision '%s': %s" , revision , code )
77
75
return [code , out , err ]
78
76
79
77
def clone (self ):
80
- code , _ , _ = self .run (
81
- 'git' , 'clone' , '--recursive' , self .repo_url , '.' )
78
+ code , _ , _ = self .run ('git' , 'clone' , '--recursive' , self .repo_url , '.' )
82
79
if code != 0 :
83
80
raise RepositoryError
84
81
85
82
@property
86
83
def tags (self ):
87
- retcode , stdout , _ = self .run ('git' , 'show-ref' , '--tags' , record_as_success = True )
84
+ retcode , stdout , _ = self .run (
85
+ 'git' ,
86
+ 'show-ref' ,
87
+ '--tags' ,
88
+ record_as_success = True ,
89
+ )
88
90
# error (or no tags found)
89
91
if retcode != 0 :
90
92
return []
@@ -122,15 +124,20 @@ def parse_tags(self, data):
122
124
@property
123
125
def branches (self ):
124
126
# Only show remote branches
125
- retcode , stdout , _ = self .run ('git' , 'branch' , '-r' , record_as_success = True )
127
+ retcode , stdout , _ = self .run (
128
+ 'git' ,
129
+ 'branch' ,
130
+ '-r' ,
131
+ record_as_success = True ,
132
+ )
126
133
# error (or no branches found)
127
134
if retcode != 0 :
128
135
return []
129
136
return self .parse_branches (stdout )
130
137
131
138
def parse_branches (self , data ):
132
139
"""
133
- Parse output of git branch -r
140
+ Parse output of git branch -r.
134
141
135
142
e.g.:
136
143
@@ -155,7 +162,8 @@ def parse_branches(self, data):
155
162
verbose_name = branch .replace ('origin/' , '' )
156
163
if verbose_name in ['HEAD' ]:
157
164
continue
158
- clean_branches .append (VCSVersion (self , branch , verbose_name ))
165
+ clean_branches .append (
166
+ VCSVersion (self , branch , verbose_name ))
159
167
else :
160
168
clean_branches .append (VCSVersion (self , branch , branch ))
161
169
return clean_branches
@@ -193,8 +201,14 @@ def checkout(self, identifier=None):
193
201
# Update submodules
194
202
if self .submodules_exists ():
195
203
self .run ('git' , 'submodule' , 'sync' )
196
- self .run ('git' , 'submodule' , 'update' ,
197
- '--init' , '--recursive' , '--force' )
204
+ self .run (
205
+ 'git' ,
206
+ 'submodule' ,
207
+ 'update' ,
208
+ '--init' ,
209
+ '--recursive' ,
210
+ '--force' ,
211
+ )
198
212
199
213
return code , out , err
200
214
0 commit comments