commands,t: make import default to saving work

We update the prompt to be more explicit when the import
(or export) migration commands notice a "dirty" working
tree with uncommitted changes, and we also revise the
default action in this case to be to exit early and
preserve the work in progress.

h/t bk2204 for the suggested revisions.
This commit is contained in:
Chris Darroch 2021-03-26 15:39:22 -07:00
parent 6ecabbfa34
commit 021a06ec55
2 changed files with 20 additions and 3 deletions

@ -331,7 +331,7 @@ func ensureWorkingCopyClean(in io.Reader, out io.Writer) {
answer := bufio.NewReader(in)
L:
for {
fmt.Fprintf(out, "migrate: override changes in your working copy? [Y/n] ")
fmt.Fprintf(out, "migrate: override changes in your working copy? All uncommitted changes will be lost! [y/N] ")
s, err := answer.ReadString('\n')
if err != nil {
if err == io.EOF {
@ -342,10 +342,10 @@ func ensureWorkingCopyClean(in io.Reader, out io.Writer) {
}
switch strings.TrimSpace(s) {
case "n", "N":
case "n", "N", "":
proceed = false
break L
case "y", "Y", "":
case "y", "Y":
proceed = true
break L
}

@ -875,6 +875,23 @@ begin_test "migrate import (multiple remotes)"
)
end_test
begin_test "migrate import (dirty copy, default negative answer)"
(
set -e
setup_local_branch_with_dirty_copy
original_main="$(git rev-parse main)"
echo | git lfs migrate import --everything 2>&1 | tee migrate.log
grep "migrate: working copy must not be dirty" migrate.log
migrated_main="$(git rev-parse main)"
assert_ref_unmoved "main" "$original_main" "$migrated_main"
)
end_test
begin_test "migrate import (dirty copy, negative answer)"
(
set -e