starting on the commit logic

This commit is contained in:
2020-06-21 22:26:03 -04:00
parent 1ec7b436da
commit e4ac7f70e6
7 changed files with 90 additions and 28 deletions

View File

@@ -5,6 +5,7 @@ import (
"os"
clientconfig "github.com/deranjer/gvc/client/clientconfig"
"github.com/deranjer/gvc/common/database"
"github.com/deranjer/gvc/common/engine"
"github.com/deranjer/gvc/common/manager"
)
@@ -15,6 +16,7 @@ func Commit(conf *clientconfig.Gvcconfig, commitMessage string, m *manager.Manag
if err != nil {
return err
}
var filesToDiff []database.File // Contains the list of files that have changed
for _, trackedFile := range trackedFiles {
currentFile, err := os.Stat(trackedFile.Path)
if err != nil {
@@ -24,10 +26,15 @@ func Commit(conf *clientconfig.Gvcconfig, commitMessage string, m *manager.Manag
currentFileHash, err := engine.UniqueFileHash(trackedFile.Path)
if err != nil {
fmt.Printf("unable to create hash for file: %s error: %s\n", currentFile.Name(), err)
continue
}
if currentFileHash == trackedFile.CurrentHash {
fmt.Printf("No changes found in file: %s when compared to file: %s\n", currentFile.Name(), trackedFile.Name)
continue
}
filesToDiff = append(filesToDiff, trackedFile)
}
m.BeginCommit(filesToDiff, conf.CurrentBranch)
return nil
}