diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d39c42f..3cbaf2a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ Jupytext ChangeLog - Temporary text notebooks for the `--pipe` or `--check` commands are now created in the notebook directory ([#1206](https://github.com/mwouts/jupytext/issues/1206)) - Jupytext uses the standard library `tomllib` in Python 3.11, or `tomli` in Python 3.10 or older, to match JupyterLab's dependencies ([#1195](https://github.com/mwouts/jupytext/issues/1195)) - The dependencies of the JupyterLab extension were updated ([#1216](https://github.com/mwouts/jupytext/issues/1216), [#1218](https://github.com/mwouts/jupytext/issues/1218), [#1231](https://github.com/mwouts/jupytext/issues/1231)) +- `jupytext --sync` will not update the timestamp of text notebooks if their content is unchanged ([#1215](https://github.com/mwouts/jupytext/issues/1215)) **Fixed** diff --git a/src/jupytext/cli.py b/src/jupytext/cli.py index e8e253d1..f270b3fc 100644 --- a/src/jupytext/cli.py +++ b/src/jupytext/cli.py @@ -858,9 +858,18 @@ def lazy_write(path, fmt=None, action=None, update_timestamp_only=False): f"[jupytext] Setting the timestamp of {shlex.quote(path)} equal to that of {shlex.quote(nb_file)}" ) os.utime(path, (os.stat(path).st_atime, os.stat(nb_file).st_mtime)) - elif not modified and not path.endswith(".ipynb"): - log(f"[jupytext] Updating the timestamp of {shlex.quote(path)}") - os.utime(path, None) + elif not modified: + if path.endswith(".ipynb"): + # No need to update the timestamp of ipynb files + log(f"[jupytext] Unchanged {shlex.quote(path)}") + elif args.sync: + # if the content is unchanged (and matches ipynb), we don't need + # to update the timestamp as the contents manager will not throw in + # that case (see the try/catch on read_pair(... must_match=True)) + log(f"[jupytext] Unchanged {shlex.quote(path)}") + else: + log(f"[jupytext] Updating the timestamp of {shlex.quote(path)}") + os.utime(path, None) if args.pre_commit: system("git", "add", path)