Skip to content

Commit 35f40a1

Browse files
webknjazMariatta
authored andcommitted
Add support for default branch detection (GH-254)
* 🎨 Make config store default branch * πŸ“ Document default_branch in README * βœ…πŸ› Add test for default_branch config option
1 parent c1e26f9 commit 35f40a1

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

β€Žcherry_picker/cherry_picker/cherry_picker.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
'team': 'python',
2323
'repo': 'cpython',
2424
'check_sha': '7f777ed95a19224294949e1b4ce56bbffcb1fe9f',
25-
'fix_commit_msg': True
25+
'fix_commit_msg': True,
26+
'default_branch': 'master',
2627
})
2728

2829

@@ -135,9 +136,10 @@ def get_commit_message(self, commit_sha):
135136
else:
136137
return message
137138

138-
def checkout_master(self):
139-
""" git checkout master """
140-
cmd = ['git', 'checkout', 'master']
139+
def checkout_default_branch(self):
140+
""" git checkout default branch """
141+
142+
cmd = 'git', 'checkout', self.config['default_branch']
141143
self.run_cmd(cmd)
142144

143145
def status(self):
@@ -256,7 +258,7 @@ def delete_branch(self, branch):
256258
self.run_cmd(cmd)
257259

258260
def cleanup_branch(self, branch):
259-
self.checkout_master()
261+
self.checkout_default_branch()
260262
try:
261263
self.delete_branch(branch)
262264
except subprocess.CalledProcessError:

β€Žcherry_picker/cherry_picker/test.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,22 +194,26 @@ def test_find_config_not_found(tmpdir, cd):
194194
assert find_config() is None
195195

196196

197-
def test_load_config(tmpdir, cd):
197+
def test_load_full_config(tmpdir, cd):
198198
cd(tmpdir)
199199
subprocess.run('git init .'.split(), check=True)
200200
cfg = tmpdir.join('.cherry_picker.toml')
201201
cfg.write('''\
202202
team = "python"
203203
repo = "core-workfolow"
204204
check_sha = "5f007046b5d4766f971272a0cc99f8461215c1ec"
205+
default_branch = "devel"
205206
''')
206207
cfg = load_config(None)
207208
assert cfg == {'check_sha': '5f007046b5d4766f971272a0cc99f8461215c1ec',
208209
'repo': 'core-workfolow',
209-
'team': 'python'}
210+
'team': 'python',
211+
'fix_commit_msg': True,
212+
'default_branch': 'devel',
213+
}
210214

211215

212-
def test_load_config(tmpdir, cd):
216+
def test_load_partial_config(tmpdir, cd):
213217
cfg = tmpdir.join('.cherry_picker.toml')
214218
cfg.write('''\
215219
repo = "core-workfolow"
@@ -218,7 +222,9 @@ def test_load_config(tmpdir, cd):
218222
assert cfg == {'check_sha': '7f777ed95a19224294949e1b4ce56bbffcb1fe9f',
219223
'repo': 'core-workfolow',
220224
'team': 'python',
221-
'fix_commit_msg': True}
225+
'fix_commit_msg': True,
226+
'default_branch': 'master',
227+
}
222228

223229

224230
def test_normalize_long_commit_message():

β€Žcherry_picker/readme.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ Configuration file example::
110110
repo = "aiohttp"
111111
check_sha = "f382b5ffc445e45a110734f5396728da7914aeb6"
112112
fix_commit_msg = false
113+
default_branch = "devel"
113114

114115

115116
Available config options::
@@ -133,14 +134,18 @@ Available config options::
133134
on pull-request xxxx.
134135
For projects using GitHub Issues, this option can be disabled.
135136

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

137142
To customize the tool for used by other project:
138143

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

142-
2. Add ``team``, ``repo``, ``fix_commit_msg`` and ``check_sha``
143-
config values as described above.
147+
2. Add ``team``, ``repo``, ``fix_commit_msg``, ``check_sha`` and
148+
``default_branch`` config values as described above.
144149

145150
3. Use ``git add .cherry_picker.toml`` / ``git commit`` to add the config
146151
into ``git``.

0 commit comments

Comments
Β (0)