From 5a6734f9e16e48438fbc1e2e512b287dc8a5c46b Mon Sep 17 00:00:00 2001 From: Taylor Blau Date: Mon, 16 Jul 2018 13:14:20 -0500 Subject: [PATCH] commands/command_migrate.go: print newline conditionally Sometimes when invoking 'git lfs migrate import', mysterious output like the following can be seen: $ git lfs migrate import migrate: override changes in your working copy? [Y/n] y migrate: changes in your working copy will be overridden ... migrate: Fetching remote refs: ..., done Where an extra newline is printed between the answer, 'y', and the next line of output from the migrator. Instead, let's only print that secondary newline when one isn't given in the answer. This should never be the case (c.f., ReadString()), but will harden the code to changes like opening /dev/tty in raw mode and reading character-by-character. To do so, ensure that the answer doesn't satisfy: strings.HasSuffix(answer, '\n') ...and print a newline iff it doesn't. In a related sense, ignore io.EOF errors. --- commands/command_migrate.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/commands/command_migrate.go b/commands/command_migrate.go index 72842a26..04f47e6a 100644 --- a/commands/command_migrate.go +++ b/commands/command_migrate.go @@ -319,13 +319,16 @@ func ensureWorkingCopyClean(in io.Reader, out io.Writer) { L: for { fmt.Fprintf(out, "migrate: override changes in your working copy? [Y/n] ") - s, _, err := answer.ReadLine() + s, err := answer.ReadString('\n') if err != nil { + if err == io.EOF { + break L + } ExitWithError(errors.Wrap(err, "fatal: could not read answer")) } - switch strings.TrimSpace(string(s)) { + switch strings.TrimSpace(s) { case "n", "N": proceed = false break L @@ -333,7 +336,10 @@ func ensureWorkingCopyClean(in io.Reader, out io.Writer) { proceed = true break L } - fmt.Fprintf(out, "\n") + + if !strings.HasSuffix(s, "\n") { + fmt.Fprintf(out, "\n") + } } }