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

@@ -110,7 +110,7 @@ func main() {
pullCommand(cli, &conf)
// Adding the "commit" command
commitCommand(cli, &conf)
commitCommand(cli, &conf, m)
err = cli.Run()
if err != nil {
@@ -689,10 +689,10 @@ func pullCommand(cli *clir.Cli, conf *config.Gvcconfig) {
})
}
func commitCommand(cli *clir.Cli, conf *config.Gvcconfig) {
func commitCommand(cli *clir.Cli, conf *config.Gvcconfig, m *manager.Manager) {
commitCommand := cli.NewSubCommand("commit", "commits the changes to the repo")
var commitMessage string
commitMessageFlag := pullCommand.StringFlag("message", "adds a message to a commit", &commitMessage)
commitMessageFlag := commitCommand.StringFlag("message", "adds a message to a commit", &commitMessage)
commitMessageFlag.FlagShortCut("message", "m")
commitCommand.Action(func() error {
isRepo := validateRepo()
@@ -700,13 +700,15 @@ func commitCommand(cli *clir.Cli, conf *config.Gvcconfig) {
fmt.Println("no valid repo found.. please run 'init' to setup a repo first")
os.Exit(0)
}
if len(commitCommand.OtherArgs()) == 0 {
commitCommand.PrintHelp()
fmt.Println("branch name required..")
os.Exit(0)
// if len(commitCommand.OtherArgs()) == 0 {
// commitCommand.PrintHelp()
// fmt.Println("branch name required..")
// os.Exit(0)
// }
if commitMessage != "" {
}
branchName := commitCommand.OtherArgs()[0]
err := clientcmd.SwitchBranch(conf, branchName)
err := clientcmd.Commit(conf, commitMessage, m)
if err != nil {
return fmt.Errorf("unable to pull branch: %s", err)
}

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
}