From 6da31a0c54caf0c05954ffe4b30fb73c86c0e342 Mon Sep 17 00:00:00 2001 From: Solipsis Date: Fri, 10 Mar 2023 21:11:39 -0800 Subject: [PATCH 01/14] Outline cHashToRefs creation into its own function --- go/cmd/dolt/commands/log.go | 93 ++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 43 deletions(-) diff --git a/go/cmd/dolt/commands/log.go b/go/cmd/dolt/commands/log.go index 6508c7b0c1..afdcd9aa2d 100644 --- a/go/cmd/dolt/commands/log.go +++ b/go/cmd/dolt/commands/log.go @@ -276,6 +276,54 @@ func getCommitSpec(commit string) (*doltdb.CommitSpec, error) { return cs, nil } +func getHashToRefs(ctx context.Context, dEnv *env.DoltEnv, decorationLevel string) (map[hash.Hash][]string, error) { + cHashToRefs := map[hash.Hash][]string{} + + // Get all branches + branches, err := dEnv.DoltDB.GetBranchesWithHashes(ctx) + if err != nil { + return cHashToRefs, fmt.Errorf(color.HiRedString("Fatal error: cannot get Branch information.")) + } + + for _, b := range branches { + refName := b.Ref.String() + if decorationLevel != "full" { + refName = b.Ref.GetPath() // trim out "refs/heads/" + } + refName = fmt.Sprintf("\033[32;1m%s\033[0m", refName) // branch names are bright green (32;1m) + cHashToRefs[b.Hash] = append(cHashToRefs[b.Hash], refName) + } + + // Get all remote branches + remotes, err := dEnv.DoltDB.GetRemotesWithHashes(ctx) + if err != nil { + return cHashToRefs, fmt.Errorf(color.HiRedString("Fatal error: cannot get Remotes information.")) + } + for _, r := range remotes { + refName := r.Ref.String() + if decorationLevel != "full" { + refName = r.Ref.GetPath() // trim out "refs/remotes/" + } + refName = fmt.Sprintf("\033[31;1m%s\033[0m", refName) // remote names are bright red (31;1m) + cHashToRefs[r.Hash] = append(cHashToRefs[r.Hash], refName) + } + + // Get all tags + tags, err := dEnv.DoltDB.GetTagsWithHashes(ctx) + if err != nil { + return cHashToRefs, fmt.Errorf(color.HiRedString("Fatal error: cannot get Tag information.")) + } + for _, t := range tags { + tagName := t.Tag.GetDoltRef().String() + if decorationLevel != "full" { + tagName = t.Tag.Name // trim out "refs/tags/" + } + tagName = fmt.Sprintf("\033[33;1mtag: %s\033[0m", tagName) // tags names are bright yellow (33;1m) + cHashToRefs[t.Hash] = append(cHashToRefs[t.Hash], tagName) + } + return cHashToRefs, nil +} + func logCommits(ctx context.Context, dEnv *env.DoltEnv, opts *logOpts) int { hashes := make([]hash.Hash, len(opts.commitSpecs)) @@ -295,51 +343,10 @@ func logCommits(ctx context.Context, dEnv *env.DoltEnv, opts *logOpts) int { hashes[i] = h } - cHashToRefs := map[hash.Hash][]string{} + cHashToRefs, err := getHashToRefs(ctx, dEnv, opts.decoration) - // Get all branches - branches, err := dEnv.DoltDB.GetBranchesWithHashes(ctx) if err != nil { - cli.PrintErrln(color.HiRedString("Fatal error: cannot get Branch information.")) - return 1 - } - for _, b := range branches { - refName := b.Ref.String() - if opts.decoration != "full" { - refName = b.Ref.GetPath() // trim out "refs/heads/" - } - refName = fmt.Sprintf("\033[32;1m%s\033[0m", refName) // branch names are bright green (32;1m) - cHashToRefs[b.Hash] = append(cHashToRefs[b.Hash], refName) - } - - // Get all remote branches - remotes, err := dEnv.DoltDB.GetRemotesWithHashes(ctx) - if err != nil { - cli.PrintErrln(color.HiRedString("Fatal error: cannot get Remotes information.")) - return 1 - } - for _, r := range remotes { - refName := r.Ref.String() - if opts.decoration != "full" { - refName = r.Ref.GetPath() // trim out "refs/remotes/" - } - refName = fmt.Sprintf("\033[31;1m%s\033[0m", refName) // remote names are bright red (31;1m) - cHashToRefs[r.Hash] = append(cHashToRefs[r.Hash], refName) - } - - // Get all tags - tags, err := dEnv.DoltDB.GetTagsWithHashes(ctx) - if err != nil { - cli.PrintErrln(color.HiRedString("Fatal error: cannot get Tag information.")) - return 1 - } - for _, t := range tags { - tagName := t.Tag.GetDoltRef().String() - if opts.decoration != "full" { - tagName = t.Tag.Name // trim out "refs/tags/" - } - tagName = fmt.Sprintf("\033[33;1mtag: %s\033[0m", tagName) // tags names are bright yellow (33;1m) - cHashToRefs[t.Hash] = append(cHashToRefs[t.Hash], tagName) + return handleErrAndExit(err) } matchFunc := func(c *doltdb.Commit) (bool, error) { From 8cf6d1069c68fc93d0eb8b705a289b94aaee9166 Mon Sep 17 00:00:00 2001 From: Solipsis Date: Sat, 11 Mar 2023 21:53:46 -0800 Subject: [PATCH 02/14] Outline PrintCommit function. --- go/cmd/dolt/commands/log.go | 70 ++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/go/cmd/dolt/commands/log.go b/go/cmd/dolt/commands/log.go index afdcd9aa2d..f631933443 100644 --- a/go/cmd/dolt/commands/log.go +++ b/go/cmd/dolt/commands/log.go @@ -576,41 +576,45 @@ func logCompact(pager *outputpager.Pager, opts *logOpts, commits []logNode) { } } +func PrintCommit(pager *outputpager.Pager, minParents int, showParents bool, decoration string, comm logNode) { + if len(comm.parentHashes) < minParents { + return + } + + chStr := comm.commitHash.String() + if showParents { + for _, h := range comm.parentHashes { + chStr += " " + h.String() + } + } + + // Write commit hash + pager.Writer.Write([]byte(fmt.Sprintf("\033[33mcommit %s \033[0m", chStr))) // Use Dim Yellow (33m) + + // Show decoration + if decoration != "no" { + logRefs(pager, comm) + } + + if len(comm.parentHashes) > 1 { + pager.Writer.Write([]byte(fmt.Sprintf("\nMerge:"))) + for _, h := range comm.parentHashes { + pager.Writer.Write([]byte(fmt.Sprintf(" " + h.String()))) + } + } + + pager.Writer.Write([]byte(fmt.Sprintf("\nAuthor: %s <%s>", comm.commitMeta.Name, comm.commitMeta.Email))) + + timeStr := comm.commitMeta.FormatTS() + pager.Writer.Write([]byte(fmt.Sprintf("\nDate: %s", timeStr))) + + formattedDesc := "\n\n\t" + strings.Replace(comm.commitMeta.Description, "\n", "\n\t", -1) + "\n\n" + pager.Writer.Write([]byte(fmt.Sprintf("%s", formattedDesc))) +} + func logDefault(pager *outputpager.Pager, opts *logOpts, commits []logNode) { for _, comm := range commits { - if len(comm.parentHashes) < opts.minParents { - return - } - - chStr := comm.commitHash.String() - if opts.showParents { - for _, h := range comm.parentHashes { - chStr += " " + h.String() - } - } - - // Write commit hash - pager.Writer.Write([]byte(fmt.Sprintf("\033[33mcommit %s \033[0m", chStr))) // Use Dim Yellow (33m) - - // Show decoration - if opts.decoration != "no" { - logRefs(pager, comm) - } - - if len(comm.parentHashes) > 1 { - pager.Writer.Write([]byte(fmt.Sprintf("\nMerge:"))) - for _, h := range comm.parentHashes { - pager.Writer.Write([]byte(fmt.Sprintf(" " + h.String()))) - } - } - - pager.Writer.Write([]byte(fmt.Sprintf("\nAuthor: %s <%s>", comm.commitMeta.Name, comm.commitMeta.Email))) - - timeStr := comm.commitMeta.FormatTS() - pager.Writer.Write([]byte(fmt.Sprintf("\nDate: %s", timeStr))) - - formattedDesc := "\n\n\t" + strings.Replace(comm.commitMeta.Description, "\n", "\n\t", -1) + "\n\n" - pager.Writer.Write([]byte(fmt.Sprintf("%s", formattedDesc))) + PrintCommit(pager, opts.minParents, opts.showParents, opts.decoration, comm) } } From a9d691d1403f71395dfb34bf6d34907383e6aa4e Mon Sep 17 00:00:00 2001 From: Solipsis Date: Sun, 12 Mar 2023 03:16:56 -0700 Subject: [PATCH 03/14] Add missing err check in dolt log --- go/cmd/dolt/commands/log.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/go/cmd/dolt/commands/log.go b/go/cmd/dolt/commands/log.go index f631933443..c91bf08f8c 100644 --- a/go/cmd/dolt/commands/log.go +++ b/go/cmd/dolt/commands/log.go @@ -386,6 +386,11 @@ func logCommits(ctx context.Context, dEnv *env.DoltEnv, opts *logOpts) int { headRef := dEnv.RepoStateReader().CWBHeadRef() cwbHash, err := dEnv.DoltDB.GetHashForRefStr(ctx, headRef.String()) + if err != nil { + cli.PrintErrln(err) + return 1 + } + var commitsInfo []logNode for _, comm := range commits { meta, mErr := comm.GetCommitMeta(ctx) From b16dc01ecee2eb6e1ddbac83ad2907dff96af2b4 Mon Sep 17 00:00:00 2001 From: Solipsis Date: Sun, 12 Mar 2023 03:17:12 -0700 Subject: [PATCH 04/14] Add `dolt show` event constant. --- .../eventsapi/v1alpha1/event_constants.pb.go | 52 ++++++++++--------- .../eventsapi/v1alpha1/event_constants.proto | 1 + 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/go/gen/proto/dolt/services/eventsapi/v1alpha1/event_constants.pb.go b/go/gen/proto/dolt/services/eventsapi/v1alpha1/event_constants.pb.go index 4fd60424b9..cd0519b4bb 100644 --- a/go/gen/proto/dolt/services/eventsapi/v1alpha1/event_constants.pb.go +++ b/go/gen/proto/dolt/services/eventsapi/v1alpha1/event_constants.pb.go @@ -16,8 +16,8 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.28.1 -// protoc v4.22.0 +// protoc-gen-go v1.29.0 +// protoc v4.22.2 // source: dolt/services/eventsapi/v1alpha1/event_constants.proto package eventsapi @@ -152,6 +152,7 @@ const ( ClientEventType_STASH_DROP ClientEventType = 58 ClientEventType_STASH_LIST ClientEventType = 59 ClientEventType_STASH_POP ClientEventType = 60 + ClientEventType_SHOW ClientEventType = 61 ) // Enum value maps for ClientEventType. @@ -218,6 +219,7 @@ var ( 58: "STASH_DROP", 59: "STASH_LIST", 60: "STASH_POP", + 61: "SHOW", } ClientEventType_value = map[string]int32{ "TYPE_UNSPECIFIED": 0, @@ -281,6 +283,7 @@ var ( "STASH_DROP": 58, "STASH_LIST": 59, "STASH_POP": 60, + "SHOW": 61, } ) @@ -468,7 +471,7 @@ var file_dolt_services_eventsapi_v1alpha1_event_constants_proto_rawDesc = []byte 0x52, 0x4d, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x09, 0x0a, 0x05, 0x4c, 0x49, 0x4e, 0x55, 0x58, 0x10, 0x01, 0x12, 0x0b, 0x0a, 0x07, 0x57, 0x49, 0x4e, 0x44, 0x4f, 0x57, 0x53, 0x10, 0x02, 0x12, 0x0a, 0x0a, 0x06, 0x44, 0x41, 0x52, 0x57, - 0x49, 0x4e, 0x10, 0x03, 0x2a, 0xe6, 0x07, 0x0a, 0x0f, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x45, + 0x49, 0x4e, 0x10, 0x03, 0x2a, 0xf0, 0x07, 0x0a, 0x0f, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70, 0x65, 0x12, 0x14, 0x0a, 0x10, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, 0x49, 0x4e, 0x49, 0x54, 0x10, 0x01, 0x12, 0x0a, 0x0a, 0x06, 0x53, 0x54, 0x41, 0x54, @@ -530,27 +533,28 @@ var file_dolt_services_eventsapi_v1alpha1_event_constants_proto_rawDesc = []byte 0x0b, 0x53, 0x54, 0x41, 0x53, 0x48, 0x5f, 0x43, 0x4c, 0x45, 0x41, 0x52, 0x10, 0x39, 0x12, 0x0e, 0x0a, 0x0a, 0x53, 0x54, 0x41, 0x53, 0x48, 0x5f, 0x44, 0x52, 0x4f, 0x50, 0x10, 0x3a, 0x12, 0x0e, 0x0a, 0x0a, 0x53, 0x54, 0x41, 0x53, 0x48, 0x5f, 0x4c, 0x49, 0x53, 0x54, 0x10, 0x3b, 0x12, 0x0d, - 0x0a, 0x09, 0x53, 0x54, 0x41, 0x53, 0x48, 0x5f, 0x50, 0x4f, 0x50, 0x10, 0x3c, 0x2a, 0x6a, 0x0a, - 0x08, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x49, 0x44, 0x12, 0x16, 0x0a, 0x12, 0x4d, 0x45, 0x54, - 0x52, 0x49, 0x43, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, - 0x00, 0x12, 0x14, 0x0a, 0x10, 0x42, 0x59, 0x54, 0x45, 0x53, 0x5f, 0x44, 0x4f, 0x57, 0x4e, 0x4c, - 0x4f, 0x41, 0x44, 0x45, 0x44, 0x10, 0x01, 0x12, 0x17, 0x0a, 0x13, 0x44, 0x4f, 0x57, 0x4e, 0x4c, - 0x4f, 0x41, 0x44, 0x5f, 0x4d, 0x53, 0x5f, 0x45, 0x4c, 0x41, 0x50, 0x53, 0x45, 0x44, 0x10, 0x02, - 0x12, 0x17, 0x0a, 0x13, 0x52, 0x45, 0x4d, 0x4f, 0x54, 0x45, 0x41, 0x50, 0x49, 0x5f, 0x52, 0x50, - 0x43, 0x5f, 0x45, 0x52, 0x52, 0x4f, 0x52, 0x10, 0x03, 0x2a, 0x45, 0x0a, 0x0b, 0x41, 0x74, 0x74, - 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x49, 0x44, 0x12, 0x19, 0x0a, 0x15, 0x41, 0x54, 0x54, 0x52, - 0x49, 0x42, 0x55, 0x54, 0x45, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, - 0x44, 0x10, 0x00, 0x12, 0x15, 0x0a, 0x11, 0x52, 0x45, 0x4d, 0x4f, 0x54, 0x45, 0x5f, 0x55, 0x52, - 0x4c, 0x5f, 0x53, 0x43, 0x48, 0x45, 0x4d, 0x45, 0x10, 0x02, 0x22, 0x04, 0x08, 0x01, 0x10, 0x01, - 0x2a, 0x2d, 0x0a, 0x05, 0x41, 0x70, 0x70, 0x49, 0x44, 0x12, 0x16, 0x0a, 0x12, 0x41, 0x50, 0x50, - 0x5f, 0x49, 0x44, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, - 0x00, 0x12, 0x0c, 0x0a, 0x08, 0x41, 0x50, 0x50, 0x5f, 0x44, 0x4f, 0x4c, 0x54, 0x10, 0x01, 0x42, - 0x51, 0x5a, 0x4f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x64, 0x6f, - 0x6c, 0x74, 0x68, 0x75, 0x62, 0x2f, 0x64, 0x6f, 0x6c, 0x74, 0x2f, 0x67, 0x6f, 0x2f, 0x67, 0x65, - 0x6e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x64, 0x6f, 0x6c, 0x74, 0x2f, 0x73, 0x65, 0x72, - 0x76, 0x69, 0x63, 0x65, 0x73, 0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x61, 0x70, 0x69, 0x2f, - 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x3b, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x61, - 0x70, 0x69, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x0a, 0x09, 0x53, 0x54, 0x41, 0x53, 0x48, 0x5f, 0x50, 0x4f, 0x50, 0x10, 0x3c, 0x12, 0x08, 0x0a, + 0x04, 0x53, 0x48, 0x4f, 0x57, 0x10, 0x3d, 0x2a, 0x6a, 0x0a, 0x08, 0x4d, 0x65, 0x74, 0x72, 0x69, + 0x63, 0x49, 0x44, 0x12, 0x16, 0x0a, 0x12, 0x4d, 0x45, 0x54, 0x52, 0x49, 0x43, 0x5f, 0x55, 0x4e, + 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x14, 0x0a, 0x10, 0x42, + 0x59, 0x54, 0x45, 0x53, 0x5f, 0x44, 0x4f, 0x57, 0x4e, 0x4c, 0x4f, 0x41, 0x44, 0x45, 0x44, 0x10, + 0x01, 0x12, 0x17, 0x0a, 0x13, 0x44, 0x4f, 0x57, 0x4e, 0x4c, 0x4f, 0x41, 0x44, 0x5f, 0x4d, 0x53, + 0x5f, 0x45, 0x4c, 0x41, 0x50, 0x53, 0x45, 0x44, 0x10, 0x02, 0x12, 0x17, 0x0a, 0x13, 0x52, 0x45, + 0x4d, 0x4f, 0x54, 0x45, 0x41, 0x50, 0x49, 0x5f, 0x52, 0x50, 0x43, 0x5f, 0x45, 0x52, 0x52, 0x4f, + 0x52, 0x10, 0x03, 0x2a, 0x45, 0x0a, 0x0b, 0x41, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, + 0x49, 0x44, 0x12, 0x19, 0x0a, 0x15, 0x41, 0x54, 0x54, 0x52, 0x49, 0x42, 0x55, 0x54, 0x45, 0x5f, + 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x15, 0x0a, + 0x11, 0x52, 0x45, 0x4d, 0x4f, 0x54, 0x45, 0x5f, 0x55, 0x52, 0x4c, 0x5f, 0x53, 0x43, 0x48, 0x45, + 0x4d, 0x45, 0x10, 0x02, 0x22, 0x04, 0x08, 0x01, 0x10, 0x01, 0x2a, 0x2d, 0x0a, 0x05, 0x41, 0x70, + 0x70, 0x49, 0x44, 0x12, 0x16, 0x0a, 0x12, 0x41, 0x50, 0x50, 0x5f, 0x49, 0x44, 0x5f, 0x55, 0x4e, + 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, 0x41, + 0x50, 0x50, 0x5f, 0x44, 0x4f, 0x4c, 0x54, 0x10, 0x01, 0x42, 0x51, 0x5a, 0x4f, 0x67, 0x69, 0x74, + 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x64, 0x6f, 0x6c, 0x74, 0x68, 0x75, 0x62, 0x2f, + 0x64, 0x6f, 0x6c, 0x74, 0x2f, 0x67, 0x6f, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x2f, 0x64, 0x6f, 0x6c, 0x74, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2f, + 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, + 0x61, 0x31, 0x3b, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x61, 0x70, 0x69, 0x62, 0x06, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/proto/dolt/services/eventsapi/v1alpha1/event_constants.proto b/proto/dolt/services/eventsapi/v1alpha1/event_constants.proto index f54edeff0d..3d9c9588e1 100644 --- a/proto/dolt/services/eventsapi/v1alpha1/event_constants.proto +++ b/proto/dolt/services/eventsapi/v1alpha1/event_constants.proto @@ -90,6 +90,7 @@ enum ClientEventType { STASH_DROP = 58; STASH_LIST = 59; STASH_POP = 60; + SHOW = 61; } enum MetricID { From 90bd2b00b2cc599361b821eecbd9cd9d7267624c Mon Sep 17 00:00:00 2001 From: Solipsis Date: Sun, 12 Mar 2023 03:18:47 -0700 Subject: [PATCH 05/14] Add initial `dolt show` implementation. --- go/cmd/dolt/commands/show.go | 183 +++++++++++++++++++++++++++++++++++ go/cmd/dolt/dolt.go | 1 + 2 files changed, 184 insertions(+) create mode 100644 go/cmd/dolt/commands/show.go diff --git a/go/cmd/dolt/commands/show.go b/go/cmd/dolt/commands/show.go new file mode 100644 index 0000000000..955434b428 --- /dev/null +++ b/go/cmd/dolt/commands/show.go @@ -0,0 +1,183 @@ +// Copyright 2023 Dolthub, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package commands + +import ( + "context" + "fmt" + + "github.com/fatih/color" + + "github.com/dolthub/dolt/go/cmd/dolt/cli" + "github.com/dolthub/dolt/go/cmd/dolt/errhand" + eventsapi "github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1" + "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" + "github.com/dolthub/dolt/go/libraries/doltcore/env" + "github.com/dolthub/dolt/go/libraries/utils/argparser" + "github.com/dolthub/dolt/go/store/util/outputpager" +) + +type showOpts struct { + showParents bool + decoration string + specRefs []string +} + +var showDocs = cli.CommandDocumentationContent{ + ShortDesc: `Show information about a specific commit`, + LongDesc: `Show information about a specific commit`, + Synopsis: []string{ + `[{{.LessThan}}revision{{.GreaterThan}}]`, + }, +} + +type ShowCmd struct{} + +// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command +func (cmd ShowCmd) Name() string { + return "show" +} + +// Description returns a description of the command +func (cmd ShowCmd) Description() string { + return "Show information about a specific commit." +} + +// EventType returns the type of the event to log +func (cmd ShowCmd) EventType() eventsapi.ClientEventType { + return eventsapi.ClientEventType_SHOW +} + +func (cmd ShowCmd) Docs() *cli.CommandDocumentation { + ap := cmd.ArgParser() + return cli.NewCommandDocumentation(showDocs, ap) +} + +func (cmd ShowCmd) ArgParser() *argparser.ArgParser { + ap := argparser.NewArgParser() + ap.SupportsFlag(cli.ParentsFlag, "", "Shows all parents of each commit in the log.") + ap.SupportsString(cli.DecorateFlag, "", "decorate_fmt", "Shows refs next to commits. Valid options are short, full, no, and auto") + return ap +} + +// Exec executes the command +func (cmd ShowCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int { + ap := cmd.ArgParser() + help, usage := cli.HelpAndUsagePrinters(cli.CommandDocsForCommandString(commandStr, showDocs, ap)) + apr := cli.ParseArgsOrDie(ap, args, help) + + opts, err := parseShowArgs(ctx, dEnv, apr) + if err != nil { + return HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage) + } + err = showCommits(ctx, dEnv, opts) + + if err != nil { + return handleErrAndExit(err) + } + + return 0 +} + +func parseShowArgs(ctx context.Context, dEnv *env.DoltEnv, apr *argparser.ArgParseResults) (*showOpts, error) { + + decorateOption := apr.GetValueOrDefault(cli.DecorateFlag, "auto") + switch decorateOption { + case "short", "full", "auto", "no": + default: + return nil, fmt.Errorf("fatal: invalid --decorate option: %s", decorateOption) + } + + return &showOpts{ + showParents: apr.Contains(cli.ParentsFlag), + decoration: decorateOption, + specRefs: apr.Args, + }, nil +} + +func showCommits(ctx context.Context, dEnv *env.DoltEnv, opts *showOpts) error { + if len(opts.specRefs) == 0 { + return showCommit(ctx, dEnv, opts, dEnv.RepoStateReader().CWBHeadSpec()) + } + + for _, specRef := range opts.specRefs { + commitSpec, err := getCommitSpec(specRef) + + if err != nil { + cli.PrintErrln(color.HiRedString("Fatal error: invalid commit spec %s", specRef)) + return err + } + + err = showCommit(ctx, dEnv, opts, commitSpec) + if err != nil { + return err + } + } + + return nil +} + +func showCommit(ctx context.Context, dEnv *env.DoltEnv, opts *showOpts, commitSpec *doltdb.CommitSpec) error { + + comm, err := dEnv.DoltDB.Resolve(ctx, commitSpec, dEnv.RepoStateReader().CWBHeadRef()) + + if err != nil { + cli.PrintErrln(color.HiRedString("Fatal error: cannot resolve commit spec.")) + return err + } + + cHashToRefs, err := getHashToRefs(ctx, dEnv, opts.decoration) + + if err != nil { + return err + } + + meta, mErr := comm.GetCommitMeta(ctx) + if mErr != nil { + cli.PrintErrln("error: failed to get commit metadata") + return err + } + pHashes, pErr := comm.ParentHashes(ctx) + if pErr != nil { + cli.PrintErrln("error: failed to get parent hashes") + return err + } + cmHash, cErr := comm.HashOf() + if cErr != nil { + cli.PrintErrln("error: failed to get commit hash") + return err + } + + headRef := dEnv.RepoStateReader().CWBHeadRef() + cwbHash, err := dEnv.DoltDB.GetHashForRefStr(ctx, headRef.String()) + + if err != nil { + return err + } + + cli.ExecuteWithStdioRestored(func() { + pager := outputpager.Start() + defer pager.Stop() + + PrintCommit(pager, 0, opts.showParents, opts.decoration, logNode{ + commitMeta: meta, + commitHash: cmHash, + parentHashes: pHashes, + branchNames: cHashToRefs[cmHash], + isHead: cmHash == *cwbHash}) + }) + + return nil +} diff --git a/go/cmd/dolt/dolt.go b/go/cmd/dolt/dolt.go index 7e85a83d44..5f524fd18b 100644 --- a/go/cmd/dolt/dolt.go +++ b/go/cmd/dolt/dolt.go @@ -75,6 +75,7 @@ var doltCommand = cli.NewSubCommandHandler("dolt", "it's git for data", []cli.Co sqlserver.SqlServerCmd{VersionStr: Version}, sqlserver.SqlClientCmd{VersionStr: Version}, commands.LogCmd{}, + commands.ShowCmd{}, commands.BranchCmd{}, commands.CheckoutCmd{}, commands.MergeCmd{}, From 4eff2e6ea9d77df2e3562911552ab55eafd72c4f Mon Sep 17 00:00:00 2001 From: Solipsis Date: Mon, 13 Mar 2023 12:19:44 -0700 Subject: [PATCH 06/14] Remove redundant call to HandleVErrAndExitCode --- go/cmd/dolt/commands/diff.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/go/cmd/dolt/commands/diff.go b/go/cmd/dolt/commands/diff.go index 0d414bf464..e784d7be99 100644 --- a/go/cmd/dolt/commands/diff.go +++ b/go/cmd/dolt/commands/diff.go @@ -170,9 +170,6 @@ func (cmd DiffCmd) Exec(ctx context.Context, commandStr string, args []string, d } verr = diffUserTables(ctx, dEnv, dArgs) - if verr != nil { - return HandleVErrAndExitCode(verr, usage) - } return HandleVErrAndExitCode(verr, usage) } From fb5eaf11ed7182253aecadb4241f1bbcc5cd28cb Mon Sep 17 00:00:00 2001 From: Solipsis Date: Mon, 13 Mar 2023 12:23:15 -0700 Subject: [PATCH 07/14] Factor out diffArgs's fields based on purpose. Using the diffArgs struct after it's been created is unchanged. But this will make it easier to do diffing in `dolt show` --- go/cmd/dolt/commands/diff.go | 101 +++++++++++++++++++++++------------ 1 file changed, 66 insertions(+), 35 deletions(-) diff --git a/go/cmd/dolt/commands/diff.go b/go/cmd/dolt/commands/diff.go index e784d7be99..91732eaa70 100644 --- a/go/cmd/dolt/commands/diff.go +++ b/go/cmd/dolt/commands/diff.go @@ -101,20 +101,28 @@ The {{.EmphasisLeft}}--diff-mode{{.EmphasisRight}} argument controls how modifie }, } -type diffArgs struct { +type diffDisplaySettings struct { diffParts diffPart diffOutput diffOutput diffMode diff.Mode - fromRoot *doltdb.RootValue - toRoot *doltdb.RootValue - fromRef string - toRef string - tableSet *set.StrSet limit int where string skinny bool } +type diffDatasets struct { + fromRoot *doltdb.RootValue + toRoot *doltdb.RootValue + fromRef string + toRef string +} + +type diffArgs struct { + *diffDisplaySettings + *diffDatasets + tableSet *set.StrSet +} + type DiffCmd struct{} // Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command @@ -190,69 +198,89 @@ func (cmd DiffCmd) validateArgs(apr *argparser.ArgParseResults) errhand.VerboseE return nil } -func parseDiffArgs(ctx context.Context, dEnv *env.DoltEnv, apr *argparser.ArgParseResults) (*diffArgs, error) { - dArgs := &diffArgs{} +func parseDiffDisplaySettings(ctx context.Context, dEnv *env.DoltEnv, apr *argparser.ArgParseResults) *diffDisplaySettings { + displaySettings := &diffDisplaySettings{} - dArgs.diffParts = SchemaAndDataDiff + displaySettings.diffParts = SchemaAndDataDiff if apr.Contains(DataFlag) && !apr.Contains(SchemaFlag) { - dArgs.diffParts = DataOnlyDiff + displaySettings.diffParts = DataOnlyDiff } else if apr.Contains(SchemaFlag) && !apr.Contains(DataFlag) { - dArgs.diffParts = SchemaOnlyDiff + displaySettings.diffParts = SchemaOnlyDiff } else if apr.Contains(StatFlag) { - dArgs.diffParts = Stat + displaySettings.diffParts = Stat } else if apr.Contains(SummaryFlag) { - dArgs.diffParts = Summary + displaySettings.diffParts = Summary } - dArgs.skinny = apr.Contains(SkinnyFlag) + displaySettings.skinny = apr.Contains(SkinnyFlag) f := apr.GetValueOrDefault(FormatFlag, "tabular") switch strings.ToLower(f) { case "tabular": - dArgs.diffOutput = TabularDiffOutput + displaySettings.diffOutput = TabularDiffOutput switch strings.ToLower(apr.GetValueOrDefault(DiffMode, "context")) { case "row": - dArgs.diffMode = diff.ModeRow + displaySettings.diffMode = diff.ModeRow case "line": - dArgs.diffMode = diff.ModeLine + displaySettings.diffMode = diff.ModeLine case "in-place": - dArgs.diffMode = diff.ModeInPlace + displaySettings.diffMode = diff.ModeInPlace case "context": - dArgs.diffMode = diff.ModeContext + displaySettings.diffMode = diff.ModeContext } case "sql": - dArgs.diffOutput = SQLDiffOutput + displaySettings.diffOutput = SQLDiffOutput case "json": - dArgs.diffOutput = JsonDiffOutput + displaySettings.diffOutput = JsonDiffOutput } - dArgs.limit, _ = apr.GetInt(limitParam) - dArgs.where = apr.GetValueOrDefault(whereParam, "") + displaySettings.limit, _ = apr.GetInt(limitParam) + displaySettings.where = apr.GetValueOrDefault(whereParam, "") + + return displaySettings +} + +func parseDiffArgs(ctx context.Context, dEnv *env.DoltEnv, apr *argparser.ArgParseResults) (*diffArgs, error) { + dArgs := &diffArgs{ + diffDisplaySettings: parseDiffDisplaySettings(ctx, dEnv, apr), + } tableNames, err := dArgs.applyDiffRoots(ctx, dEnv, apr.Args, apr.Contains(cli.CachedFlag), apr.Contains(MergeBase)) if err != nil { return nil, err } - dArgs.tableSet = set.NewStrSet(nil) + tableSet, err := parseDiffTableSet(ctx, dEnv, dArgs.diffDatasets, tableNames) + if err != nil { + return nil, err + } + + dArgs.tableSet = tableSet + + return dArgs, nil +} + +func parseDiffTableSet(ctx context.Context, dEnv *env.DoltEnv, datasets *diffDatasets, tableNames []string) (*set.StrSet, error) { + + tableSet := set.NewStrSet(nil) for _, tableName := range tableNames { // verify table args exist in at least one root - _, ok, err := dArgs.fromRoot.GetTable(ctx, tableName) + _, ok, err := datasets.fromRoot.GetTable(ctx, tableName) if err != nil { return nil, err } if ok { - dArgs.tableSet.Add(tableName) + tableSet.Add(tableName) continue } - _, ok, err = dArgs.toRoot.GetTable(ctx, tableName) + _, ok, err = datasets.toRoot.GetTable(ctx, tableName) if err != nil { return nil, err } if ok { - dArgs.tableSet.Add(tableName) + tableSet.Add(tableName) continue } if !ok { @@ -262,14 +290,14 @@ func parseDiffArgs(ctx context.Context, dEnv *env.DoltEnv, apr *argparser.ArgPar // if no tables or docs were specified as args, diff all tables and docs if len(tableNames) == 0 { - utn, err := doltdb.UnionTableNames(ctx, dArgs.fromRoot, dArgs.toRoot) + utn, err := doltdb.UnionTableNames(ctx, datasets.fromRoot, datasets.toRoot) if err != nil { return nil, err } - dArgs.tableSet.Add(utn...) + tableSet.Add(utn...) } - return dArgs, nil + return tableSet, nil } // applyDiffRoots applies the appropriate |from| and |to| root values to the receiver and returns the table names @@ -290,10 +318,13 @@ func (dArgs *diffArgs) applyDiffRoots(ctx context.Context, dEnv *env.DoltEnv, ar return nil, err } - dArgs.fromRoot = stagedRoot - dArgs.fromRef = doltdb.Staged - dArgs.toRoot = workingRoot - dArgs.toRef = doltdb.Working + dArgs.diffDatasets = &diffDatasets{ + fromRoot: stagedRoot, + fromRef: doltdb.Staged, + toRoot: workingRoot, + toRef: doltdb.Working, + } + if isCached { dArgs.fromRoot = headRoot dArgs.fromRef = "HEAD" From a3bc1d762853127396412191b88cf54c7fc7e042 Mon Sep 17 00:00:00 2001 From: Solipsis Date: Mon, 13 Mar 2023 12:24:47 -0700 Subject: [PATCH 08/14] Add display settings from `diff` to `show` --- go/cmd/dolt/commands/show.go | 39 +++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/go/cmd/dolt/commands/show.go b/go/cmd/dolt/commands/show.go index 955434b428..8740bbb3fe 100644 --- a/go/cmd/dolt/commands/show.go +++ b/go/cmd/dolt/commands/show.go @@ -17,6 +17,7 @@ package commands import ( "context" "fmt" + "strings" "github.com/fatih/color" @@ -33,6 +34,8 @@ type showOpts struct { showParents bool decoration string specRefs []string + + *diffDisplaySettings } var showDocs = cli.CommandDocumentationContent{ @@ -67,8 +70,22 @@ func (cmd ShowCmd) Docs() *cli.CommandDocumentation { func (cmd ShowCmd) ArgParser() *argparser.ArgParser { ap := argparser.NewArgParser() + // Flags inherited from Log ap.SupportsFlag(cli.ParentsFlag, "", "Shows all parents of each commit in the log.") ap.SupportsString(cli.DecorateFlag, "", "decorate_fmt", "Shows refs next to commits. Valid options are short, full, no, and auto") + + // Flags inherited from Diff + ap.SupportsFlag(DataFlag, "d", "Show only the data changes, do not show the schema changes (Both shown by default).") + ap.SupportsFlag(SchemaFlag, "s", "Show only the schema changes, do not show the data changes (Both shown by default).") + ap.SupportsFlag(StatFlag, "", "Show stats of data changes") + ap.SupportsFlag(SummaryFlag, "", "Show summary of data and schema changes") + ap.SupportsString(FormatFlag, "r", "result output format", "How to format diff output. Valid values are tabular, sql, json. Defaults to tabular.") + ap.SupportsString(whereParam, "", "column", "filters columns based on values in the diff. See {{.EmphasisLeft}}dolt diff --help{{.EmphasisRight}} for details.") + ap.SupportsInt(limitParam, "", "record_count", "limits to the first N diffs.") + ap.SupportsFlag(cli.CachedFlag, "c", "Show only the staged data changes.") + ap.SupportsFlag(SkinnyFlag, "sk", "Shows only primary key columns and any columns with data changes.") + ap.SupportsFlag(MergeBase, "", "Uses merge base of the first commit and second commit (or HEAD if not supplied) as the first commit") + ap.SupportsString(DiffMode, "", "diff mode", "Determines how to display modified rows with tabular output. Valid values are row, line, in-place, context. Defaults to context.") return ap } @@ -82,13 +99,29 @@ func (cmd ShowCmd) Exec(ctx context.Context, commandStr string, args []string, d if err != nil { return HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage) } + + opts.diffDisplaySettings = parseDiffDisplaySettings(ctx, dEnv, apr) + err = showCommits(ctx, dEnv, opts) - if err != nil { - return handleErrAndExit(err) + return handleErrAndExit(err) +} + +func (cmd ShowCmd) validateArgs(apr *argparser.ArgParseResults) errhand.VerboseError { + if apr.Contains(StatFlag) || apr.Contains(SummaryFlag) { + if apr.Contains(SchemaFlag) || apr.Contains(DataFlag) { + return errhand.BuildDError("invalid Arguments: --stat and --summary cannot be combined with --schema or --data").Build() + } } - return 0 + f, _ := apr.GetValue(FormatFlag) + switch strings.ToLower(f) { + case "tabular", "sql", "json", "": + default: + return errhand.BuildDError("invalid output format: %s", f).Build() + } + + return nil } func parseShowArgs(ctx context.Context, dEnv *env.DoltEnv, apr *argparser.ArgParseResults) (*showOpts, error) { From 53546b8b96dac39993bc720fa79c8efe78d3ec09 Mon Sep 17 00:00:00 2001 From: Solipsis Date: Mon, 13 Mar 2023 12:25:15 -0700 Subject: [PATCH 09/14] Print diff from previous commit in `dolt show` --- go/cmd/dolt/commands/show.go | 51 +++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/go/cmd/dolt/commands/show.go b/go/cmd/dolt/commands/show.go index 8740bbb3fe..6e1a9abc45 100644 --- a/go/cmd/dolt/commands/show.go +++ b/go/cmd/dolt/commands/show.go @@ -212,5 +212,54 @@ func showCommit(ctx context.Context, dEnv *env.DoltEnv, opts *showOpts, commitSp isHead: cmHash == *cwbHash}) }) - return nil + if comm.NumParents() == 0 { + return nil + } + + if comm.NumParents() > 1 { + return fmt.Errorf("Requested commit is a merge commit. 'dolt show' currently only supports viewing non-merge commits.") + } + + commitRoot, err := comm.GetRootValue(ctx) + if err != nil { + return err + } + + parent, err := comm.GetParent(ctx, 0) + if err != nil { + return err + } + + parentRoot, err := parent.GetRootValue(ctx) + if err != nil { + return err + } + + parentHash, err := parent.HashOf() + if err != nil { + return err + } + + datasets := &diffDatasets{ + fromRoot: parentRoot, + toRoot: commitRoot, + fromRef: parentHash.String(), + toRef: cmHash.String(), + } + + // An empty string will cause all tables to be printed. + var tableNames []string + + tableSet, err := parseDiffTableSet(ctx, dEnv, datasets, tableNames) + if err != nil { + return err + } + + dArgs := &diffArgs{ + diffDisplaySettings: opts.diffDisplaySettings, + diffDatasets: datasets, + tableSet: tableSet, + } + + return diffUserTables(ctx, dEnv, dArgs) } From 2eb99a47554f068e7b404039aee87b7023799cac Mon Sep 17 00:00:00 2001 From: Solipsis Date: Mon, 13 Mar 2023 15:57:17 -0700 Subject: [PATCH 10/14] Fix formatting in event_constants.proto --- proto/dolt/services/eventsapi/v1alpha1/event_constants.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proto/dolt/services/eventsapi/v1alpha1/event_constants.proto b/proto/dolt/services/eventsapi/v1alpha1/event_constants.proto index 3d9c9588e1..bc03a166fe 100644 --- a/proto/dolt/services/eventsapi/v1alpha1/event_constants.proto +++ b/proto/dolt/services/eventsapi/v1alpha1/event_constants.proto @@ -90,7 +90,7 @@ enum ClientEventType { STASH_DROP = 58; STASH_LIST = 59; STASH_POP = 60; - SHOW = 61; + SHOW = 61; } enum MetricID { From 99363fb121f7a74d8fd10a8430a6f1aa6f9d94cb Mon Sep 17 00:00:00 2001 From: Solipsis Date: Mon, 13 Mar 2023 15:57:26 -0700 Subject: [PATCH 11/14] Fix formatting in show.go --- go/cmd/dolt/commands/show.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/go/cmd/dolt/commands/show.go b/go/cmd/dolt/commands/show.go index 6e1a9abc45..faa3ec958f 100644 --- a/go/cmd/dolt/commands/show.go +++ b/go/cmd/dolt/commands/show.go @@ -48,7 +48,7 @@ var showDocs = cli.CommandDocumentationContent{ type ShowCmd struct{} -// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command +// Name returns the name of the Dolt cli command. This is what is used on the command line to invoke the command func (cmd ShowCmd) Name() string { return "show" } @@ -165,14 +165,12 @@ func showCommits(ctx context.Context, dEnv *env.DoltEnv, opts *showOpts) error { func showCommit(ctx context.Context, dEnv *env.DoltEnv, opts *showOpts, commitSpec *doltdb.CommitSpec) error { comm, err := dEnv.DoltDB.Resolve(ctx, commitSpec, dEnv.RepoStateReader().CWBHeadRef()) - if err != nil { cli.PrintErrln(color.HiRedString("Fatal error: cannot resolve commit spec.")) return err } cHashToRefs, err := getHashToRefs(ctx, dEnv, opts.decoration) - if err != nil { return err } @@ -195,7 +193,6 @@ func showCommit(ctx context.Context, dEnv *env.DoltEnv, opts *showOpts, commitSp headRef := dEnv.RepoStateReader().CWBHeadRef() cwbHash, err := dEnv.DoltDB.GetHashForRefStr(ctx, headRef.String()) - if err != nil { return err } From 28f6f26cdc11e20c6ed89f9e801b6d278032be0a Mon Sep 17 00:00:00 2001 From: solipsis-project <98993875+solipsis-project@users.noreply.github.com> Date: Wed, 15 Mar 2023 16:03:29 -0700 Subject: [PATCH 12/14] Update typo in go/cmd/dolt/commands/show.go Co-authored-by: Jason Fulghum --- go/cmd/dolt/commands/show.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/cmd/dolt/commands/show.go b/go/cmd/dolt/commands/show.go index 6e1a9abc45..10006e8d4f 100644 --- a/go/cmd/dolt/commands/show.go +++ b/go/cmd/dolt/commands/show.go @@ -48,7 +48,7 @@ var showDocs = cli.CommandDocumentationContent{ type ShowCmd struct{} -// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command +// Name returns the name of the Dolt cli command. This is what is used on the command line to invoke the command func (cmd ShowCmd) Name() string { return "show" } From 54647f7084332602c59ecea44b1644e673ba2f9f Mon Sep 17 00:00:00 2001 From: Solipsis Date: Mon, 20 Mar 2023 18:56:34 -0700 Subject: [PATCH 13/14] Add basic bats tests for dolt show. --- integration-tests/bats/show.bats | 86 ++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 integration-tests/bats/show.bats diff --git a/integration-tests/bats/show.bats b/integration-tests/bats/show.bats new file mode 100644 index 0000000000..d8bd50c8dd --- /dev/null +++ b/integration-tests/bats/show.bats @@ -0,0 +1,86 @@ +#!/usr/bin/env bats +load $BATS_TEST_DIRNAME/helper/common.bash + +setup() { + setup_common +} + +teardown() { + assert_feature_version + teardown_common +} + +@test "show: on initialized repo" { + run dolt show + [ "$status" -eq "0" ] + [[ "$output" =~ "Initialize data repository" ]] || false +} + +@test "show: log zero refs" { + dolt commit --allow-empty -m "Commit One" + dolt tag v1 + run dolt show + [ $status -eq 0 ] + [[ "$output" =~ "Commit One" ]] || false + [[ "$output" =~ "tag: v1" ]] || false + + dolt commit --allow-empty -m "Commit Two" + dolt tag v2 + run dolt show + [ $status -eq 0 ] + [[ "$output" =~ "Commit Two" ]] || false + [[ "$output" =~ "tag: v2" ]] || false +} + +@test "show: log one ref" { + dolt commit --allow-empty -m "Commit One" + dolt tag v1 + + dolt commit --allow-empty -m "Commit Two" + dolt tag v2 + + run dolt show v1 + [ $status -eq 0 ] + [[ "$output" =~ "Commit One" ]] || false + [[ "$output" =~ "tag: v1" ]] || false +} + +@test "show: log two refs" { + dolt commit --allow-empty -m "Commit One" + dolt tag v1 + + dolt commit --allow-empty -m "Commit Two" + dolt tag v2 + + run dolt show v1 v2 + [ $status -eq 0 ] + [[ "$output" =~ "Commit One" ]] || false + [[ "$output" =~ "tag: v1" ]] || false + [[ "$output" =~ "Commit Two" ]] || false + [[ "$output" =~ "tag: v2" ]] || false +} + +@test "show: log and diff" { + dolt sql -q "create table testtable (pk int PRIMARY KEY)" + dolt add . + dolt commit -m "commit: add table" + + run dolt show + [ $status -eq 0 ] + [[ "$output" =~ "commit: add table" ]] || false + [[ "$output" =~ "diff --dolt a/testtable b/testtable" ]] || false + [[ "$output" =~ "added table" ]] || false + [[ "$output" =~ "+CREATE TABLE \`testtable\` (" ]] || false + [[ "$output" =~ "+ \`pk\` int NOT NULL," ]] || false + [[ "$output" =~ "+ PRIMARY KEY (\`pk\`)" ]] || false + + dolt sql -q 'insert into testtable values (4)' + dolt add . + dolt commit -m "commit: add values" + + run dolt show + [ $status -eq 0 ] + [[ "$output" =~ "commit: add values" ]] || false + [[ "$output" =~ "| | pk |" ]] || false + [[ "$output" =~ "| + | 4 |" ]] || false +} \ No newline at end of file From 6cf83d11add276e33fff8f1925cfe39854a76c82 Mon Sep 17 00:00:00 2001 From: Jason Fulghum Date: Tue, 21 Mar 2023 18:57:07 -0700 Subject: [PATCH 14/14] Update integration-tests/bats/show.bats --- integration-tests/bats/show.bats | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/integration-tests/bats/show.bats b/integration-tests/bats/show.bats index d8bd50c8dd..d88c387685 100644 --- a/integration-tests/bats/show.bats +++ b/integration-tests/bats/show.bats @@ -78,9 +78,9 @@ teardown() { dolt add . dolt commit -m "commit: add values" - run dolt show - [ $status -eq 0 ] - [[ "$output" =~ "commit: add values" ]] || false - [[ "$output" =~ "| | pk |" ]] || false - [[ "$output" =~ "| + | 4 |" ]] || false + run dolt show + [ $status -eq 0 ] + [[ "$output" =~ "commit: add values" ]] || false + [[ "$output" =~ "| | pk |" ]] || false + [[ "$output" =~ "| + | 4 |" ]] || false } \ No newline at end of file