working on merging configs, adding branch/switch/pull commands

This commit is contained in:
2020-06-10 22:45:15 -04:00
parent c4aa5a1c66
commit 2cbdf21a81
12 changed files with 269 additions and 66 deletions

View File

@@ -0,0 +1,25 @@
package clientcmd
import (
"fmt"
clientconfig "github.com/deranjer/gvc/client/clientconfig"
)
// CreateBranch creates a new branch with the supplied name
func CreateBranch(conf *clientconfig.Gvcconfig, branchName string) error {
branches := conf.LocalBranches
for _, branch := range branches {
if branch == branchName {
return fmt.Errorf("Branch already exists, unable to create, use the switch command to switch to this branch: %s", branchName)
}
}
conf.LocalBranches = append(conf.LocalBranches, branchName) //add the branch to the config
// TODO Create the branch
//If success, switch to new branch
err := SwitchBranch(conf, branchName)
if err != nil {
return fmt.Errorf("error switching to new branch: %s", err)
}
return nil
}

View File

@@ -5,6 +5,7 @@ import (
clientconfig "github.com/deranjer/gvc/client/clientconfig"
"github.com/deranjer/gvc/common"
"github.com/deranjer/store"
"github.com/go-resty/resty/v2"
)
@@ -31,7 +32,34 @@ func RefreshContent(conf *clientconfig.Gvcconfig, repoName string) error { //TOD
}
return fmt.Errorf("response not a success: %d: connection URL: %s", resp.StatusCode(), resp.Request.URL)
}
fmt.Println(resp)
//fmt.Println(resp)
fmt.Printf("%+v\n", refreshResult)
fmt.Println("Merging server config with local config...")
// TODO: Save a backup of the config in case we need to roll back
// TODO: Before merging check to make sure the slices aren't already the same
conf.Locked = refreshResult.Locked // Overwriting locks on client since server is authoritative on locks
fmt.Println("Replaced client locked with server locked...")
// Now merging the structs where the user might have customized for their environment
conf.NoCompress.Exts = append(conf.NoCompress.Exts, refreshResult.NoCompress.Exts...)
conf.NoCompress.Files = append(conf.NoCompress.Files, refreshResult.NoCompress.Files...)
conf.NoCompress.Folders = append(conf.NoCompress.Folders, refreshResult.NoCompress.Folders...)
conf.Ignores.Exts = append(conf.Ignores.Exts, refreshResult.Ignores.Exts...)
conf.Ignores.Files = append(conf.Ignores.Files, refreshResult.Ignores.Files...)
conf.Ignores.Folders = append(conf.Ignores.Folders, refreshResult.Ignores.Folders...)
// And then purging the duplicates using a map in case there are very large slices
conf.NoCompress.Exts = common.RemoveDuplicatesFromSlice(conf.NoCompress.Exts)
conf.NoCompress.Files = common.RemoveDuplicatesFromSlice(conf.NoCompress.Files)
conf.NoCompress.Folders = common.RemoveDuplicatesFromSlice(conf.NoCompress.Folders)
conf.Ignores.Exts = common.RemoveDuplicatesFromSlice(conf.Ignores.Exts)
conf.Ignores.Files = common.RemoveDuplicatesFromSlice(conf.Ignores.Files)
conf.Ignores.Folders = common.RemoveDuplicatesFromSlice(conf.Ignores.Folders)
fmt.Println("Joined and purged duplicates for Ignore and NoCompress...")
conf.RemoteBranches = refreshResult.Branches
fmt.Println("updated remote branches...")
// TODO Update Commits
err = store.Save(ConfigPath, &conf)
if err != nil {
return fmt.Errorf("unable to save refreshed config to file: %s", err)
}
return nil
}

View File

@@ -0,0 +1,21 @@
package clientcmd
import (
"fmt"
clientconfig "github.com/deranjer/gvc/client/clientconfig"
)
// SwitchBranch switches to a different branch
func SwitchBranch(conf *clientconfig.Gvcconfig, branchName string) error {
fmt.Println("Attempting to switch to branch: ", branchName)
branches := conf.LocalBranches
for _, branch := range branches {
if branch == branchName {
fmt.Println("Found Branch: ", branch)
// TODO: do the actual branch switch
return nil
}
}
return fmt.Errorf("unable to locate requested branch: %s", branchName)
}