Skip to content

Commit 138c4c1

Browse files
committed
tweak to return string message (resolves #109)
1 parent b100fd7 commit 138c4c1

File tree

5 files changed

+59
-18
lines changed

5 files changed

+59
-18
lines changed

git/git_branch_checkout.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func CheckoutBranch(repo *git.Repository, branchName string) string {
3939
})
4040
if checkoutErr != nil {
4141
logger.Log(checkoutErr.Error(), global.StatusError)
42-
return "CHECKOUT_FAILED"
42+
return global.BranchCheckoutError
4343
}
4444
}
4545

@@ -49,7 +49,7 @@ func CheckoutBranch(repo *git.Repository, branchName string) string {
4949
})
5050
if checkoutErr != nil {
5151
logger.Log(checkoutErr.Error(), global.StatusError)
52-
return "CHECKOUT_FAILED"
52+
return global.BranchCheckoutError
5353
}
5454

5555
logger.Log(fmt.Sprintf("Current branch checked out to -> %s", branchName), global.StatusInfo)

git/git_branch_list.go

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,28 @@ type Branch struct {
1515
AllBranchList []*string
1616
}
1717

18+
// isBranchNameValid function checks if the branch name is valid to be return as an eligible branch
19+
//
20+
// The function filters out Tags and stashes returned as references
21+
func isBranchNameValid(branchName string) bool {
22+
var branchNameValid bool
23+
branchNameValid = true
24+
25+
if branchName == "HEAD" {
26+
branchNameValid = false
27+
}
28+
29+
if !strings.Contains(branchName, "refs/") {
30+
branchNameValid = false
31+
}
32+
33+
if strings.Contains(branchName, "tags/") {
34+
branchNameValid = false
35+
}
36+
37+
return branchNameValid
38+
}
39+
1840
// GetBranchList fetches all the branches from the target repository
1941
// The result will be returned as a struct with the current branch and all the available branches
2042
func GetBranchList(repo *git.Repository, branchChan chan Branch) {
@@ -50,7 +72,8 @@ func GetBranchList(repo *git.Repository, branchChan chan Branch) {
5072
refNamePtr *string
5173
)
5274
if ref != nil {
53-
if reference.Name().String() != "HEAD" && strings.Contains(reference.Name().String(), "refs/") {
75+
referenceName := reference.Name().String()
76+
if isBranchNameValid(referenceName) {
5477
refNameSplit := strings.Split(reference.Name().String(), "refs/")
5578
if len(refNameSplit) == 2 && strings.Contains(refNameSplit[1], "/") && !strings.Contains(refNameSplit[1], "remotes/"+git.DefaultRemoteName+"/HEAD") {
5679
logger.Log(fmt.Sprintf("Available Branch : %v", refNameSplit[1]), global.StatusInfo)
@@ -74,12 +97,15 @@ func GetBranchList(repo *git.Repository, branchChan chan Branch) {
7497

7598
if bIter != nil {
7699
_ = bIter.ForEach(func(reference *plumbing.Reference) error {
77-
if reference != nil {
78-
localBranch := reference.String()
79-
splitBranch := strings.Split(localBranch, "/")
80-
localBranch = splitBranch[len(splitBranch)-1]
100+
if reference != nil && !strings.Contains(reference.Name().String(), "tags/") {
101+
localBranch := reference.Name().String()
102+
if isBranchNameValid(localBranch) {
103+
splitBranch := strings.Split(localBranch, "/")
104+
localBranch = splitBranch[len(splitBranch)-1]
81105

82-
branches = append(branches, &localBranch)
106+
logger.Log("Available Branch : "+localBranch, global.StatusInfo)
107+
branches = append(branches, &localBranch)
108+
}
83109
return nil
84110
} else {
85111
return types.Error{Msg: "Empty reference"}

git/git_fetch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func windowsFetch(repoPath string, remoteName string, branch string) *model.Fetc
3636
} else {
3737
logger.Log(fmt.Sprintf("Changes fetched from remote - %s -> %s", remoteName, cmdStr), global.StatusInfo)
3838

39-
msg := fmt.Sprintf("Changes fetched from %v", remoteName)
39+
msg := fmt.Sprintf("Changes fetched from remote %v", remoteName)
4040
return &model.FetchResult{
4141
Status: "CHANGES FETCHED FROM REMOTE",
4242
FetchedItems: []*string{&msg},

server.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ func main() {
7171
currentDir := filepath.Dir(execName)
7272
buildPath = fmt.Sprintf("%s/gitconvex-ui", currentDir)
7373
staticPath = fmt.Sprintf("%s/static", buildPath)
74+
} else {
75+
logger.Log("Unable to serve UI bundle", global.StatusError)
7476
}
7577

7678
// Static file supplier for hosting the react static assets and scripts

utils/env_file_handler.go

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"go/types"
77
"io/ioutil"
88
"os"
9+
"path/filepath"
910
)
1011

1112
type EnvConfig struct {
@@ -20,13 +21,13 @@ func localLogger(message string, status string) {
2021

2122
// EnvConfigValidator checks if the env_config json file is present and accessible
2223
// If the file is missing or unable to access, then an error will be thrown
23-
2424
func EnvConfigValidator() error {
25-
cwd, wdErr := os.Getwd()
25+
execName, execErr := os.Executable()
26+
cwd := filepath.Dir(execName)
2627

27-
if wdErr != nil {
28-
localLogger(wdErr.Error(), global.StatusError)
29-
return wdErr
28+
if execErr != nil {
29+
localLogger(execErr.Error(), global.StatusError)
30+
return execErr
3031
}
3132

3233
fileString := cwd + "/env_config.json"
@@ -45,9 +46,15 @@ func EnvConfigValidator() error {
4546
}
4647

4748
// EnvConfigFileReader reads the env_config json file and returns the config data as a struct
48-
4949
func EnvConfigFileReader() *EnvConfig {
50-
cwd, _ := os.Getwd()
50+
execName, execErr := os.Executable()
51+
cwd := filepath.Dir(execName)
52+
53+
if execErr != nil {
54+
localLogger(execErr.Error(), global.StatusError)
55+
return nil
56+
}
57+
5158
fileString := cwd + "/env_config.json"
5259
envFile, err := os.Open(fileString)
5360

@@ -72,9 +79,15 @@ func EnvConfigFileReader() *EnvConfig {
7279

7380
// EnvConfigFileGenerator will be invoked when the EnvConfigValidator returns an error or if EnvConfigFileReader returns no data
7481
// The function generates a new env_config.json file and populates it with the default config data
75-
7682
func EnvConfigFileGenerator() error {
77-
cwd, _ := os.Getwd()
83+
execName, execErr := os.Executable()
84+
cwd := filepath.Dir(execName)
85+
86+
if execErr != nil {
87+
localLogger(execErr.Error(), global.StatusError)
88+
return types.Error{Msg: execErr.Error()}
89+
}
90+
7891
fileString := cwd + "/env_config.json"
7992

8093
envContent, _ := json.MarshalIndent(&EnvConfig{

0 commit comments

Comments
 (0)