Skip to content

Commit a54b291

Browse files
committed
revert previous commit with correct function code
1 parent 318acd2 commit a54b291

File tree

5 files changed

+66
-42
lines changed

5 files changed

+66
-42
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ $ ./make.bat build
8181

8282
| Software | Purpose |
8383
| -- | -- |
84-
| <b>[Git v2.20+](https://git-scm.com/)</b> | <b>Required for handling some intense git operations with the target repo</b> |
85-
| <b>[Go v1.15](https://golang.org/)</b> | <b>For building the backend from the source</b> |
86-
| <b>[npm v6+](https://nodejs.org/en/)</b> | <b>For building the react UI bundle from scratch</b> |
84+
| <b>[Git](https://git-scm.com/)</b> | <b>Required for handling some intense git operations with the target repo</b> |
85+
| <b>[Go](https://golang.org/)</b> | <b>For building the backend from the source</b> |
86+
| <b>[Node JS](https://nodejs.org/en/)</b> | <b>For building the react UI bundle from scratch</b> |
8787

8888
> **Important note for windows users**
8989

api/code_file_view.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func CodeFileView(repoPath string, fileName string) *model.CodeFileType {
2222
FileData: nil,
2323
}
2424
} else {
25-
logger.Log(fmt.Sprintf("Reading lines from file --> %s", fileName), global.StatusInfo)
25+
logger.Log(fmt.Sprintf("Reading lines from file --> %s", targetFile), global.StatusInfo)
2626
scanner := bufio.NewScanner(file)
2727
scanner.Split(bufio.ScanLines)
2828
for scanner.Scan() {

git/git_branch_add.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ func AddBranch(repo *git.Repository, branchName string) string {
1212
logger := global.Logger{}
1313
headRef, headErr := repo.Head()
1414

15+
logger.Log(fmt.Sprintf("Adding new branch -> %s", branchName), global.StatusInfo)
1516
if headErr != nil {
1617
logger.Log(fmt.Sprintf("Unable to fetch HEAD -> %s", headErr.Error()), global.StatusError)
1718
return "BRANCH_ADD_FAILED"

git/git_branch_list.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,19 @@ func GetBranchList(repo *git.Repository, branchChan chan Branch) {
5050
refNamePtr *string
5151
)
5252

53-
if reference.Name().String() != "HEAD" && strings.Contains(reference.Name().String(), "refs/") {
54-
refNameSplit := strings.Split(reference.Name().String(), "refs/")
55-
if len(refNameSplit) == 2 {
56-
logger.Log(fmt.Sprintf("Available Branch : %v", refNameSplit[1]), global.StatusInfo)
57-
if strings.Contains(refNameSplit[1], "heads/") {
58-
headBranch := strings.Split(refNameSplit[1], "heads/")[1]
59-
refNamePtr = &headBranch
60-
} else {
61-
refNamePtr = &refNameSplit[1]
53+
if ref != nil {
54+
if reference.Name().String() != "HEAD" && strings.Contains(reference.Name().String(), "refs/") {
55+
refNameSplit := strings.Split(reference.Name().String(), "refs/")
56+
if len(refNameSplit) == 2 {
57+
logger.Log(fmt.Sprintf("Available Branch : %v", refNameSplit[1]), global.StatusInfo)
58+
if strings.Contains(refNameSplit[1], "heads/") {
59+
headBranch := strings.Split(refNameSplit[1], "heads/")[1]
60+
refNamePtr = &headBranch
61+
} else {
62+
refNamePtr = &refNameSplit[1]
63+
}
64+
allBranchList = append(allBranchList, refNamePtr)
6265
}
63-
allBranchList = append(allBranchList, refNamePtr)
6466
}
6567
}
6668

git/git_commit_changes.go

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/neel1996/gitconvex-server/global"
1010
"github.com/neel1996/gitconvex-server/utils"
1111
"runtime"
12+
"strings"
1213
"time"
1314
)
1415

@@ -33,40 +34,55 @@ func windowsCommit(repoPath string, msg string) string {
3334
// The function falls back to the native git client for Windows platform due to an existing bug in the go-git library which
3435
// blocks commits in windows platform
3536
func CommitChanges(repo *git.Repository, commitMessage string) string {
37+
var formattedMessage = commitMessage
3638
logger := global.Logger{}
3739
w, wErr := repo.Worktree()
3840

39-
// Checking OS platform for switching to git client for Windows systems
40-
platform := runtime.GOOS
41-
if platform == "windows" && w != nil {
42-
logger.Log(fmt.Sprintf("OS is %s -- Switching to native git client", platform), global.StatusWarning)
43-
return windowsCommit(w.Filesystem.Root(), commitMessage)
44-
}
41+
if wErr != nil {
42+
logger.Log(fmt.Sprintf("Error occurred while fetching repo worktree -> %s", wErr.Error()), global.StatusError)
43+
return "COMMIT_FAILED"
44+
} else {
45+
//Checking and splitting multi-line commit messages
46+
if strings.Contains(commitMessage, "||") {
47+
splitMessage := strings.Split(commitMessage, "||")
48+
formattedMessage = strings.Join(splitMessage, "\n")
49+
}
4550

46-
// Logic to check if the repo / global config has proper user information setup
47-
// Commit will be signed by default user if no user config is present
48-
globalConfig, gCfgErr := repo.ConfigScoped(config.GlobalScope)
49-
localConfig, lCfgErr := repo.ConfigScoped(config.LocalScope)
50-
var author string
51+
// Checking OS platform for switching to git client for Windows systems
52+
platform := runtime.GOOS
53+
if platform == "windows" && w != nil {
54+
logger.Log(fmt.Sprintf("OS is %s -- Switching to native git client", platform), global.StatusWarning)
55+
return windowsCommit(w.Filesystem.Root(), formattedMessage)
56+
}
57+
58+
// Checking if repo is a fresh repo with no branches
59+
// fallback function will be used to commit with git if no branches are present
60+
head, _ := repo.Head()
61+
if head == nil {
62+
logger.Log("Repo with no HEAD", global.StatusWarning)
63+
return windowsCommit(w.Filesystem.Root(), formattedMessage)
64+
}
5165

52-
if gCfgErr == nil && lCfgErr == nil {
53-
fmt.Println(localConfig.User)
54-
fmt.Println(globalConfig.User)
66+
// Logic to check if the repo / global config has proper user information setup
67+
// Commit will be signed by default user if no user config is present
68+
globalConfig, gCfgErr := repo.ConfigScoped(config.GlobalScope)
69+
localConfig, lCfgErr := repo.ConfigScoped(config.LocalScope)
70+
var author string
5571

56-
if globalConfig.User.Name != "" {
57-
author = globalConfig.User.Name
58-
} else if localConfig.User.Name != "" {
59-
author = localConfig.User.Name
72+
if gCfgErr == nil && lCfgErr == nil {
73+
fmt.Println(localConfig.User)
74+
fmt.Println(globalConfig.User)
75+
76+
if globalConfig.User.Name != "" {
77+
author = globalConfig.User.Name
78+
} else if localConfig.User.Name != "" {
79+
author = localConfig.User.Name
80+
}
81+
} else {
82+
logger.Log(fmt.Sprintf("Unable to fetch repo config -> %v || %v", gCfgErr, lCfgErr), global.StatusError)
83+
return "COMMIT_FAILED"
6084
}
61-
} else {
62-
logger.Log(fmt.Sprintf("Unable to fetch repo config -> %v || %v", gCfgErr, lCfgErr), global.StatusError)
63-
return "COMMIT_FAILED"
64-
}
6585

66-
if wErr != nil {
67-
logger.Log(fmt.Sprintf("Error occurred while fetching repo worktree -> %s", wErr.Error()), global.StatusError)
68-
return "COMMIT_FAILED"
69-
} else {
7086
var commitOptions *git.CommitOptions
7187
var parentHash plumbing.Hash
7288
head, headErr := repo.Head()
@@ -89,13 +105,18 @@ func CommitChanges(repo *git.Repository, commitMessage string) string {
89105
Parents: []plumbing.Hash{parentHash},
90106
}
91107
} else {
92-
logger.Log(fmt.Sprintf("Commiting changes with author -> %s", author), global.StatusInfo)
108+
logger.Log(fmt.Sprintf("Commiting changes with author -> %s, message -> %s", author, formattedMessage), global.StatusInfo)
93109
commitOptions = &git.CommitOptions{
94110
All: false,
95111
Parents: []plumbing.Hash{parentHash},
96112
}
97113
}
98-
hash, err := w.Commit(commitMessage, commitOptions)
114+
115+
if formattedMessage == "" {
116+
return "COMMIT_FAILED"
117+
}
118+
119+
hash, err := w.Commit(formattedMessage, commitOptions)
99120
if err != nil {
100121
logger.Log(fmt.Sprintf("Error occurred while committing changes -> %s\n%v", err.Error(), err), global.StatusError)
101122
return "COMMIT_FAILED"

0 commit comments

Comments
 (0)