Compare commits
1 Commits
29d40969c2
...
9e8ccfe78e
Author | SHA1 | Date | |
---|---|---|---|
9e8ccfe78e |
@ -54,8 +54,8 @@ func findNumberOfCommitDiffs(srcCommit *object.Commit, dstCommit *object.Commit)
|
|||||||
return diffRange, false
|
return diffRange, false
|
||||||
}
|
}
|
||||||
|
|
||||||
var baseCommitHashes []string
|
baseCommitHashes := []string{}
|
||||||
var destCommitHashes []string
|
destCommitHashes := []string{}
|
||||||
|
|
||||||
// Try to find all differences, limit only to five last changes to avoid reading whole repository at once
|
// Try to find all differences, limit only to five last changes to avoid reading whole repository at once
|
||||||
for {
|
for {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"gitlab.com/revalus/grm/internal/config"
|
"gitlab.com/revalus/grm/internal/config"
|
||||||
|
|
||||||
@ -27,14 +26,15 @@ const (
|
|||||||
func fetchRepository(repo *git.Repository) (bool, error) {
|
func fetchRepository(repo *git.Repository) (bool, error) {
|
||||||
err := repo.Fetch(&git.FetchOptions{})
|
err := repo.Fetch(&git.FetchOptions{})
|
||||||
|
|
||||||
switch {
|
if err == git.NoErrAlreadyUpToDate {
|
||||||
case errors.Is(err, git.NoErrAlreadyUpToDate):
|
|
||||||
return false, nil
|
return false, nil
|
||||||
case errors.Is(err, git.NoErrAlreadyUpToDate):
|
|
||||||
return false, nil
|
|
||||||
default:
|
|
||||||
return true, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err != nil && err != git.NoErrAlreadyUpToDate {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func cloneRepository(destPath string, repoCfg *config.RepositoryConfig) (bool, error) {
|
func cloneRepository(destPath string, repoCfg *config.RepositoryConfig) (bool, error) {
|
||||||
@ -62,22 +62,20 @@ func (s Synchronizer) Command(repoCfg config.RepositoryConfig) CommandStatus {
|
|||||||
destPath := fmt.Sprintf("%v/%v", s.workspace, repoCfg.Dest)
|
destPath := fmt.Sprintf("%v/%v", s.workspace, repoCfg.Dest)
|
||||||
repo, err := git.PlainOpen(destPath)
|
repo, err := git.PlainOpen(destPath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil && err == git.ErrRepositoryNotExists {
|
||||||
if errors.Is(err, git.ErrRepositoryNotExists) {
|
cmdStatus.Changed, err = cloneRepository(destPath, &repoCfg)
|
||||||
cmdStatus.Changed, err = cloneRepository(destPath, &repoCfg)
|
cmdStatus.Message = syncCloned
|
||||||
cmdStatus.Message = syncCloned
|
} else if err == nil {
|
||||||
|
cmdStatus.Changed, err = fetchRepository(repo)
|
||||||
|
if cmdStatus.Changed {
|
||||||
|
cmdStatus.Message = syncFetched
|
||||||
} else {
|
} else {
|
||||||
cmdStatus.Error = true
|
cmdStatus.Message = syncUpToDate
|
||||||
cmdStatus.Message = err.Error()
|
|
||||||
}
|
}
|
||||||
return cmdStatus
|
|
||||||
}
|
|
||||||
|
|
||||||
cmdStatus.Changed, err = fetchRepository(repo)
|
|
||||||
if cmdStatus.Changed {
|
|
||||||
cmdStatus.Message = syncFetched
|
|
||||||
} else {
|
} else {
|
||||||
cmdStatus.Message = syncUpToDate
|
cmdStatus.Error = true
|
||||||
|
cmdStatus.Message = err.Error()
|
||||||
|
return cmdStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -102,9 +101,9 @@ repositories:
|
|||||||
`)
|
`)
|
||||||
_, err := GetRepositoryConfig(exampleWrongYamlConfig, "yaml")
|
_, err := GetRepositoryConfig(exampleWrongYamlConfig, "yaml")
|
||||||
|
|
||||||
expectedError := errors.New(fmt.Sprintf(errMissingSrcField, 0))
|
expectedError := fmt.Sprintf(errMissingSrcField, 0)
|
||||||
|
|
||||||
if errors.Is(err, expectedError) {
|
if err.Error() != expectedError {
|
||||||
t.Errorf("Expected to get error with value %v, instead of this got: %v", expectedError, err.Error())
|
t.Errorf("Expected to get error with value %v, instead of this got: %v", expectedError, err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -128,7 +127,7 @@ repositories:
|
|||||||
}
|
}
|
||||||
expectedError := getDuplicateFieldError("name", "example2", []int{1, 2})
|
expectedError := getDuplicateFieldError("name", "example2", []int{1, 2})
|
||||||
|
|
||||||
if errors.Is(err, expectedError) {
|
if err.Error() != expectedError.Error() {
|
||||||
t.Errorf("Expected to get error with value %v, instead of this got: %v", expectedError.Error(), err.Error())
|
t.Errorf("Expected to get error with value %v, instead of this got: %v", expectedError.Error(), err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -152,7 +151,7 @@ repositories:
|
|||||||
|
|
||||||
expectedError := getDuplicateFieldError("dest", "example", []int{1, 2})
|
expectedError := getDuplicateFieldError("dest", "example", []int{1, 2})
|
||||||
|
|
||||||
if errors.Is(err, expectedError) {
|
if err.Error() != expectedError.Error() {
|
||||||
t.Errorf("Expected to get error with value \"%v\", instead of this got: \"%v\"", expectedError, err)
|
t.Errorf("Expected to get error with value \"%v\", instead of this got: \"%v\"", expectedError, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ func TestGetFileExtension(t *testing.T) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestErrorInGetExtensionFile(t *testing.T) {
|
func TestErrorInGetExcensionFile(t *testing.T) {
|
||||||
|
|
||||||
result, err := getFileExtension("test")
|
result, err := getFileExtension("test")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user