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

Public Member Functions

def __init__ (self, branch_name, commit_msg, upload=True, commit_queue=False, delete_when_finished=True, cc_list=None)
 
def __enter__ (self)
 
def commit_and_upload (self, use_commit_queue=False)
 
def __exit__ (self, exc_type, _value, _traceback)
 

Detailed Description

Class to manage git branches.

This class allows one to create a new branch in a repository to make changes,
then it commits the changes, switches to main branch, and deletes the
created temporary branch upon exit.

Definition at line 44 of file git_utils.py.

Constructor & Destructor Documentation

◆ __init__()

def git_utils.GitBranch.__init__ (   self,
  branch_name,
  commit_msg,
  upload = True,
  commit_queue = False,
  delete_when_finished = True,
  cc_list = None 
)

Definition at line 51 of file git_utils.py.

52 delete_when_finished=True, cc_list=None):
53 self._branch_name = branch_name
54 self._commit_msg = commit_msg
55 self._upload = upload
56 self._commit_queue = commit_queue
57 self._patch_set = 0
58 self._delete_when_finished = delete_when_finished
59 self._cc_list = cc_list
60

Member Function Documentation

◆ __enter__()

def git_utils.GitBranch.__enter__ (   self)

Definition at line 61 of file git_utils.py.

61 def __enter__(self):
62 subprocess.check_call(['git', 'reset', '--hard', 'HEAD'])
63 subprocess.check_call(['git', 'checkout', 'main'])
64 if self._branch_name in subprocess.check_output([
65 'git', 'branch']).decode('utf-8').split():
66 subprocess.check_call(['git', 'branch', '-D', self._branch_name])
67 subprocess.check_call(['git', 'checkout', '-b', self._branch_name,
68 '-t', 'origin/main'])
69 return self
70
static DecodeResult decode(std::string path)
Definition: png_codec.cpp:124

◆ __exit__()

def git_utils.GitBranch.__exit__ (   self,
  exc_type,
  _value,
  _traceback 
)

Definition at line 91 of file git_utils.py.

91 def __exit__(self, exc_type, _value, _traceback):
92 if self._upload:
93 # Only upload if no error occurred.
94 try:
95 if exc_type is None:
96 self.commit_and_upload(use_commit_queue=self._commit_queue)
97 finally:
98 subprocess.check_call(['git', 'checkout', 'main'])
99 if self._delete_when_finished:
100 subprocess.check_call(['git', 'branch', '-D', self._branch_name])
101
102

◆ commit_and_upload()

def git_utils.GitBranch.commit_and_upload (   self,
  use_commit_queue = False 
)
Commit all changes and upload a CL, returning the issue URL.

Definition at line 71 of file git_utils.py.

71 def commit_and_upload(self, use_commit_queue=False):
72 """Commit all changes and upload a CL, returning the issue URL."""
73 subprocess.check_call(['git', 'commit', '-a', '-m', self._commit_msg])
74 upload_cmd = ['git', 'cl', 'upload', '-f', '--bypass-hooks',
75 '--bypass-watchlists']
76 self._patch_set += 1
77 if self._patch_set > 1:
78 upload_cmd.extend(['-t', 'Patch set %d' % self._patch_set])
79 if use_commit_queue:
80 upload_cmd.append('--use-commit-queue')
81 # Need the --send-mail flag to publish the CL and remove WIP bit.
82 upload_cmd.append('--send-mail')
83 if self._cc_list:
84 upload_cmd.extend(['--cc=%s' % ','.join(self._cc_list)])
85 subprocess.check_call(upload_cmd)
86 output = subprocess.check_output([
87 'git', 'cl', 'issue']).decode('utf-8').rstrip()
88 return re.match('^Issue number: (?P<issue>\d+) \‍((?P<issue_url>.+)\‍)$',
89 output).group('issue_url')
90
static SkString join(const CommandLineFlags::StringArray &)
Definition: skpbench.cpp:741

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