Skip to content

Commit

Permalink
Revert "add check for upstream branch"
Browse files Browse the repository at this point in the history
This reverts commit 9bff470.
  • Loading branch information
bryans-go committed Sep 20, 2024
1 parent 72e943e commit 904564d
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 126 deletions.
16 changes: 12 additions & 4 deletions internal/util/apiclient/conversion/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,15 @@ func ToGitStatus(gitStatusDTO apiclient.GitStatus) *project.GitStatus {
behind = int(*gitStatusDTO.Behind)
}

var branchPublished bool
if gitStatusDTO.BranchPublished != nil {
branchPublished = *gitStatusDTO.BranchPublished
}

return &project.GitStatus{
CurrentBranch: gitStatusDTO.CurrentBranch,
Files: files,
BranchPublished: *gitStatusDTO.BranchPublished,
UpstreamSet: *gitStatusDTO.UpstreamSet,
BranchPublished: branchPublished,
Ahead: ahead,
Behind: behind,
}
Expand Down Expand Up @@ -127,12 +131,16 @@ func ToGitStatusDTO(gitStatus *project.GitStatus) *apiclient.GitStatus {
value := int32(gitStatus.Behind)
behind = &value
}
var branchPublished *bool
if gitStatus.BranchPublished {
value := true
branchPublished = &value
}

