github.com/google/syzkaller@v0.0.0-20251211124644-a066d2bc4b02/syz-cluster/pkg/triage/git.go (about) 1 // Copyright 2024 syzkaller project authors. All rights reserved. 2 // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4 package triage 5 6 import ( 7 "fmt" 8 "os" 9 10 "github.com/google/syzkaller/pkg/vcs" 11 "github.com/google/syzkaller/syz-cluster/pkg/api" 12 ) 13 14 type GitTreeOps struct { 15 *vcs.Git 16 } 17 18 func NewGitTreeOps(dir string, sandbox bool) (*GitTreeOps, error) { 19 ops := &GitTreeOps{ 20 Git: &vcs.Git{ 21 Dir: dir, 22 // TODO: why doesn't sandbox=true work normally under go tests? 23 Sandbox: sandbox, 24 Env: os.Environ(), 25 }, 26 } 27 err := ops.Reset() 28 return ops, err 29 } 30 31 func (ops *GitTreeOps) HeadCommit(tree *api.Tree) (*vcs.Commit, error) { 32 // See kernel-disk/cron.yaml. 33 return ops.Git.Commit(tree.Name + "/" + tree.Branch) 34 } 35 36 func (ops *GitTreeOps) Commit(treeName, commitOrBranch string) (*vcs.Commit, error) { 37 // See kernel-disk/cron.yaml. 38 if vcs.CheckCommitHash(commitOrBranch) { 39 return ops.Git.Commit(commitOrBranch) 40 } 41 return ops.Git.Commit(treeName + "/" + commitOrBranch) 42 } 43 44 func (ops *GitTreeOps) ApplySeries(commit string, patches [][]byte) error { 45 ops.Reset() 46 _, err := ops.Run("reset", "--hard", commit) 47 if err != nil { 48 return err 49 } 50 for i, patch := range patches { 51 err := ops.Apply(patch) 52 if err != nil { 53 return fmt.Errorf("failed to apply patch %d: %w", i, err) 54 } 55 } 56 return nil 57 }