Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
utils.git_branch Class Reference
Inheritance diagram for utils.git_branch:

Public Member Functions

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

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__()

def 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__()

def 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)
Definition: png_codec.cpp:124

◆ __exit__()

def 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

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