Compare commits

..

1 Commits

Author SHA1 Message Date
9e8ccfe78e Improve code readability #1
Improve mostly common_utils_test.go
2024-06-13 21:19:04 +02:00
4 changed files with 25 additions and 28 deletions

View File

@ -54,8 +54,8 @@ func findNumberOfCommitDiffs(srcCommit *object.Commit, dstCommit *object.Commit)
return diffRange, false
}
var baseCommitHashes []string
var destCommitHashes []string
baseCommitHashes := []string{}
destCommitHashes := []string{}
// Try to find all differences, limit only to five last changes to avoid reading whole repository at once
for {

View File

@ -1,7 +1,6 @@
package commands
import (
"errors"
"fmt"
"gitlab.com/revalus/grm/internal/config"
@ -27,14 +26,15 @@ const (
func fetchRepository(repo *git.Repository) (bool, error) {
err := repo.Fetch(&git.FetchOptions{})
switch {
case errors.Is(err, git.NoErrAlreadyUpToDate):
if err == git.NoErrAlreadyUpToDate {
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) {
@ -62,23 +62,21 @@ func (s Synchronizer) Command(repoCfg config.RepositoryConfig) CommandStatus {
destPath := fmt.Sprintf("%v/%v", s.workspace, repoCfg.Dest)
repo, err := git.PlainOpen(destPath)
if err != nil {
if errors.Is(err, git.ErrRepositoryNotExists) {
if err != nil && err == git.ErrRepositoryNotExists {
cmdStatus.Changed, err = cloneRepository(destPath, &repoCfg)
cmdStatus.Message = syncCloned
} else {
cmdStatus.Error = true
cmdStatus.Message = err.Error()
}
return cmdStatus
}
} else if err == nil {
cmdStatus.Changed, err = fetchRepository(repo)
if cmdStatus.Changed {
cmdStatus.Message = syncFetched
} else {
cmdStatus.Message = syncUpToDate
}
} else {
cmdStatus.Error = true
cmdStatus.Message = err.Error()
return cmdStatus
}
if err != nil {
cmdStatus.Error = true

View File

@ -1,7 +1,6 @@
package config
import (
"errors"
"fmt"
"os"
"reflect"
@ -102,9 +101,9 @@ repositories:
`)
_, 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())
}
}
@ -128,7 +127,7 @@ repositories:
}
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())
}
}
@ -152,7 +151,7 @@ repositories:
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)
}
}

View File

@ -29,7 +29,7 @@ func TestGetFileExtension(t *testing.T) {
}
func TestErrorInGetExtensionFile(t *testing.T) {
func TestErrorInGetExcensionFile(t *testing.T) {
result, err := getFileExtension("test")