/stdhome

To get this branch, use:
bzr branch http://bzr.ed.am/stdhome

« back to all changes in this revision

Viewing changes to lib/stdhome/vcs/bzr.py

  • Committer: Tim Marston
  • Date: 2016-04-10 20:17:32 UTC
  • Revision ID: tim@ed.am-20160410201732-w6358gtt2df1y5e9
added 'ci' as an alias of add; fixed issue with lack of output from vcs when
there are merge conflicts

Show diffs side-by-side

added added

removed removed

34
34
 
35
35
                @param dir the fully-qualified directory to work in.
36
36
                """
 
37
 
37
38
                self.dir = dir
38
39
 
39
40
 
 
41
        def has_authority( self ):
 
42
                """Check that the directory is under this VCS's control.
 
43
                """
 
44
 
 
45
                return os.path.exists( os.path.join( self.dir, '.bzr' ) )
 
46
 
 
47
 
 
48
        def expand_repo_url( self, url ):
 
49
                """Convert a simple hostname in to an URL that the VCS can use.
 
50
                """
 
51
 
 
52
                return 'bzr+ssh://%s/%s/%s' % ( url, the.dir, the.repo.name )
 
53
 
 
54
 
40
55
        def init( self ):
41
56
                """Create a new, empty branch
42
57
                """
85
100
                """Obtain some sort of revision identifier
86
101
                """
87
102
 
88
 
                # bzr revert
 
103
                # bzr revno
89
104
                output = self.run( [ 'bzr', 'revno', '--tree' ] )
90
105
 
91
106
                # parse revno
108
123
                # symlink to a non-existant file)
109
124
                if 'kind changed' in files:
110
125
                        for file in files[ 'kind changed' ]:
111
 
                                matches = re.match( r'(.+?)[/@+]? \([^)]+\)', file )
 
126
                                matches = re.search( '^(.+?)[/@+]? \([^)]+\)$', file )
112
127
                                if not matches:
113
128
                                        raise RunTimeError(
114
129
                                                'failed to parse bzr kind change: %s' % file )
132
147
                # remove unknown files
133
148
                if 'unknown' in files:
134
149
                        for file in files[ 'unknown' ]:
 
150
                                matches = re.search( r'^(.+?)[/@+]?$', file )
 
151
                                if not matches:
 
152
                                        raise RunTimeError(
 
153
                                                'failed to parse bzr unknowns: %s' % file )
 
154
                                file = matches.group( 1 )
135
155
                                if the.verbose >= 2: print "removing (unknown): " + file
136
156
                                full_file = os.path.join( self.dir, file )
137
 
                                if os.path.isfile( full_file ):
 
157
                                if os.path.isfile( full_file ) or os.path.islink( full_file ):
138
158
                                        os.unlink( full_file )
139
159
                                elif os.path.isdir( full_file ):
140
160
                                        shutil.rmtree( full_file )
141
161
                                else:
142
162
                                        raise RuntimeError( 'exotic file in repo: %s' % file )
143
163
 
144
 
                # if a revision identifyer has been given, update to that
145
 
                if revno is not None:
 
164
                # if a revision identifier has been given, ensure we're updated to that
 
165
                if revno is not None and self.get_revno() != revno:
146
166
 
147
167
                        # bzr update
148
168
                        self.run( [ 'bzr', 'update', '-r', revno ] )
202
222
                for line in buf:
203
223
                        if not re.search( '^[-R+ ?][K NMD!][* ] ', line ): continue
204
224
                        line = line.rstrip()
205
 
                        if the.verbose >= 2: print '  %s' % line
206
225
 
207
226
                        # renames show before and after file names
208
227
                        matches = re.search( '^R.. (.*?)[/@+]? => (.*?)[/@+]?$', line )
253
272
                return files['conflicts'] if 'conflicts' in files else None
254
273
 
255
274
 
 
275
        def add( self, files ):
 
276
                """Make sure files are added to version control.
 
277
                @param files a list of relative filenames
 
278
                """
 
279
 
 
280
                # bzr add
 
281
                self.run( [ 'bzr', 'add', '-N' ] + files )
 
282
 
 
283
 
 
284
        def commit( self ):
 
285
                """Commit changes to the repo.
 
286
                """
 
287
 
 
288
                # bzr commit
 
289
                self.run( [ 'bzr', 'commit', '-m', '' ] )
 
290
 
 
291
 
256
292
        def run( self, cmd ):
257
293
                if the.verbose >= 2: print 'exec: %s' % ' '.join( cmd )
258
294
                p = Popen( cmd, cwd = self.dir,
260
296
                output = p.communicate()[ 0 ]
261
297
                if p.returncode > 0:
262
298
                        raise self.VcsError( ' '.join( cmd[ : 2 ] ), output )
 
299
                if the.verbose >= 2:
 
300
                        verbose_output = output.rstrip()
 
301
                        if len( verbose_output ):
 
302
                                print re.sub( '(^|\n)', '\\1  : ', verbose_output )
263
303
                return output
264
304
 
265
305