@@ -49,6 +49,11 @@ func commitModel(commit object.Commit) string {
49
49
return commitString
50
50
}
51
51
52
+ func nilCommit () []* string {
53
+ logger .Log ("No new commits available to push" , global .StatusWarning )
54
+ return nil
55
+ }
56
+
52
57
// UnPushedCommits compares the local branch and the remote branch to extract the commits which are not pushed to the remote
53
58
func UnPushedCommits (repo * git.Repository , remoteRef string ) []* string {
54
59
var commitArray []* string
@@ -59,8 +64,12 @@ func UnPushedCommits(repo *git.Repository, remoteRef string) []*string {
59
64
remoteCommit , _ := repo .CommitObject (* revHash )
60
65
61
66
head , _ := repo .Head ()
62
- localCommit , _ := repo .CommitObject (head .Hash ())
63
67
68
+ if head == nil {
69
+ return nilCommit ()
70
+ }
71
+
72
+ localCommit , _ := repo .CommitObject (head .Hash ())
64
73
isAncestor , _ = localCommit .IsAncestor (remoteCommit )
65
74
66
75
if ! isAncestor {
@@ -70,7 +79,22 @@ func UnPushedCommits(repo *git.Repository, remoteRef string) []*string {
70
79
All : false ,
71
80
})
72
81
82
+ if logItr == nil {
83
+ if localCommit != nil {
84
+ commitString := commitModel (* localCommit )
85
+ logger .Log (fmt .Sprintf ("New commit available for pushing to remote -> %s" , commitString ), global .StatusInfo )
86
+ commitArray = append (commitArray , & commitString )
87
+ return commitArray
88
+ } else {
89
+ return nilCommit ()
90
+ }
91
+ }
92
+
73
93
_ = logItr .ForEach (func (commit * object.Commit ) error {
94
+ if commit == nil {
95
+ logger .Log ("Commit object is nil" , global .StatusError )
96
+ return types.Error {Msg : "Commit object is nil" }
97
+ }
74
98
if commit .Hash == remoteCommit .Hash {
75
99
logger .Log (fmt .Sprintf ("Same commits found in remote and local trees -> %s" , commit .Hash .String ()), global .StatusInfo )
76
100
return types.Error {Msg : "Same commit" }
@@ -84,8 +108,7 @@ func UnPushedCommits(repo *git.Repository, remoteRef string) []*string {
84
108
logItr .Close ()
85
109
return commitArray
86
110
} else {
87
- logger .Log ("No new commits available to push" , global .StatusWarning )
88
- return nil
111
+ return nilCommit ()
89
112
}
90
113
91
114
}
0 commit comments