Skip to content

Commit 56bddd0

Browse files
Jairo Llopisgithub-actions[bot]
Jairo Llopis
authored andcommitted
Remove --only-diff flag
This flag was not working fine, after all. Also, the only difference between `copier copy` and `copier update` is that copying should ignore subproject history, while updating should respect it. Thus, the real CLI reflection of the `only_diff` option is whether you're using `copier copy` or `copier update`. Well, that's how it is now. Besides all this, the real behavior of `only_diff=False` wasn't being tested. Fixed also, and updated docs. Fixes #270.
1 parent b479cb9 commit 56bddd0

File tree

4 files changed

+30
-13
lines changed

4 files changed

+30
-13
lines changed

copier/cli.py

+9-11
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ def main(self, *args: str) -> int:
231231
class CopierCopySubApp(cli.Application):
232232
"""The `copier copy` subcommand.
233233
234-
Use this subcommand to bootstrap a new subproject from a template.
234+
Use this subcommand to bootstrap a new subproject from a template, or to override
235+
a preexisting subproject ignoring its history diff.
235236
236237
Attributes:
237238
cleanup_on_error: Set [cleanup_on_error][] option.
@@ -259,7 +260,10 @@ def main(self, template_src: str, destination_path: str) -> int:
259260
Where to generate the new subproject. It must not exist or be empty.
260261
"""
261262
self.parent._copy(
262-
template_src, destination_path, cleanup_on_error=self.cleanup_on_error
263+
template_src,
264+
destination_path,
265+
cleanup_on_error=self.cleanup_on_error,
266+
only_diff=False,
263267
)
264268
return 0
265269

@@ -270,9 +274,6 @@ class CopierUpdateSubApp(cli.Application):
270274
271275
Use this subcommand to update an existing subproject from a template
272276
that supports updates.
273-
274-
Attributes:
275-
only_diff: Set [only_diff][] option.
276277
"""
277278

278279
DESCRIPTION = "Update a copy from its original template"
@@ -284,14 +285,11 @@ class CopierUpdateSubApp(cli.Application):
284285
285286
If that file contains also `_commit` and `destination_path` is a git
286287
repository, this command will do its best to respect the diff that you have
287-
generated since the last `copier` execution. To disable that, use `--no-diff`.
288+
generated since the last `copier` execution. To avoid that, use `copier copy`
289+
instead.
288290
"""
289291
)
290292

291-
only_diff: cli.Flag = cli.Flag(
292-
["-D", "--no-diff"], default=True, help="Disable smart diff detection."
293-
)
294-
295293
@handle_exceptions
296294
def main(self, destination_path: cli.ExistingDirectory = ".") -> int:
297295
"""Call [`copy`][copier.main.copy] in update mode.
@@ -305,7 +303,7 @@ def main(self, destination_path: cli.ExistingDirectory = ".") -> int:
305303
working directory is used.
306304
"""
307305
self.parent._copy(
308-
dst_path=destination_path, only_diff=self.only_diff,
306+
dst_path=destination_path, only_diff=True,
309307
)
310308
return 0
311309

copier/config/factory.py

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def make_config(
7070
quiet: OptBool = None,
7171
cleanup_on_error: OptBool = None,
7272
vcs_ref: OptStr = None,
73+
only_diff: OptBool = True,
7374
subdirectory: OptStr = None,
7475
use_prereleases: OptBool = False,
7576
**kwargs,

docs/configuring.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,7 @@ _min_copier_version: "4.1.0"
423423
### `only_diff`
424424

425425
- Format: `bool`
426-
- CLI flags: `-D`, `--no-diff` (used to disable this setting; only available in
427-
`copier update` subcommand)
426+
- CLI flags: Just use `copier copy` to disable it, or `copier update` to enable it.
428427
- Default value: `True`
429428

430429
When doing an update, by default Copier will do its best to understand how the template

tests/test_updatediff.py

+19
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,25 @@ def test_updatediff(tmpdir):
139139
Thanks for your grog.
140140
"""
141141
)
142+
commit("-m", "Subproject evolved")
143+
# Reapply template ignoring subproject evolution
144+
copy(
145+
data={"author_name": "Largo LaGrande", "project_name": "to steal a lot"},
146+
force=True,
147+
vcs_ref="HEAD",
148+
only_diff=False,
149+
)
150+
assert readme.read_text() == dedent(
151+
"""
152+
Let me introduce myself.
153+
154+
My name is Largo LaGrande.
155+
156+
My project is to steal a lot.
157+
158+
Thanks for your attention.
159+
"""
160+
)
142161

143162

144163
def test_commit_hooks_respected(tmp_path: Path):

0 commit comments

Comments
 (0)