starting to write the commit functions

This commit is contained in:
2020-06-20 18:48:58 -04:00
parent 47cc65a824
commit 1ec7b436da
9 changed files with 268 additions and 32 deletions

View File

@@ -0,0 +1,33 @@
package clientcmd
import (
"fmt"
"os"
clientconfig "github.com/deranjer/gvc/client/clientconfig"
"github.com/deranjer/gvc/common/engine"
"github.com/deranjer/gvc/common/manager"
)
// Commit commits the tracked files and changes to the repo
func Commit(conf *clientconfig.Gvcconfig, commitMessage string, m *manager.Manager) error {
trackedFiles, err := m.FetchTrackedFiles()
if err != nil {
return err
}
for _, trackedFile := range trackedFiles {
currentFile, err := os.Stat(trackedFile.Path)
if err != nil {
fmt.Printf("unable to stat tracked file: %s error: %s\n", currentFile.Name(), err)
continue
}
currentFileHash, err := engine.UniqueFileHash(trackedFile.Path)
if err != nil {
fmt.Printf("unable to create hash for file: %s error: %s\n", currentFile.Name(), err)
}
if currentFileHash == trackedFile.CurrentHash {
fmt.Printf("No changes found in file: %s when compared to file: %s\n", currentFile.Name(), trackedFile.Name)
}
}
return nil
}