Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
utils.git_branch Class Reference
Inheritance diagram for utils.git_branch:

Public Member Functions

 __init__ (self)
 
 __enter__ (self)
 
 __exit__ (self, exc_type, _value, _traceback)
 

Protected Attributes

 _branch
 
 _orig_branch
 
 _stashed
 

Detailed Description

Check out a temporary git branch.

On exit, deletes the branch and attempts to restore the original state.

Definition at line 82 of file utils.py.

Constructor & Destructor Documentation

◆ __init__()

utils.git_branch.__init__ (   self)

Definition at line 87 of file utils.py.

87 def __init__(self):
88 self._branch = None
89 self._orig_branch = None
90 self._stashed = False
91

Member Function Documentation

◆ __enter__()

utils.git_branch.__enter__ (   self)

Definition at line 92 of file utils.py.

92 def __enter__(self):
93 output = subprocess.check_output([GIT, 'stash']).decode('utf-8')
94 self._stashed = 'No local changes' not in output
95
96 # Get the original branch name or commit hash.
97 self._orig_branch = subprocess.check_output([
98 GIT, 'rev-parse', '--abbrev-ref', 'HEAD']).decode('utf-8').rstrip()
99 if self._orig_branch == 'HEAD':
100 self._orig_branch = subprocess.check_output([
101 GIT, 'rev-parse', 'HEAD']).decode('utf-8').rstrip()
102
103 # Check out a new branch, based at updated origin/main.
104 subprocess.check_call([GIT, 'fetch', 'origin'])
105 self._branch = '_tmp_%s' % uuid.uuid4()
106 subprocess.check_call([GIT, 'checkout', '-b', self._branch,
107 '-t', 'origin/main'])
108 return self
109
static DecodeResult decode(std::string path)

◆ __exit__()

utils.git_branch.__exit__ (   self,
  exc_type,
  _value,
  _traceback 
)

Definition at line 110 of file utils.py.

110 def __exit__(self, exc_type, _value, _traceback):
111 subprocess.check_call([GIT, 'reset', '--hard', 'HEAD'])
112 subprocess.check_call([GIT, 'checkout', self._orig_branch])
113 if self._stashed:
114 subprocess.check_call([GIT, 'stash', 'pop'])
115 subprocess.check_call([GIT, 'branch', '-D', self._branch])
116
117

Member Data Documentation

◆ _branch

utils.git_branch._branch
protected

Definition at line 88 of file utils.py.

◆ _orig_branch

utils.git_branch._orig_branch
protected

Definition at line 89 of file utils.py.

◆ _stashed

utils.git_branch._stashed
protected

Definition at line 90 of file utils.py.


The documentation for this class was generated from the following file: