From 943dcef478a95b4fa324187512a517cc9ddc1ec7 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sat, 19 Sep 2020 15:06:07 +0900 Subject: [PATCH] Don't send a request when the contents haven't changed By doing this, the command will finish faster if the user canceled the editing. --- pkg/cmd/gist/edit/edit.go | 4 ++++ pkg/cmd/gist/edit/edit_test.go | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/pkg/cmd/gist/edit/edit.go b/pkg/cmd/gist/edit/edit.go index 554e9363d..566307b63 100644 --- a/pkg/cmd/gist/edit/edit.go +++ b/pkg/cmd/gist/edit/edit.go @@ -174,6 +174,10 @@ func editRun(opts *EditOptions) error { } } + if len(filesToUpdate) == 0 { + return nil + } + err = updateGist(client, ghinstance.OverridableDefault(), gist) if err != nil { return err diff --git a/pkg/cmd/gist/edit/edit_test.go b/pkg/cmd/gist/edit/edit_test.go index d7fffd958..623e2c825 100644 --- a/pkg/cmd/gist/edit/edit_test.go +++ b/pkg/cmd/gist/edit/edit_test.go @@ -177,6 +177,19 @@ func Test_editRun(t *testing.T) { }, }, }, + { + name: "not change", + gist: &shared.Gist{ + ID: "1234", + Files: map[string]*shared.GistFile{ + "cicada.txt": { + Filename: "cicada.txt", + Content: "new file content", + Type: "text/plain", + }, + }, + }, + }, } for _, tt := range tests {