-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(init): add --checkout option to sam init command for specifying git branch, tag, or commit for cookiecutter projects #9045
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
4b9e72a
6acc848
b30ba7a
ff0236c
d1319d7
be2ae19
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,7 @@ def generate_project( | |
| tracing=False, | ||
| application_insights=False, | ||
| structured_logging=False, | ||
| checkout=None, | ||
| ): | ||
| """Generates project using cookiecutter and options given | ||
|
|
||
|
|
@@ -74,6 +75,8 @@ def generate_project( | |
| Enable or disable AppInsights Monitoring | ||
| structured_logging: Optional[bool] | ||
| boolean value to determine if Json structured logging should be enabled or not | ||
| checkout: Optional[str] | ||
| Branch, tag or commit to checkout after git clone | ||
|
|
||
| Raises | ||
| ------ | ||
|
|
@@ -98,6 +101,9 @@ def generate_project( | |
| if extra_context: | ||
| params["extra_context"] = extra_context | ||
|
|
||
| if checkout: | ||
| params["checkout"] = checkout | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [BUG] The Flow:
project_output_dir = str(Path(output_dir, name)) if name else output_dir
generate_non_cookiecutter_project(location=params["template"], output_dir=project_output_dir)
elif repository.is_repo_url(location):
LOG.debug("%s location is a source control repository", location)
download_fn = functools.partial(repository.clone, repo_url=location, no_input=no_input)Result: a user running This was raised in the earlier automated review and has not been explicitly dismissed by the author. Please propagate |
||
|
|
||
| LOG.debug("Parameters dict created with input given") | ||
| LOG.debug("%s", params) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[BUG] The
--checkoutflag is silently ignored when the target repository does not contain acookiecutter.json. Cookiecutter clones the repo and applies the checkout, but then raisesRepositoryNotFound, which is caught below and dispatched togenerate_non_cookiecutter_project():generate_non_cookiecutter_project()insamcli/lib/init/arbitrary_project.pydoes not accept acheckoutparameter and callsrepository.clone(repo_url=location, no_input=no_input)without one. As a result, a user runningsam init --location <git-repo-without-cookiecutter.json> --checkout my-branchwill get code from the repository's default branch instead ofmy-branch, with no error or warning.Propagate
checkoutto the fallback path so the ref is honored consistently (cookiecutter'srepository.cloneaccepts acheckoutkwarg):…and update
generate_non_cookiecutter_projectto acceptcheckoutand forward it torepository.clone. It would also be worth adding a unit test that mocks cookiecutter to raiseRepositoryNotFoundand asserts the checkout is propagated to the fallback.