2121
2222// Helper functions
2323
24+ // isGotInstalled checks to see if Git inls installed on the system
2425func isGitInstalled () (bool , error ) {
2526 _ , err := exec .Command ("git" , "--version" ).Output ()
2627 if err != nil {
@@ -29,6 +30,7 @@ func isGitInstalled() (bool, error) {
2930 return true , nil
3031}
3132
33+ // isGitRepo checks to see if the active directory has Git initialized
3234func isGitRepo () (bool , error ) {
3335 _ , err := exec .Command ("git" , "rev-parse" , "--is-inside-work-tree" ).Output ()
3436 if err != nil {
@@ -37,6 +39,7 @@ func isGitRepo() (bool, error) {
3739 return true , nil
3840}
3941
42+ // isGitDirty checks the Git repo for diffs
4043func isGitDirty () (bool , error ) {
4144 out , err := exec .Command ("git" , "diff-files" ).Output ()
4245 if err != nil {
@@ -45,6 +48,7 @@ func isGitDirty() (bool, error) {
4548 return len (out ) > 0 , nil
4649}
4750
51+ // runCmd runs the given command and its arguments
4852func runCmd (name string , args ... string ) error {
4953 internal .LogVerbose (verbose , "Running: %s %s" , name , strings .Join (args , " " ))
5054 cmd := exec .Command (name , args ... )
@@ -54,11 +58,13 @@ func runCmd(name string, args ...string) error {
5458 return cmd .Run ()
5559}
5660
61+ // hostname returns the OS hostname, discarding the potential error
5762func hostname () string {
5863 h , _ := os .Hostname ()
5964 return h
6065}
6166
67+ // stageAndCommit stages all modified files in the repo and commits them with the function's internal formatting
6268func stageAndCommit (files []string ) error {
6369 args := append ([]string {"add" }, files ... )
6470 internal .LogVerbose (verbose , "Staging files: %v" , files )
@@ -70,6 +76,7 @@ func stageAndCommit(files []string) error {
7076 return runCmd ("git" , "commit" , "-m" , msg )
7177}
7278
79+ // pullBeforePush pulls from remote repo using --ff-only flag
7380func pullBeforePush () error {
7481 fmt .Println (" Pulling latest changes from remote..." )
7582 return runner .RunInteractive ("git" , "pull" , "--ff-only" )
0 commit comments