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

Public Member Functions

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

Protected Attributes

 _branch_name
 
 _commit_msg
 
 _upload
 
 _commit_queue
 
 _patch_set
 
 _delete_when_finished
 
 _cc_list
 

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

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

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)

◆ __exit__()

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

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

Member Data Documentation

◆ _branch_name

git_utils.GitBranch._branch_name
protected

Definition at line 53 of file git_utils.py.

◆ _cc_list

git_utils.GitBranch._cc_list
protected

Definition at line 59 of file git_utils.py.

◆ _commit_msg

git_utils.GitBranch._commit_msg
protected

Definition at line 54 of file git_utils.py.

◆ _commit_queue

git_utils.GitBranch._commit_queue
protected

Definition at line 56 of file git_utils.py.

◆ _delete_when_finished

git_utils.GitBranch._delete_when_finished
protected

Definition at line 58 of file git_utils.py.

◆ _patch_set

git_utils.GitBranch._patch_set
protected

Definition at line 57 of file git_utils.py.

◆ _upload

git_utils.GitBranch._upload
protected

Definition at line 55 of file git_utils.py.


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