Skip to content

Commit

Permalink
Fix incorrect kart reset hint in status responses. #426
Browse files Browse the repository at this point in the history
  • Loading branch information
olsen232 committed May 13, 2021
1 parent 9b7b384 commit ae4cdad
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ _When adding new entries to the changelog, please include issue/PR numbers where
* Bugfix: GPKG spatial indexes are now created and deleted properly regardless of the case (upper-case or lower-case) of the table name and geometry column.
* `diff` now accepts `--only-feature-count`, which produces a feature count for the diff. The feature count can be exact or a fast estimate.
* `log` now accepts `--with-feature-count` which adds a feature count to each commit when used with `-o json`. The feature count can be exact or a fast estimate.
* Fix help text for discarding changes to refer to `kart restore` instead of `kart reset`, as `kart restore` is now the simplest way to discard changes. [#426](https://github.com/koordinates/kart/issues/426)

## 0.9.0 (First "Kart" release)

Expand Down
14 changes: 11 additions & 3 deletions kart/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ def _find_remote_branch_by_name(repo, name):
@click.argument("pathspec", nargs=-1)
def restore(ctx, source, pathspec):
"""
Restore specified paths in the working copy with some contents from a restore source.
Restore specified paths in the working copy with some contents from the given restore source.
By default, restores the entire working copy to the commit at HEAD (so, discards all uncommitted changes).
"""
repo = ctx.obj.repo

Expand Down Expand Up @@ -323,13 +324,20 @@ def restore(ctx, source, pathspec):
is_flag=True,
help="Discard local changes in working copy if necessary",
)
@click.argument("refish")
@click.argument("refish", default="HEAD")
def reset(ctx, discard_changes, refish):
"""
Reset the branch head to point to a different commit.
Reset the branch head to point to a particular commit.
Defaults to HEAD, which has no effect unless --discard-changes is also specified.
"""
repo = ctx.obj.repo

if refish == "HEAD" and not discard_changes:
raise InvalidOperation(
"Resetting the current branch to HEAD has no effect, unless you also discard changes.\n"
"Do you mean `kart reset --discard-changes?`"
)

try:
commit_or_tree, ref = repo.resolve_refish(refish)
commit = commit_or_tree.peel(pygit2.Commit)
Expand Down
2 changes: 1 addition & 1 deletion kart/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def working_copy_status_to_text(jdict):
return (
"Changes in working copy:\n"
' (use "kart commit" to commit)\n'
' (use "kart reset" to discard changes)\n\n'
' (use "kart restore" to discard changes)\n\n'
+ diff_status_to_text(jdict["changes"])
)

Expand Down
2 changes: 1 addition & 1 deletion kart/working_copy/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def tracking_changes_count(self, dataset=None):
def check_not_dirty(self, help_message=None):
"""Checks the working copy has no changes in it. Otherwise, raises InvalidOperation"""
if not help_message:
help_message = "Commit these changes (`kart commit`) or discard these changes (`kart reset`) first."
help_message = "Commit these changes (`kart commit`) or discard these changes (`kart restore`) first."
if self.is_dirty():
raise InvalidOperation(
f"You have uncommitted changes in your working copy.\n{help_message}"
Expand Down
2 changes: 1 addition & 1 deletion kart/working_copy/gpkg_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ def gpkg_metadata_to_xml(gpkg_metadata, gpkg_metadata_reference):

# We can't actually commit a whole list of XML, but we need to return something that makes sense.
# Simply throwing an error here stops dirty-detection working, and stops commands that would fix the situation
# from working, like `kart reset HEAD --discard-changes` or `kart create-workingcopy --discard-changes`.
# from working, like `kart reset --discard-changes` or `kart create-workingcopy --discard-changes`.
return xml_list


Expand Down
2 changes: 1 addition & 1 deletion tests/test_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def test_status(
"",
"Changes in working copy:",
' (use "kart commit" to commit)',
' (use "kart reset" to discard changes)',
' (use "kart restore" to discard changes)',
"",
f" {H.POINTS.LAYER}:",
" feature:",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_working_copy_gpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,8 @@ def test_working_copy_discard_changes(
assert r.exit_code == 0, r

elif via == "reset":
# using `kart reset HEAD --discard-changes`
r = cli_runner.invoke(["reset", "HEAD", "--discard-changes"])
# using `kart reset --discard-changes`
r = cli_runner.invoke(["reset", "--discard-changes"])
assert r.exit_code == 0, r

elif via == "checkout":
Expand Down
2 changes: 1 addition & 1 deletion tests/test_working_copy_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def test_commit_edits(
"",
"Changes in working copy:",
' (use "kart commit" to commit)',
' (use "kart reset" to discard changes)',
' (use "kart restore" to discard changes)',
"",
f" {table}:",
" feature:",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_working_copy_postgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def test_commit_edits(
"",
"Changes in working copy:",
' (use "kart commit" to commit)',
' (use "kart reset" to discard changes)',
' (use "kart restore" to discard changes)',
"",
f" {table}:",
" feature:",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_working_copy_sqlserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def test_commit_edits(
"",
"Changes in working copy:",
' (use "kart commit" to commit)',
' (use "kart reset" to discard changes)',
' (use "kart restore" to discard changes)',
"",
f" {table}:",
" feature:",
Expand Down

0 comments on commit ae4cdad

Please sign in to comment.