Repository: python/cherry-picker (language: python)

Issue:
Use the main branch by default.
After 2021-05-03, CPython's default branch will become `main`.
Since cherry-picker was designed for CPython initially, it would be great to use the `main` branch when backporting.


Others can configure the branch name using the ``default_branch`` config option, documented in https://github.com/python/cherry-picker#options




Discussion / hints:

Fix patch:
diff --git a/.travis.yml b/.travis.yml
index 467af9e..ab0b9d7 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,16 +4,22 @@ git:
   depth: false
 
 
-dist: xenial
+dist: focal
 cache: pip
 
 
 language: python
 python:
+- "3.9"
+- "3.8"
 - "3.7"
 - "3.6"
-- "nightly"  # currently, it's 3.8-dev
+- "nightly"  # currently, it's 3.10
 
+matrix:
+  allow_failures:
+    - python: "nightly"
+      dist: focal
 
 install:
 - python -m pip install --upgrade flit pip
diff --git a/cherry_picker/__init__.py b/cherry_picker/__init__.py
index 34837f2..f8cd9a5 100644
--- a/cherry_picker/__init__.py
+++ b/cherry_picker/__init__.py
@@ -1,2 +1,2 @@
-"""Backport CPython changes from master to maintenance branches."""
-__version__ = '1.3.3.dev1'
+"""Backport CPython changes from main to maintenance branches."""
+__version__ = "2.0.0.dev1"
diff --git a/cherry_picker/__main__.py b/cherry_picker/__main__.py
index 437561a..cc02b31 100644
--- a/cherry_picker/__main__.py
+++ b/cherry_picker/__main__.py
@@ -1,4 +1,4 @@
 from .cherry_picker import cherry_pick_cli
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     cherry_pick_cli()
diff --git a/cherry_picker/cherry_picker.py b/cherry_picker/cherry_picker.py
index 4f24e44..a14068c 100755
--- a/cherry_picker/cherry_picker.py
+++ b/cherry_picker/cherry_picker.py
@@ -25,7 +25,7 @@
         "repo": "cpython",
         "check_sha": "7f777ed95a19224294949e1b4ce56bbffcb1fe9f",
         "fix_commit_msg": True,
-        "default_branch": "master",
+        "default_branch": "main",
     }
 )
 
diff --git a/readme.rst b/readme.rst
index 00ad57f..ad95222 100644
--- a/readme.rst
+++ b/readme.rst
@@ -11,7 +11,7 @@ Usage (from a cloned CPython directory) ::
 About
 =====
 
-This tool is used to backport CPython changes from ``master`` into one or more
+This tool is used to backport CPython changes from ``main`` into one or more
 of the maintenance branches (``3.6``, ``3.5``, ``2.7``).
 
 ``cherry_picker`` can be configured to backport other projects with similar
@@ -76,10 +76,10 @@ Commit sha1
 -----------
 
 The commit sha1 for cherry-picking is the squashed commit that was merged to
-the ``master`` branch.  On the merged pull request, scroll to the bottom of the
+the ``main`` branch.  On the merged pull request, scroll to the bottom of the
 page.  Find the event that says something like::
 
-   <coredeveloper> merged commit <commit_sha1> into python:master <sometime> ago.
+   <coredeveloper> merged commit <commit_sha1> into python:main <sometime> ago.
 
 By following the link to ``<commit_sha1>``, you will get the full commit hash.
 Use the full commit hash for ``cherry_picker.py``.
@@ -136,7 +136,7 @@ Available config options::
 
    repo            Project's default branch name,
                    e.g "devel" for https://github.com/ansible/ansible
-                   ("master" by default)
+                   ("main" by default)
 
 
 To customize the tool for used by other project:
@@ -190,13 +190,13 @@ What this will do:
     (venv) $ git checkout -b backport-6de2b78-3.5 upstream/3.5
     (venv) $ git cherry-pick -x 6de2b7817f-some-commit-sha1-d064
     (venv) $ git push origin backport-6de2b78-3.5
-    (venv) $ git checkout master
+    (venv) $ git checkout main
     (venv) $ git branch -D backport-6de2b78-3.5
 
     (venv) $ git checkout -b backport-6de2b78-3.6 upstream/3.6
     (venv) $ git cherry-pick -x 6de2b7817f-some-commit-sha1-d064
     (venv) $ git push origin backport-6de2b78-3.6
-    (venv) $ git checkout master
+    (venv) $ git checkout main
     (venv) $ git branch -D backport-6de2b78-3.6
 
 In case of merge conflicts or errors, the following message will be displayed::
@@ -226,14 +226,14 @@ steps it would execute without actually executing any of them. For example::
     dry_run: git cherry-pick -x 1e32a1be4a1705e34011770026cb64ada2d340b5
     dry_run: git push pr backport-1e32a1b-3.6
     dry_run: Create new PR: https://github.com/python/cpython/compare/3.6...ncoghlan:backport-1e32a1b-3.6?expand=1
