diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 396fc83..26d96b6 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,8 +10,8 @@ jobs: runs-on: ubuntu-latest steps: - - name: Install libgit2-dev - run: sudo apt-get install -y libgit2-dev + name: Install deps + run: sudo apt-get install -y pkg-config cmake - name: Checkout uses: actions/checkout@v3 @@ -29,10 +29,14 @@ jobs: restore-keys: | ${{ runner.os }}-go- - - name: Set the right libgit2 version + name: Building run: | - sed -i -e 's/v34/v31/g' go.mod splitter/*.go - go mod tidy + go mod vendor + rm -rf vendor/github.com/libgit2/git2go + git clone https://github.com/libgit2/git2go vendor/github.com/libgit2/git2go/v34 + cd vendor/github.com/libgit2/git2go/v34 && git checkout v34.0.0 && git submodule update --init && make install-static - name: Test - run: go test -v ./... + run: | + export PKG_CONFIG_PATH=/home/runner/work/lite/lite/vendor/github.com/libgit2/git2go/v34/static-build/build + go test -v ./... diff --git a/main.go b/main.go index aad01df..bbd9a61 100644 --- a/main.go +++ b/main.go @@ -32,7 +32,7 @@ func (p *prefixesFlag) Set(value string) error { for _, prefix := range []*splitter.Prefix(*p) { // FIXME: to should be normalized (xxx vs xxx/ for instance) if prefix.To == to { - return fmt.Errorf("Cannot have two prefix splits under the same directory: %s -> %s vs %s -> %s", prefix.From, prefix.To, from, to) + return fmt.Errorf("cannot have two prefix splits under the same directory: %s -> %s vs %s -> %s", prefix.From, prefix.To, from, to) } } diff --git a/splitter/cache.go b/splitter/cache.go index 507c738..60b1ac4 100644 --- a/splitter/cache.go +++ b/splitter/cache.go @@ -41,7 +41,7 @@ func newCache(branch string, config *Config) (*cache, error) { return err1 }) if err != nil { - return nil, fmt.Errorf("Impossible to create bucket: %s", err) + return nil, fmt.Errorf("impossible to create bucket: %s", err) } return c, nil diff --git a/splitter/config.go b/splitter/config.go index 7dcec5c..3448daa 100644 --- a/splitter/config.go +++ b/splitter/config.go @@ -53,17 +53,25 @@ func Split(config *Config, result *Result) error { // Validate validates the configuration func (config *Config) Validate() error { - if !git.ReferenceIsValidName(config.Origin) { - return fmt.Errorf("The origin is not a valid Git reference") + ok, err := git.ReferenceNameIsValid(config.Origin) + if err != nil { + return err + } + if !ok { + return fmt.Errorf("the origin is not a valid Git reference") } - if config.Target != "" && !git.ReferenceIsValidName(config.Target) { - return fmt.Errorf("The target is not a valid Git reference") + ok, err = git.ReferenceNameIsValid(config.Target) + if err != nil { + return err + } + if config.Target != "" && !ok { + return fmt.Errorf("the target is not a valid Git reference") } git, ok := supportedGitVersions[config.GitVersion] if !ok { - return fmt.Errorf(`The git version can only be one of "<1.8.2", "<2.8.0", or "latest"`) + return fmt.Errorf(`the git version can only be one of "<1.8.2", "<2.8.0", or "latest"`) } config.Git = git diff --git a/splitter/result.go b/splitter/result.go index ed99ecf..7dbcabc 100644 --- a/splitter/result.go +++ b/splitter/result.go @@ -84,12 +84,12 @@ func roundDuration(d, r time.Duration) time.Duration { } neg := d < 0 if neg { - d = -d + d -= d } if m := d % r; m+m < r { - d = d - m + d -= m } else { - d = d + r - m + d += r - m } if neg { return -d diff --git a/splitter/state.go b/splitter/state.go index cd80647..89a0fa5 100644 --- a/splitter/state.go +++ b/splitter/state.go @@ -119,7 +119,7 @@ func (s *state) split() error { revWalk, err := s.walker() if err != nil { - return fmt.Errorf("Impossible to walk the repository: %s", err) + return fmt.Errorf("impossible to walk the repository: %s", err) } defer revWalk.Free() @@ -163,12 +163,12 @@ func (s *state) split() error { func (s *state) walker() (*git.RevWalk, error) { revWalk, err := s.repo.Walk() if err != nil { - return nil, fmt.Errorf("Impossible to walk the repository: %s", err) + return nil, fmt.Errorf("impossible to walk the repository: %s", err) } err = s.pushRevs(revWalk) if err != nil { - return nil, fmt.Errorf("Impossible to determine split range: %s", err) + return nil, fmt.Errorf("impossible to determine split range: %s", err) } revWalk.Sorting(git.SortTopological | git.SortReverse) @@ -320,7 +320,7 @@ func (s *state) mergeTrees(t1, t2 *git.Tree) (*git.Tree, error) { defer index.Free() if index.HasConflicts() { - return nil, fmt.Errorf("Cannot split as there is a merge conflict between two paths") + return nil, fmt.Errorf("cannot split as there is a merge conflict between two paths") } oid, err := index.WriteTreeTo(s.repo) @@ -373,7 +373,7 @@ func (s *state) copyOrSkip(rev *git.Commit, tree *git.Tree, newParents []*git.Oi continue } - if 0 == ptree.Cmp(tree.Id()) { + if ptree.Cmp(tree.Id()) == 0 { // an identical parent could be used in place of this rev. identical = parent } else { @@ -384,7 +384,7 @@ func (s *state) copyOrSkip(rev *git.Commit, tree *git.Tree, newParents []*git.Oi // eliminate duplicates isNew := true for _, gp := range gotParents { - if 0 == gp.Cmp(parent) { + if gp.Cmp(parent) == 0 { isNew = false break } @@ -405,7 +405,7 @@ func (s *state) copyOrSkip(rev *git.Commit, tree *git.Tree, newParents []*git.Oi if s.config.Git > 2 && nil != identical && nil != nonIdentical { revWalk, err := s.repo.Walk() if err != nil { - return nil, false, fmt.Errorf("Impossible to walk the repository: %s", err) + return nil, false, fmt.Errorf("impossible to walk the repository: %s", err) } s.repoMu.Lock() @@ -413,7 +413,7 @@ func (s *state) copyOrSkip(rev *git.Commit, tree *git.Tree, newParents []*git.Oi err = revWalk.PushRange(fmt.Sprintf("%s..%s", identical, nonIdentical)) if err != nil { - return nil, false, fmt.Errorf("Impossible to determine split range: %s", err) + return nil, false, fmt.Errorf("impossible to determine split range: %s", err) } err = revWalk.Iterate(func(rev *git.Commit) bool { @@ -494,7 +494,7 @@ func (s *state) updateTarget() error { } if nil == s.result.Head() { - return fmt.Errorf("Unable to create branch %s as it is empty (no commits were split)", s.config.Target) + return fmt.Errorf("unable to create branch %s as it is empty (no commits were split)", s.config.Target) } obj, ref, err := s.repo.RevparseExt(s.config.Target) diff --git a/splitter/utils.go b/splitter/utils.go index 3c9249f..00328de 100644 --- a/splitter/utils.go +++ b/splitter/utils.go @@ -63,7 +63,7 @@ func normalizeOriginBranch(repo *git.Repository, origin string) (string, error) obj, ref, err := repo.RevparseExt(origin) if err != nil { - return "", fmt.Errorf("Bad revision for origin: %s", err) + return "", fmt.Errorf("bad revision for origin: %s", err) } if obj != nil { obj.Free()