From 09a660905081d74504a376d262a9886a150526d9 Mon Sep 17 00:00:00 2001 From: Christian Gregg Date: Thu, 9 Sep 2021 12:37:05 +0100 Subject: [PATCH] Show * after branch name if codespace working directory is dirty Append a `*` to the end of a branch name in `ghcs list` if the working directory of the codespace is dirty (has uncommited or unpushed changes). Closes: #104 --- api/api.go | 10 ++++++++++ cmd/ghcs/list.go | 17 ++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/api/api.go b/api/api.go index 7bb43811a..00844a422 100644 --- a/api/api.go +++ b/api/api.go @@ -124,6 +124,16 @@ type Codespace struct { type CodespaceEnvironment struct { State string `json:"state"` Connection CodespaceEnvironmentConnection `json:"connection"` + GitStatus CodespaceEnvironmentGitStatus `json:"gitStatus"` +} + +type CodespaceEnvironmentGitStatus struct { + Ahead int `json:"ahead"` + Behind int `json:"behind"` + Branch string `json:"branch"` + Commit string `json:"commit"` + HasUnpushedChanges bool `json:"hasUnpushedChanges"` + HasUncommitedChanges bool `json:"hasUncommitedChanges"` } const ( diff --git a/cmd/ghcs/list.go b/cmd/ghcs/list.go index c6075a988..ee26e3013 100644 --- a/cmd/ghcs/list.go +++ b/cmd/ghcs/list.go @@ -53,10 +53,25 @@ func list(opts *listOptions) error { table.SetHeader([]string{"Name", "Repository", "Branch", "State", "Created At"}) for _, codespace := range codespaces { table.Append([]string{ - codespace.Name, codespace.RepositoryNWO, codespace.Branch, codespace.Environment.State, codespace.CreatedAt, + codespace.Name, + codespace.RepositoryNWO, + branch(codespace), + codespace.Environment.State, + codespace.CreatedAt, }) } table.Render() return nil } + +func branch(codespace *api.Codespace) string { + name := codespace.Branch + gitStatus := codespace.Environment.GitStatus + + if gitStatus.HasUncommitedChanges || gitStatus.HasUnpushedChanges { + name += "*" + } + + return name +}