reworking database, init and add commands

This commit is contained in:
2020-07-02 15:00:30 -04:00
parent 6379c73e38
commit 5af55ed62e
15 changed files with 220 additions and 295 deletions

View File

@@ -97,6 +97,7 @@ func AddFiles(input string, inputType string, ignore common.FileTypes, m *engine
} else {
wildcard = input
}
m.Info().Msgf("Adding all files with wildcard: %s", wildcard)
err := common.CheckFileTypes(wildcard, "wildcard", ignore)
if err != nil {
return err
@@ -146,6 +147,7 @@ func AddFiles(input string, inputType string, ignore common.FileTypes, m *engine
return nil
})
case "all":
m.Info().Msg("Adding all files...")
filepath.Walk(workingDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return fmt.Errorf("failure accessing path %s", err)

View File

@@ -1,13 +1,18 @@
package clientcmd
import (
"fmt"
clientconfig "github.com/deranjer/gvc/client/clientconfig"
"github.com/deranjer/gvc/common/engine"
)
// Commit commits the tracked files and changes to the repo
func Commit(conf *clientconfig.Gvcconfig, commitMessage string, m *engine.Manager) error {
m.BeginCommit(conf.CurrentBranch, commitMessage)
err := m.BeginCommit(conf.CurrentBranch, commitMessage)
if err != nil {
return fmt.Errorf("begin commit failed with message: %s", err)
}
return nil
}

View File

@@ -25,7 +25,7 @@ func validateFileType(path string, inputType string) error {
return fmt.Errorf("unable to read file, corrupted? %s", err)
}
if fileInfo.IsDir() {
if inputType == "folder" {
if inputType == "folder" || inputType == "all" {
return nil
} else {
return fmt.Errorf("folder flag was used, but input is not a folder, will not continue")

View File

@@ -2,23 +2,41 @@ package clientcmd
import (
"fmt"
"log"
"os"
"path/filepath"
"github.com/deranjer/gvc/common/database"
"github.com/deranjer/gvc/common/engine"
)
// InitializeRepo creates the repo directory and a new config file
func InitializeRepo() string {
func InitializeRepo(dbPath string, version string, rootPath string) (string, error) {
cwd, err := os.Getwd()
if err != nil {
log.Fatal("unable to get current working directory.. permissions issue?")
fmt.Printf("unable to get current working directory.. permissions issue? %s\n", err)
return "", err
}
repoName := filepath.Base(cwd)
fmt.Println("Initializing repo in dir: ", cwd)
err = os.Mkdir(".gvc", 0644)
if err != nil {
fmt.Println(".gvc directory already exists, but no config file... continuing")
fmt.Printf(".gvc directory already exists, but no config file... continuing")
}
err = engine.CreatePaths(rootPath)
if err != nil {
fmt.Printf("unable to create root dir paths.. permissions issue? %s\n", err)
return "", err
}
fmt.Println("Creating DB...")
err = database.CreateDB(dbPath, version, repoName)
if err != nil {
fmt.Printf("unable to create db: %s\n", err)
err := os.Remove(dbPath)
if err != nil {
fmt.Printf("unable to roll back database, cannot delete db: %s err: %s", dbPath, err)
}
return "", err
}
repoName := filepath.Base(cwd)
fmt.Println("Adding new repo with name: ", repoName)
return repoName
return repoName, nil
}