-    dry_run: git checkout master
+    dry_run: git checkout main
     dry_run: git branch -D backport-1e32a1b-3.6
     Now backporting '1e32a1be4a1705e34011770026cb64ada2d340b5' into '3.5'
     dry_run: git checkout -b backport-1e32a1b-3.5 origin/3.5
     dry_run: git cherry-pick -x 1e32a1be4a1705e34011770026cb64ada2d340b5
     dry_run: git push pr backport-1e32a1b-3.5
     dry_run: Create new PR: https://github.com/python/cpython/compare/3.5...ncoghlan:backport-1e32a1b-3.5?expand=1
-    dry_run: git checkout master
+    dry_run: git checkout main
     dry_run: git branch -D backport-1e32a1b-3.5
 
 `--pr-remote` option
@@ -291,7 +291,7 @@ The url of the pull request page looks similar to the following::
 Press the ``Create Pull Request`` button.
 
 Bedevere will then remove the ``needs backport to ...`` label from the original
-pull request against ``master``.
+pull request against ``main``.
 
 
 Running Tests
@@ -329,15 +329,17 @@ in the directory where ``pyproject.toml`` exists::
 .. |pypi status| image:: https://img.shields.io/pypi/v/cherry-picker.svg
    :target: https://pypi.org/project/cherry-picker/
 
-.. |travis status| image:: https://travis-ci.com/python/cherry-picker.svg?branch=master
+.. |travis status| image:: https://travis-ci.com/python/cherry-picker.svg?branch=main
    :target: https://travis-ci.com/python/cherry-picker
 
 Changelog
 =========
 
-1.3.3 (in development)
+2.0.0 (in development)
 ----------------------
 
+- Support the ``main`` branch by default. To use a different default branch,
+  please configure it in the ``.cherry-picker.toml`` file.
 
 1.3.2
 -----


Test patch:
diff --git a/cherry_picker/test.py b/cherry_picker/test.py
index 6dd5b76..983e053 100644
--- a/cherry_picker/test.py
+++ b/cherry_picker/test.py
@@ -52,7 +52,7 @@ def changedir(d):
 
 @pytest.fixture
 def git_init():
-    git_init_cmd = "git", "init", "."
+    git_init_cmd = "git", "init", "--initial-branch=main", "."
     return lambda: subprocess.run(git_init_cmd, check=True)
 
 
@@ -143,8 +143,8 @@ def test_get_base_branch_invalid(subprocess_check_output, cherry_pick_branch):
 
 @mock.patch("subprocess.check_output")
 def test_get_current_branch(subprocess_check_output):
-    subprocess_check_output.return_value = b"master"
-    assert get_current_branch() == "master"
+    subprocess_check_output.return_value = b"main"
+    assert get_current_branch() == "main"
 
 
 @mock.patch("subprocess.check_output")
@@ -368,7 +368,7 @@ def test_load_partial_config(tmp_git_repo_dir, git_add, git_commit):
             "repo": "core-workfolow",
             "team": "python",
             "fix_commit_msg": True,
-            "default_branch": "master",
+            "default_branch": "main",
         },
     )
 
@@ -608,7 +608,9 @@ def test_cherry_pick(tmp_git_repo_dir, git_add, git_branch, git_commit, git_chec
     cherry_picker.cherry_pick()
 
 
-def test_cherry_pick_fail(tmp_git_repo_dir,):
+def test_cherry_pick_fail(
+    tmp_git_repo_dir,
+):
     with mock.patch("cherry_picker.cherry_picker.validate_sha", return_value=True):
         cherry_picker = CherryPicker("origin", "xxx", [])
 
@@ -616,7 +618,9 @@ def test_cherry_pick_fail(tmp_git_repo_dir,):
         cherry_picker.cherry_pick()
 
 
-def test_get_state_and_verify_fail(tmp_git_repo_dir,):
+def test_get_state_and_verify_fail(
+    tmp_git_repo_dir,
+):
     class tested_state:
         name = "invalid_state"
 
@@ -648,7 +652,7 @@ def test_push_to_remote_fail(tmp_git_repo_dir):
     with mock.patch("cherry_picker.cherry_picker.validate_sha", return_value=True):
         cherry_picker = CherryPicker("origin", "xxx", [])
 
-    cherry_picker.push_to_remote("master", "backport-branch-test")
+    cherry_picker.push_to_remote("main", "backport-branch-test")
     assert get_state() == WORKFLOW_STATES.PUSHING_TO_REMOTE_FAILED
 
 
@@ -659,7 +663,7 @@ def test_push_to_remote_interactive(tmp_git_repo_dir):
     with mock.patch.object(cherry_picker, "run_cmd"), mock.patch.object(
         cherry_picker, "open_pr"
     ), mock.patch.object(cherry_picker, "get_pr_url", return_value="https://pr_url"):
-        cherry_picker.push_to_remote("master", "backport-branch-test")
+        cherry_picker.push_to_remote("main", "backport-branch-test")
     assert get_state() == WORKFLOW_STATES.PR_OPENING
 
 
@@ -671,7 +675,7 @@ def test_push_to_remote_botflow(tmp_git_repo_dir, monkeypatch):
     with mock.patch.object(cherry_picker, "run_cmd"), mock.patch.object(
         cherry_picker, "create_gh_pr"
     ):
-        cherry_picker.push_to_remote("master", "backport-branch-test")
+        cherry_picker.push_to_remote("main", "backport-branch-test")
     assert get_state() == WORKFLOW_STATES.PR_CREATING