diff --git a/cherry_picker/cherry_picker/cherry_picker.py b/cherry_picker/cherry_picker/cherry_picker.py index ff046a4..f41aca5 100755 --- a/cherry_picker/cherry_picker/cherry_picker.py +++ b/cherry_picker/cherry_picker/cherry_picker.py @@ -21,7 +21,8 @@ 'team': 'python', 'repo': 'cpython', 'check_sha': '7f777ed95a19224294949e1b4ce56bbffcb1fe9f', - 'fix_commit_msg': True + 'fix_commit_msg': True, + 'default_branch': 'master', }) @@ -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): @@ -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: diff --git a/cherry_picker/cherry_picker/test.py b/cherry_picker/cherry_picker/test.py index 7ce83be..64293e8 100644 --- a/cherry_picker/cherry_picker/test.py +++ b/cherry_picker/cherry_picker/test.py @@ -178,7 +178,7 @@ 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') @@ -186,14 +186,18 @@ def test_load_config(tmpdir, cd): 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" @@ -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(): diff --git a/cherry_picker/readme.rst b/cherry_picker/readme.rst index e0d4a38..2e834af 100644 --- a/cherry_picker/readme.rst +++ b/cherry_picker/readme.rst @@ -103,6 +103,7 @@ Configuration file example:: repo = "aiohttp" check_sha = "f382b5ffc445e45a110734f5396728da7914aeb6" fix_commit_msg = false + default_branch = "devel" Available config options:: @@ -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``.