Changeset efc4f09 in rtems-tools for rtemstoolkit/git.py
- Timestamp:
- 12/09/15 09:08:19 (8 years ago)
- Branches:
- 4.10, 5, master
- Children:
- 8b49f73
- Parents:
- c9fa179
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
rtemstoolkit/git.py
rc9fa179 refc4f09 1 1 # 2 2 # RTEMS Tools Project (http://www.rtems.org/) 3 # Copyright 2010-201 4Chris Johns (chrisj@rtems.org)3 # Copyright 2010-2015 Chris Johns (chrisj@rtems.org) 4 4 # All rights reserved. 5 5 # 6 6 # This file is part of the RTEMS Tools package in 'rtems-tools'. 7 #8 # Redistribution and use in source and binary forms, with or without9 # modification, are permitted provided that the following conditions are met:10 7 # 11 8 # 1. Redistributions of source code must retain the above copyright notice, … … 62 59 return exit_code, output 63 60 64 def __init__(self, _path, opts , macros = None):61 def __init__(self, _path, opts = None, macros = None): 65 62 self.path = _path 66 63 self.opts = opts 67 if macros is None :64 if macros is None and opts is not None: 68 65 self.macros = opts.defaults 69 66 else: 70 67 self.macros = macros 71 self.git = self.macros.expand('%{__git}') 68 if self.macros is None: 69 self.git = 'git' 70 else: 71 self.git = self.macros.expand('%{__git}') 72 72 73 73 def git_version(self): … … 87 87 ec, output = self._run(['fetch'], check = True) 88 88 89 def merge(self): 90 ec, output = self._run(['merge'], check = True) 91 89 92 def pull(self): 90 93 ec, output = self._run(['pull'], check = True) … … 105 108 def checkout(self, branch = 'master'): 106 109 ec, output = self._run(['checkout', branch], check = True) 110 111 def submodule(self, module): 112 ec, output = self._run(['submodule', 'update', '--init', module], check = True) 113 114 def clean(self, args = []): 115 if type(args) == str: 116 args = [args] 117 ec, output = self._run(['clean'] + args, check = True) 107 118 108 119 def status(self): … … 113 124 state = 'none' 114 125 for l in output.split('\n'): 115 if l.startswith('# On branch '): 116 _status['branch'] = l[len('# On branch '):] 117 elif l.startswith('# Changes to be committed:'): 126 if l.startswith('# '): 127 l = l[2:] 128 if l.startswith('On branch '): 129 _status['branch'] = l[len('On branch '):] 130 elif l.startswith('Changes to be committed:'): 118 131 state = 'staged' 119 elif l.startswith(' #Changes not staged for commit:'):132 elif l.startswith('Changes not staged for commit:'): 120 133 state = 'unstaged' 121 elif l.startswith(' #Untracked files:'):134 elif l.startswith('Untracked files:'): 122 135 state = 'untracked' 123 elif state != 'none' and l[0] == '#': 124 if l.strip() != '#' and not l.startswith('# ('): 125 if state not in _status: 126 _status[state] = [] 127 l = l[1:] 128 if ':' in l: 129 l = l.split(':')[1] 130 _status[state] += [l.strip()] 136 elif l.startswith('HEAD detached'): 137 state = 'detached' 138 elif state != 'none' and len(l.strip()) != 0: 139 if l[0].isspace(): 140 l = l.strip() 141 if l[0] != '(': 142 if state not in _status: 143 _status[state] = [] 144 l = l[1:] 145 if ':' in l: 146 l = l.split(':')[1] 147 _status[state] += [l.strip()] 131 148 return _status 132 149 133 def clean(self):150 def dirty(self): 134 151 _status = self.status() 135 return len(_status) == 1 and 'branch' in _status152 return not (len(_status) == 1 and 'branch' in _status) 136 153 137 154 def valid(self):
Note: See TracChangeset
for help on using the changeset viewer.