return &apiclient.GitStatus{
CurrentBranch: gitStatus.CurrentBranch,
FileStatus: fileStatusDTO,
BranchPublished: &gitStatus.BranchPublished,
UpstreamSet: &gitStatus.UpstreamSet,
BranchPublished: branchPublished,
Ahead: ahead,
Behind: behind,
}
Expand Down
3 changes: 0 additions & 3 deletions pkg/api/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2233,9 +2233,6 @@ const docTemplate = `{
"items": {
"$ref": "#/definitions/FileStatus"
}
},
"upstreamSet": {
"type": "boolean"
}
}
},
Expand Down
3 changes: 0 additions & 3 deletions pkg/api/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2230,9 +2230,6 @@
"items": {
"$ref": "#/definitions/FileStatus"
}
},
"upstreamSet": {
"type": "boolean"
}
}
},
Expand Down
2 changes: 0 additions & 2 deletions pkg/api/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,6 @@ definitions:
items:
$ref: '#/definitions/FileStatus'
type: array
upstreamSet:
type: boolean
required:
- currentBranch
- fileStatus
Expand Down
10 changes: 0 additions & 10 deletions pkg/apiclient/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1775,7 +1775,6 @@ components:
GitStatus:
example:
behind: 6
upstreamSet: true
fileStatus:
- extra: extra
name: name
Expand All @@ -1801,8 +1800,6 @@ components:
items:
$ref: '#/components/schemas/FileStatus'
type: array
upstreamSet:
type: boolean
required:
- currentBranch
- fileStatus
Expand Down Expand Up @@ -1940,7 +1937,6 @@ components:
state:
gitStatus:
behind: 6
upstreamSet: true
fileStatus:
- extra: extra
name: name
Expand Down Expand Up @@ -2086,7 +2082,6 @@ components:
example:
gitStatus:
behind: 6
upstreamSet: true
fileStatus:
- extra: extra
name: name
Expand Down Expand Up @@ -2272,7 +2267,6 @@ components:
example:
gitStatus:
behind: 6
upstreamSet: true
fileStatus:
- extra: extra
name: name
Expand Down Expand Up @@ -2330,7 +2324,6 @@ components:
state:
gitStatus:
behind: 6
upstreamSet: true
fileStatus:
- extra: extra
name: name
Expand Down Expand Up @@ -2372,7 +2365,6 @@ components:
state:
gitStatus:
behind: 6
upstreamSet: true
fileStatus:
- extra: extra
name: name
Expand Down Expand Up @@ -2437,7 +2429,6 @@ components:
state:
gitStatus:
behind: 6
upstreamSet: true
fileStatus:
- extra: extra
name: name
Expand Down Expand Up @@ -2479,7 +2470,6 @@ components:
state:
gitStatus:
behind: 6
upstreamSet: true
fileStatus:
- extra: extra
name: name
Expand Down
26 changes: 0 additions & 26 deletions pkg/apiclient/docs/GitStatus.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Name | Type | Description | Notes
**BranchPublished** | Pointer to **bool** | | [optional]
**CurrentBranch** | **string** | |
**FileStatus** | [**[]FileStatus**](FileStatus.md) | |
**UpstreamSet** | Pointer to **bool** | | [optional]

## Methods

Expand Down Expand Up @@ -145,31 +144,6 @@ and a boolean to check if the value has been set.
SetFileStatus sets FileStatus field to given value.


### GetUpstreamSet

`func (o *GitStatus) GetUpstreamSet() bool`

GetUpstreamSet returns the UpstreamSet field if non-nil, zero value otherwise.

### GetUpstreamSetOk

`func (o *GitStatus) GetUpstreamSetOk() (*bool, bool)`

GetUpstreamSetOk returns a tuple with the UpstreamSet field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.

### SetUpstreamSet

`func (o *GitStatus) SetUpstreamSet(v bool)`

SetUpstreamSet sets UpstreamSet field to given value.

### HasUpstreamSet

`func (o *GitStatus) HasUpstreamSet() bool`

HasUpstreamSet returns a boolean if a field has been set.


[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down
36 changes: 0 additions & 36 deletions pkg/apiclient/model_git_status.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions pkg/db/dto/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ type GitStatusDTO struct {
CurrentBranch string `json:"currentBranch"`
Files []*FileStatusDTO `json:"fileStatus"`
BranchPublished bool `json:"branchPublished,omitempty"`
UpstreamSet bool `json:"upstreamSet,omitempty"`
Ahead int32 `json:"ahead,omitempty"`
Behind int32 `json:"behind,omitempty"`
}
Expand Down Expand Up @@ -116,7 +115,6 @@ func ToGitStatusDTO(status *project.GitStatus) *GitStatusDTO {
statusDTO := &GitStatusDTO{
CurrentBranch: status.CurrentBranch,
BranchPublished: status.BranchPublished,
UpstreamSet: status.UpstreamSet,
Ahead: int32(status.Ahead),
Behind: int32(status.Behind),
}
Expand Down Expand Up @@ -191,7 +189,6 @@ func ToGitStatus(statusDTO *GitStatusDTO) *project.GitStatus {
status := &project.GitStatus{
CurrentBranch: statusDTO.CurrentBranch,
BranchPublished: statusDTO.BranchPublished,
UpstreamSet: statusDTO.UpstreamSet,
Ahead: int(statusDTO.Ahead),
Behind: int(statusDTO.Behind),
}
Expand Down
40 changes: 10 additions & 30 deletions pkg/git/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,42 +191,26 @@ func (s *Service) SetGitConfig(userData *gitprovider.GitUser) error {
return nil
}

func (s *Service) isBranchPublished(branchname string) (bool, error) {
cmd := exec.Command("git", "-C", s.ProjectDir, "ls-remote", "--heads", "origin", branchname)
out, err := cmd.CombinedOutput()
func (s *Service) isBranchPublished() (bool, error) {
upstream, err := s.getUpstreamBranch()
if err != nil {
return false, err
}

output := strings.TrimSpace(string(out))
return strings.Contains(output, fmt.Sprintf("refs/heads/%s", branchname)), nil
return upstream != "", nil
}

func (s *Service) getUpstreamBranch(branchname string) (string, error) {
isPublished, err := s.isBranchPublished(branchname)
if err != nil || !isPublished {
return "", err
}

func (s *Service) getUpstreamBranch() (string, error) {
cmd := exec.Command("git", "-C", s.ProjectDir, "rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{upstream}")
out, err := cmd.CombinedOutput()
if err != nil {
return "", err
return "", nil
}

return strings.TrimSpace(string(out)), nil
}

func (s *Service) isUpstreamSet(branchname string) (bool, error) {
upstream, err := s.getUpstreamBranch(branchname)
if err != nil || upstream == "" {
return false, err
}
return true, nil
}

func (s *Service) getAheadBehindInfo(branchName string) (int, int, error) {
upstream, err := s.getUpstreamBranch(branchName)
func (s *Service) getAheadBehindInfo() (int, int, error) {
upstream, err := s.getUpstreamBranch()
if err != nil {
return 0, 0, err
}
Expand Down Expand Up @@ -292,25 +276,21 @@ func (s *Service) GetGitStatus() (*project.GitStatus, error) {
Worktree: MapStatus[file.Worktree],
})
}
branchName := ref.Name().Short()

branchPublished, err := s.isBranchPublished(branchName)
branchPublished, err := s.isBranchPublished()
if err != nil {
return nil, err
}

upstreamSet, err := s.isUpstreamSet(branchName)

ahead, behind, err := s.getAheadBehindInfo(branchName)
ahead, behind, err := s.getAheadBehindInfo()
if err != nil {
return nil, err
}

return &project.GitStatus{
CurrentBranch: branchName,
CurrentBranch: ref.Name().Short(),
Files: files,
BranchPublished: branchPublished,
UpstreamSet: upstreamSet,
Ahead: ahead,
Behind: behind,
}, nil
Expand Down
11 changes: 3 additions & 8 deletions pkg/views/workspace/info/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,15 @@ func getInfoLineGitStatus(key string, status *apiclient.GitStatus) string {

unpushedOutput := ""

if status.Ahead != nil && *status.Ahead > 0 {
if *status.Ahead > 0 {
if *status.Ahead == 1 {
unpushedOutput += " (1 commit ahead)"
} else {
unpushedOutput += fmt.Sprintf(" (%d commits ahead)", *status.Ahead)
}
}

if status.Behind != nil && *status.Behind > 0 {
if *status.Behind > 0 {
if *status.Behind == 1 {
unpushedOutput += " (1 commit behind)"
} else {
Expand All @@ -191,12 +191,7 @@ func getInfoLineGitStatus(key string, status *apiclient.GitStatus) string {
branchPublishedOutput = " (branch not published)"
}

upstreamSetOutput := ""
if !*status.UpstreamSet {
upstreamSetOutput = " (upstream not set)"
}

output += changesOutput + unpushedOutput + branchPublishedOutput + upstreamSetOutput + propertyValueStyle.Foreground(views.Light).Render("\n")
output += changesOutput + unpushedOutput + branchPublishedOutput + propertyValueStyle.Foreground(views.Light).Render("\n")

return output
}
1 change: 0 additions & 1 deletion pkg/workspace/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ type GitStatus struct {
CurrentBranch string `json:"currentBranch" validate:"required"`
Files []*FileStatus `json:"fileStatus" validate:"required"`
BranchPublished bool `json:"branchPublished" validate:"optional"`
UpstreamSet bool `json:"upstreamSet" validate:"optional"`
Ahead int `json:"ahead" validate:"optional"`
Behind int `json:"behind" validate:"optional"`
} // @name GitStatus
Expand Down

0 comments on commit 904564d

Please sign in to comment.