starting on the commit logic
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/asdine/storm"
|
||||
"github.com/asdine/storm/q"
|
||||
)
|
||||
|
||||
// ConfigureDB sets up bolt and Storm according to the path of the database
|
||||
@@ -187,3 +188,39 @@ func (db *DB) UpdateDescription(patchID int, description string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// FetchCommitByNumber fetches the commit number of the passed branch
|
||||
func (db *DB) FetchCommitByNumber(branch string, commitNumber string) (commitResult Commit, err error) {
|
||||
var commit Commit
|
||||
db.Info().Msgf("fetching commit by number: %s in branch: %s", commitNumber, branch)
|
||||
query := db.Select(q.And(q.Eq("Branch", branch), q.Eq("Number", commitNumber)))
|
||||
err = query.Find(&commit)
|
||||
if err != nil {
|
||||
db.Err(err).Msgf("Failed to find commit by number: %s on branch: %s", commitNumber, branch)
|
||||
return commit, err
|
||||
}
|
||||
return commit, nil
|
||||
}
|
||||
|
||||
// FetchCommitByHash fetches a single commit on any branch by hash //TODO: Hash collision?
|
||||
func (db *DB) FetchCommitByHash(hash string) (commitResult Commit, err error) {
|
||||
var commit Commit
|
||||
db.Info().Msgf("Searching for commit by hash: %s", hash)
|
||||
if err := db.One("CommitHash", hash, &commit); err != nil {
|
||||
db.Err(err).Msgf("Failed to find commit by hash: %s", hash)
|
||||
return commit, err
|
||||
}
|
||||
return commit, nil
|
||||
}
|
||||
|
||||
// FetchLastCommitOnBranch gets the latest commit to the provided branch
|
||||
func (db *DB) FetchLastCommitOnBranch(branch string) (commitResult Commit, err error) {
|
||||
var commit Commit
|
||||
db.Info().Msgf("Fetching last commit on branch: %s", branch)
|
||||
query := db.Select(q.Eq("Branch", branch)) //Selecting everything that applies to that branch
|
||||
err = query.OrderBy("Number").Reverse().First(&commit) // Getting the last entry by number
|
||||
if err != nil {
|
||||
db.Err(err).Msgf("Failed to find last commit on branch: %s", branch)
|
||||
}
|
||||
return commit, nil
|
||||
}
|
||||
|
@@ -8,6 +8,8 @@ type Commit struct {
|
||||
TrackedFiles []File // All of the tracked files for this commit
|
||||
Date string
|
||||
Version string //User can tag a commit with a version number
|
||||
Branch string //Branch this commit belongs to
|
||||
Number string // The commit number
|
||||
|
||||
}
|
||||
|
||||
|
@@ -8,21 +8,9 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
logger "github.com/apsdehal/go-logger"
|
||||
clientconfig "github.com/deranjer/gvc/client/clientconfig"
|
||||
)
|
||||
|
||||
var log *logger.Logger
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
log, err = logger.New("utilities logger", 1, os.Stdout)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
log.SetFormat("[%{module}] [%{level}] %{message}")
|
||||
log.Info("Utilities logger Created")
|
||||
}
|
||||
|
||||
// CompressIntArray compresses an array of integers into a buffer
|
||||
func CompressIntArray(arry []int64, compressionBuffer *bytes.Buffer) (float64, error) {
|
||||
buf := new(bytes.Buffer)
|
||||
@@ -83,22 +71,28 @@ func InitiateDirectory(directory string) {
|
||||
// For the keys-folder we need to check if the folder exists...
|
||||
checkDir, err := IsDirectory(directory)
|
||||
if err != nil {
|
||||
log.ErrorF("Error checking for "+directory+" directory: %s\r\n", err)
|
||||
fmt.Println("Error checking for "+directory+" directory: %s\r\n", err)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if checkDir == true {
|
||||
log.Warning(directory + " already exists")
|
||||
fmt.Println(directory + " already exists")
|
||||
} else {
|
||||
// Create the directory.
|
||||
log.Info("Creating " + directory)
|
||||
fmt.Println("Creating " + directory)
|
||||
err = CreateDirectory(directory)
|
||||
if err != nil {
|
||||
log.ErrorF("Error creating the folder %s\r\n", err)
|
||||
fmt.Println("Error creating the folder %s\r\n", err)
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CreateInitialCommit copies the files over and compresses them if they are not in the NoCompress struct
|
||||
func CreateInitialCommit(conf *clientconfig.Gvcconfig) {
|
||||
//Need to deduplicate so we aren't storing duplicates of files, storing all the files in one folder won't work, will need something like git
|
||||
}
|
||||
|
||||
func IsDirectory(path string) (bool, error) {
|
||||
|
||||
s, err := os.Stat(path) // returns an error if the path does not exist.
|
||||
|
@@ -6,11 +6,13 @@ import (
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/deranjer/gvc/common/database"
|
||||
engine "github.com/deranjer/gvc/common/engine"
|
||||
"github.com/rs/zerolog"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// NewManager creates a new manager interface that contains all the needed information to make changes to the repo
|
||||
@@ -31,12 +33,13 @@ func NewManager(rootDir string, version string, dbPath string, informer chan Ope
|
||||
if err != nil {
|
||||
log.Fatal().Msgf("unable to create or open db: %s", err)
|
||||
}
|
||||
|
||||
var wg *sync.WaitGroup
|
||||
m := Manager{
|
||||
version,
|
||||
|
||||
//settings,
|
||||
log,
|
||||
wg,
|
||||
patcher,
|
||||
gvcDB,
|
||||
informer,
|
||||
@@ -160,6 +163,22 @@ func (m *Manager) prepareDatabaseForFile(tmpFile database.File) (int, error) {
|
||||
|
||||
}
|
||||
|
||||
func (m *Manager) BeginCommit(fileList []database.File, branch string) error {
|
||||
diffChannel := make(chan database.DiffObject)
|
||||
diffContext := context.Background()
|
||||
m.WaitGroup.Add(2)
|
||||
commit, err := m.dB.FetchLastCommitOnBranch(branch)
|
||||
if err != nil {
|
||||
m.Err(err).Msgf("unable to fetch last commit on branch, assuming first commit on branch", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Manager) FetchCommitByNumber(branch string, commitNumber string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// FetchTrackedFiles just grabbes all the files currently tracked in the repo
|
||||
func (m *Manager) FetchTrackedFiles() ([]database.File, error) {
|
||||
files, err := m.dB.RetrieveTrackedFiles()
|
||||
|
@@ -3,6 +3,7 @@ package manager
|
||||
//https://github.com/apsdehal/go-logger
|
||||
import (
|
||||
"os/user"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
database "github.com/deranjer/gvc/common/database"
|
||||
@@ -14,7 +15,7 @@ type Manager struct {
|
||||
Version string //What version of the client or server are we using
|
||||
//Settings *UserSettings
|
||||
*zerolog.Logger
|
||||
//*sync.WaitGroup
|
||||
*sync.WaitGroup
|
||||
//watcher engine.FileWatcher
|
||||
patcher engine.Patcher
|
||||
dB *database.DB
|
||||
|
Reference in New Issue
Block a user