mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-02 03:10:42 -05:00
add error message for failed to open commit editor
This commit is contained in:
@@ -18,13 +18,11 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
goisatty "github.com/mattn/go-isatty"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
goisatty "github.com/mattn/go-isatty"
|
||||
|
||||
"github.com/dolthub/dolt/go/cmd/dolt/cli"
|
||||
"github.com/dolthub/dolt/go/cmd/dolt/errhand"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/diff"
|
||||
@@ -37,6 +35,7 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/utils/iohelp"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/set"
|
||||
"github.com/dolthub/dolt/go/store/datas"
|
||||
"github.com/fatih/color"
|
||||
)
|
||||
|
||||
var commitDocs = cli.CommandDocumentationContent{
|
||||
@@ -286,13 +285,7 @@ func getCommitMessageFromEditor(ctx context.Context, dEnv *env.DoltEnv, suggeste
|
||||
return suggestedMsg, nil
|
||||
}
|
||||
|
||||
isTerminal := false
|
||||
cli.ExecuteWithStdioRestored(func() {
|
||||
if goisatty.IsTerminal(os.Stdout.Fd()) {
|
||||
isTerminal = true
|
||||
}
|
||||
})
|
||||
if !isTerminal {
|
||||
if !checkIsTerminal() {
|
||||
return suggestedMsg, nil
|
||||
}
|
||||
|
||||
@@ -322,12 +315,22 @@ func getCommitMessageFromEditor(ctx context.Context, dEnv *env.DoltEnv, suggeste
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
return "", fmt.Errorf("Failed to open commit editor")
|
||||
}
|
||||
|
||||
return finalMsg, nil
|
||||
}
|
||||
|
||||
func checkIsTerminal() bool {
|
||||
isTerminal := false
|
||||
cli.ExecuteWithStdioRestored(func() {
|
||||
if goisatty.IsTerminal(os.Stdout.Fd()) || os.Getenv("dolt_test_forceOpenEditor") == "1" {
|
||||
isTerminal = true
|
||||
}
|
||||
})
|
||||
return isTerminal
|
||||
}
|
||||
|
||||
func buildInitalCommitMsg(ctx context.Context, dEnv *env.DoltEnv, suggestedMsg string) (string, error) {
|
||||
initialNoColor := color.NoColor
|
||||
color.NoColor = true
|
||||
|
||||
@@ -47,18 +47,18 @@ func OpenCommitEditor(ed string, initialContents string) (string, error) {
|
||||
cmd.Stderr = os.Stderr
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
return "Failed to open editor", err
|
||||
return "", err
|
||||
}
|
||||
fmt.Printf("Waiting for command to finish.\n")
|
||||
err = cmd.Wait()
|
||||
if err != nil {
|
||||
return "Error returned by editor", err
|
||||
return "", err
|
||||
}
|
||||
|
||||
data, err := os.ReadFile(filename)
|
||||
|
||||
if err != nil {
|
||||
return "Failed to read file", err
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(data), nil
|
||||
|
||||
@@ -40,4 +40,15 @@ teardown() {
|
||||
run dolt ls
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "t2" ]] || false
|
||||
}
|
||||
|
||||
@test "commit: failed to open commit editor." {
|
||||
export EDITOR="foo"
|
||||
export dolt_test_forceOpenEditor="1"
|
||||
dolt sql -q "CREATE table t (pk int primary key);"
|
||||
dolt sql -q "INSERT INTO t VALUES (1);"
|
||||
dolt add t
|
||||
run dolt commit
|
||||
[ $status -eq 1 ]
|
||||
[[ "$output" =~ "Failed to open commit editor" ]] || false
|
||||
}
|
||||
@@ -997,14 +997,3 @@ SQL
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "2 tables changed, 3 rows added(+), 1 rows modified(*), 1 rows deleted(-)" ]] || false
|
||||
}
|
||||
|
||||
@test "merge: failed to open editor" {
|
||||
dolt config --add core.editor "vi --broken"
|
||||
dolt checkout -b merge_branch
|
||||
dolt SQL -q "INSERT INTO test1 values (0,1,2)"
|
||||
dolt add test1
|
||||
|
||||
run dolt commit
|
||||
[ $status -eq 1 ]
|
||||
[[ "$output" =~ "Failed to open editor" ]] || false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user