Skip to content
12 changes: 7 additions & 5 deletions cherry_picker/cherry_picker/cherry_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
'team': 'python',
'repo': 'cpython',
'check_sha': '7f777ed95a19224294949e1b4ce56bbffcb1fe9f',
'fix_commit_msg': True
'fix_commit_msg': True,
'default_branch': 'master',
})


Expand Down Expand Up @@ -128,9 +129,10 @@ def get_commit_message(self, commit_sha):
else:
return message

def checkout_master(self):
""" git checkout master """
cmd = ['git', 'checkout', 'master']
def checkout_default_branch(self):
""" git checkout default branch """

cmd = 'git', 'checkout', self.config['default_branch']
self.run_cmd(cmd)

def status(self):
Expand Down Expand Up @@ -249,7 +251,7 @@ def delete_branch(self, branch):
self.run_cmd(cmd)

def cleanup_branch(self, branch):
self.checkout_master()
self.checkout_default_branch()
try:
self.delete_branch(branch)
except subprocess.CalledProcessError:
Expand Down
14 changes: 10 additions & 4 deletions cherry_picker/cherry_picker/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,22 +178,26 @@ def test_find_config_not_found(tmpdir, cd):
assert find_config() is None


def test_load_config(tmpdir, cd):
def test_load_full_config(tmpdir, cd):
cd(tmpdir)
subprocess.run('git init .'.split(), check=True)
cfg = tmpdir.join('.cherry_picker.toml')
cfg.write('''\
team = "python"
repo = "core-workfolow"
check_sha = "5f007046b5d4766f971272a0cc99f8461215c1ec"
default_branch = "devel"
''')
cfg = load_config(None)
assert cfg == {'check_sha': '5f007046b5d4766f971272a0cc99f8461215c1ec',
'repo': 'core-workfolow',
'team': 'python'}
'team': 'python',
'fix_commit_msg': True,
'default_branch': 'devel',
}


def test_load_config(tmpdir, cd):
def test_load_partial_config(tmpdir, cd):
cfg = tmpdir.join('.cherry_picker.toml')
cfg.write('''\
repo = "core-workfolow"
Expand All @@ -202,7 +206,9 @@ def test_load_config(tmpdir, cd):
assert cfg == {'check_sha': '7f777ed95a19224294949e1b4ce56bbffcb1fe9f',
'repo': 'core-workfolow',
'team': 'python',
'fix_commit_msg': True}
'fix_commit_msg': True,
'default_branch': 'master',
}


def test_normalize_long_commit_message():
Expand Down
9 changes: 7 additions & 2 deletions cherry_picker/readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ Configuration file example::
repo = "aiohttp"
check_sha = "f382b5ffc445e45a110734f5396728da7914aeb6"
fix_commit_msg = false
default_branch = "devel"


Available config options::
Expand All @@ -126,14 +127,18 @@ Available config options::
on pull-request xxxx.
For projects using GitHub Issues, this option can be disabled.

repo Project's default branch name,
e.g "devel" for https://github.com/ansible/ansible
("master" by default)


To customize the tool for used by other project:

1. Create a file called ``.cherry_picker.toml`` in the project's root
folder (alongside with ``.git`` folder).

2. Add ``team``, ``repo``, ``fix_commit_msg`` and ``check_sha``
config values as described above.
2. Add ``team``, ``repo``, ``fix_commit_msg``, ``check_sha`` and
``default_branch`` config values as described above.

3. Use ``git add .cherry_picker.toml`` / ``git commit`` to add the config
into ``git``.
Expand Down