6"""This module contains functions for using git."""
18 """Class to manage local git configs."""
26 prev = subprocess.check_output([
27 'git',
'config',
'--local', k]).
decode(
'utf-8').rstrip()
30 except subprocess.CalledProcessError:
33 subprocess.check_call([
'git',
'config',
'--local', k, v])
35 def __exit__(self, exc_type, _value, _traceback):
38 subprocess.check_call(
41 subprocess.check_call([
'git',
'config',
'--local',
'--unset', k])
45 """Class to manage git branches.
47 This class allows one to
create a new branch in
a repository to
make changes,
48 then it commits the changes, switches to main branch,
and deletes the
49 created temporary branch upon exit.
51 def __init__(self, branch_name, commit_msg, upload=True, commit_queue=False,
52 delete_when_finished=True, cc_list=None):
62 subprocess.check_call([
'git',
'reset',
'--hard',
'HEAD'])
63 subprocess.check_call([
'git',
'checkout',
'main'])
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,
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']
78 upload_cmd.extend([
'-t',
'Patch set %d' % self.
_patch_set])
80 upload_cmd.append(
'--use-commit-queue')
82 upload_cmd.append(
'--send-mail')
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')
91 def __exit__(self, exc_type, _value, _traceback):
98 subprocess.check_call([
'git',
'checkout',
'main'])
100 subprocess.check_call([
'git',
'branch',
'-D', self.
_branch_name])
104 """Creates a new local checkout of a Git repository."""
107 """Set parameters for this local copy of a Git repository.
109 Because this is a new checkout, rather than a reference to an existing
110 checkout on disk, it
is safe to assume that the calling thread
is the
111 only thread manipulating the checkout.
113 You must use the
'with' statement to create this object:
120 repository: URL of the remote repository (e.g.,
121 'https://skia.googlesource.com/common')
or path to a local repository
122 (e.g.,
'/path/to/repo/.git') to check out a copy of
123 local: optional path to an existing copy of the remote repo on local disk.
124 If provided, the initial clone
is performed
with the local copy
as the
125 upstream, then the upstream
is switched to the remote repo
and the
126 new copy
is updated
from there.
128 super(NewGitCheckout, self).__init__()
139 """Returns the root directory containing the checked-out files."""
143 """Check out a new local copy of the repository.
145 Uses the parameters that were passed into the constructor.
151 subprocess.check_call([
'git',
'clone', remote])
152 repo_name = remote.split(
'/')[-1]
153 if repo_name.endswith(
'.git'):
154 repo_name = repo_name[:-
len(
'.git')]
158 subprocess.check_call([
159 'git',
'remote',
'set-url',
'origin', self.
_repository])
160 subprocess.check_call([
'git',
'remote',
'update'])
161 subprocess.check_call([
'git',
'checkout',
'main'])
162 subprocess.check_call([
'git',
'reset',
'--hard',
'origin/main'])
def commit_and_upload(self, use_commit_queue=False)
def __exit__(self, exc_type, _value, _traceback)
def __init__(self, branch_name, commit_msg, upload=True, commit_queue=False, delete_when_finished=True, cc_list=None)
def __exit__(self, exc_type, _value, _traceback)
def __init__(self, config_dict)
def __init__(self, repository, local=None)
const myers::Point & get(const myers::Segment &)
static void make(SkBitmap *bitmap, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace)
static DecodeResult decode(std::string path)
static SkString join(const CommandLineFlags::StringArray &)