Skip to content

Commit 50bb67b

Browse files
authored
fix(cli): improves UX around renku init (#1997)
* fix(cli): improves UX around renku init * add support for --initial-branch
1 parent 71befe0 commit 50bb67b

File tree

12 files changed

+325
-99
lines changed

12 files changed

+325
-99
lines changed

renku/cli/init.py

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -111,24 +111,56 @@
111111
~~~~~~~~~~~~~~~~~~~~~~~~~~
112112
113113
There are situations when the required structure of a Renku project needs
114-
to be recreated or you have an **existing** Git repository. You can solve
115-
these situation by simply adding the ``--force`` option.
114+
to be recreated or you have an **existing** Git repository for folder that
115+
you wish to turn into a Renku project. In these cases, Renku will warn you
116+
if there are any files that need to be overwritten. ``README.md`` and
117+
``README.rst`` will never be overwritten. ``.gitignore`` will be appended to
118+
to prevent files accidentally getting committed. Files that are not present
119+
in the template will be left untouched by the command.
116120
117121
.. code-block:: console
118122
119-
$ git init .
120123
$ echo "# Example\nThis is a README." > README.md
121-
$ git add README.md
122-
$ git commit -m 'Example readme file'
123-
# renku init would fail because there is a git repository
124-
$ renku init --force
124+
$ echo "FROM python:3.7-alpine" > Dockerfile
125+
$ renku init
126+
127+
INDEX ID PARAMETERS
128+
------- -------------- ------------
129+
1 python-minimal description
130+
2 R-minimal description
131+
3 bioc-minimal description
132+
4 julia-minimal description
133+
5 minimal
134+
Please choose a template by typing the index: 1
135+
The template requires a value for "description": Test Project
136+
Initializing Git repository...
137+
Warning: The following files exist in the directory and will be overwritten:
138+
Dockerfile
139+
Proceed? [y/N]: y
140+
Initializing new Renku repository...
141+
Initializing file .dockerignore ...
142+
Initializing file .gitignore ...
143+
Initializing file .gitlab-ci.yml ...
144+
Initializing file .renku/renku.ini ...
145+
Initializing file .renkulfsignore ...
146+
Overwriting file Dockerfile ...
147+
Initializing file data/.gitkeep ...
148+
Initializing file environment.yml ...
149+
Initializing file notebooks/.gitkeep ...
150+
Initializing file requirements.txt ...
151+
Project initialized.
152+
OK
153+
154+
If you initialize in an existing git repository, Renku will create a backup
155+
branch before overwriting any files and will print commands to revert the
156+
changes done and to see what changes were made.
125157
126158
You can also enable the external storage system for output files, if it
127159
was not installed previously.
128160
129161
.. code-block:: console
130162
131-
$ renku init --force --external-storage
163+
$ renku init --external-storage
132164
133165
"""
134166

@@ -142,7 +174,7 @@
142174

143175
from renku.cli.utils.callback import ClickCallback
144176
from renku.core import errors
145-
from renku.core.commands.init import init_command, is_path_empty
177+
from renku.core.commands.init import init_command
146178
from renku.core.commands.options import option_external_storage_requested
147179

148180
_GITLAB_CI = ".gitlab-ci.yml"
@@ -241,6 +273,7 @@ def check_git_user_config():
241273
@click.option("-l", "--list-templates", is_flag=True, help="List templates available in the template-source.")
242274
@click.option("-d", "--describe", is_flag=True, help="Show description for templates and parameters")
243275
@click.option("--force", is_flag=True, help="Override target path.")
276+
@click.option("--initial-branch", help="Initial git branch to create.")
244277
@option_external_storage_requested
245278
@click.pass_context
246279
def init(
@@ -257,18 +290,9 @@ def init(
257290
force,
258291
describe,
259292
data_dir,
293+
initial_branch,
260294
):
261295
"""Initialize a project in PATH. Default is the current path."""
262-
# verify dirty path
263-
if not is_path_empty(path) and not force and not list_templates:
264-
existing_paths = [str(p.relative_to(path)) for p in Path(path).iterdir()]
265-
existing_paths.sort()
266-
raise errors.InvalidFileOperation(
267-
f'Folder "{str(path)}" is not empty and contains the following files/directories:'
268-
+ "".join((f"\n\t{e}" for e in existing_paths))
269-
+ "\nPlease add --force flag to transform it into a Renku repository."
270-
)
271-
272296
data_dir = resolve_data_directory(data_dir, path)
273297

274298
if not check_git_user_config():
@@ -294,6 +318,7 @@ def init(
294318
force=force,
295319
describe=describe,
296320
data_dir=data_dir,
321+
initial_branch=initial_branch,
297322
)
298323

299324
if list_templates:

0 commit comments

Comments
 (0)