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.
This commit is contained in:
yuuji.yaginuma 2020-09-19 15:06:07 +09:00
parent 921a2993ab
commit 943dcef478
2 changed files with 17 additions and 0 deletions

View file

@ -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

View file

@ -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 {