Skip to content
This repository was archived by the owner on Mar 13, 2024. It is now read-only.

Commit 7cabd68

Browse files
Add --from-branch cli arg
This will allow users to choose which skeleton branch they want to merge with their code. If they do not supply this argument, then main will be used by default.
1 parent 2932aa9 commit 7cabd68

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

src/python3_pip_skeleton/__main__.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def merge_skeleton(
5252
org: str,
5353
full_name: str,
5454
email: str,
55+
from_branch: str,
5556
package,
5657
):
5758
path = path.resolve()
@@ -82,7 +83,7 @@ def replace_text(text: str) -> str:
8283
# will do the wrong thing
8384
shutil.rmtree(git_tmp / "src", ignore_errors=True)
8485
# Merge in the skeleton commits
85-
git_tmp("pull", "--rebase=false", SKELETON, "main")
86+
git_tmp("pull", "--rebase=false", SKELETON, from_branch or "main")
8687
# Move things around
8788
if package != "python3_pip_skeleton":
8889
git_tmp("mv", "src/python3_pip_skeleton", f"src/{package}")
@@ -156,6 +157,7 @@ def new(args):
156157
org=args.org,
157158
full_name=args.full_name or git("config", "--get", "user.name").strip(),
158159
email=args.email or git("config", "--get", "user.email").strip(),
160+
from_branch=args.from_branch,
159161
package=package,
160162
)
161163

@@ -188,6 +190,7 @@ def existing(args):
188190
org=args.org,
189191
full_name=conf["metadata"]["author"],
190192
email=conf["metadata"]["author_email"],
193+
from_branch=args.from_branch,
191194
package=package,
192195
)
193196

@@ -225,6 +228,11 @@ def main(args=None):
225228
sub.add_argument(
226229
"--email", default=None, help="Email address, defaults to git config user.email"
227230
)
231+
sub.add_argument(
232+
"--from-branch",
233+
default=None,
234+
help="Merge from skeleton branch, defaults to main",
235+
)
228236
# Add a command for adopting in existing repo
229237
sub = subparsers.add_parser("existing", help="Adopt skeleton in existing repo")
230238
sub.set_defaults(func=existing)
@@ -234,6 +242,11 @@ def main(args=None):
234242
sub.add_argument(
235243
"--package", default=None, help="Package name, defaults to directory name"
236244
)
245+
sub.add_argument(
246+
"--from-branch",
247+
default=None,
248+
help="Merge from skeleton branch, defaults to main",
249+
)
237250
# Add a command for cleaning an existing repo of skeleton code
238251
sub = subparsers.add_parser(
239252
"clean", help="Clean up branch from failed skeleton merge"

tests/test_adopt.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,42 @@ def test_new_module_existing_dir(tmp_path: Path):
8989
assert "to not exist, or be an empty dir" in str(excinfo.value)
9090

9191

92+
def test_new_module_merge_from_valid_branch(tmp_path: Path):
93+
module = tmp_path / "my-module"
94+
check_output(
95+
sys.executable,
96+
"-m",
97+
"python3_pip_skeleton",
98+
"new",
99+
"--org=myorg",
100+
"--package=my_module",
101+
"--full-name=Firstname Lastname",
102+
103+
"--from-branch=main",
104+
str(module),
105+
)
106+
assert check_output("git", "branch", cwd=module).strip() == "* main"
107+
108+
109+
def test_new_module_merge_from_invalid_branch(tmp_path: Path):
110+
module = tmp_path / "my-module"
111+
112+
with pytest.raises(ValueError) as excinfo:
113+
check_output(
114+
sys.executable,
115+
"-m",
116+
"python3_pip_skeleton",
117+
"new",
118+
"--org=myorg",
119+
"--package=my_module",
120+
"--full-name=Firstname Lastname",
121+
122+
"--from-branch=fail",
123+
str(module),
124+
)
125+
assert "couldn't find remote ref fail" in str(excinfo.value)
126+
127+
92128
def test_existing_module(tmp_path: Path):
93129
module = tmp_path / "scanspec"
94130
__main__.git(
@@ -169,3 +205,27 @@ def test_existing_module_already_adopted(tmp_path: Path):
169205
str(module),
170206
)
171207
assert "already adopted skeleton" in str(excinfo.value)
208+
209+
210+
def test_existing_module_merge_from_invalid_branch(tmp_path: Path):
211+
module = tmp_path / "scanspec"
212+
__main__.git(
213+
"clone",
214+
"--depth",
215+
"1",
216+
"--branch",
217+
"0.5.3",
218+
"https://github.com/dls-controls/scanspec",
219+
str(module),
220+
)
221+
with pytest.raises(ValueError) as excinfo:
222+
check_output(
223+
sys.executable,
224+
"-m",
225+
"python3_pip_skeleton",
226+
"existing",
227+
"--org=epics-containers",
228+
"--from-branch=fail",
229+
str(module),
230+
)
231+
assert "couldn't find remote ref fail" in str(excinfo.value)

0 commit comments

Comments
 (0)