MCPcopy Index your code
hub / github.com/dagger/dagger / Cleaned

Method Cleaned

core/git_local.go:82–202  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

80}
81
82func (repo *LocalGitRepository) Cleaned(ctx context.Context) (inst dagql.ObjectResult[*Directory], rerr error) {
83 srv := dagql.CurrentDagqlServer(ctx)
84 query, err := CurrentQuery(ctx)
85 if err != nil {
86 return inst, err
87 }
88 cache := query.SnapshotManager()
89
90 parent, err := repo.Directory.Self().Snapshot.GetOrEval(ctx, repo.Directory.Result)
91 if err != nil {
92 return inst, fmt.Errorf("get git directory snapshot: %w", err)
93 }
94 repoDirPath, err := repo.Directory.Self().Dir.GetOrEval(ctx, repo.Directory.Result)
95 if err != nil {
96 return inst, fmt.Errorf("get git directory path: %w", err)
97 }
98
99 bkref, err := cache.New(ctx, parent,
100 bkcache.WithRecordType(bkclient.UsageRecordTypeRegular),
101 bkcache.WithDescription("git cleaned worktree"))
102
103 if err != nil {
104 return inst, err
105 }
106 defer func() {
107 if rerr != nil && bkref != nil {
108 bkref.Release(context.WithoutCancel(ctx))
109 }
110 }()
111 skip := false
112 err = MountRef(ctx, bkref, func(parentRoot string, _ *mount.Mount) error {
113 src, err := fs.RootPath(parentRoot, repoDirPath)
114 if err != nil {
115 return err
116 }
117
118 git := gitutil.NewGitCLI(gitutil.WithDir(src))
119 worktree, err := git.WorkTree(ctx)
120 if err != nil {
121 return err
122 }
123 if worktree == "" {
124 skip = true // no worktree, no changes
125 return nil
126 }
127 gitDir, err := git.GitDir(ctx)
128 if err != nil {
129 return err
130 }
131
132 idx, err := os.Open(filepath.Join(gitDir, "index"))
133 if err != nil {
134 return err
135 }
136 defer idx.Close()
137
138 // NOTE: apply the index to a temp file because "git restore --staged"
139 // re-writes the index which we don't want to show up as a changed file

Callers

nothing calls this directly

Calls 15

WorkTreeMethod · 0.95
GitDirMethod · 0.95
NewMethod · 0.95
RunMethod · 0.95
OnReleaseMethod · 0.95
CurrentDagqlServerFunction · 0.92
NewGitCLIFunction · 0.92
WithDirFunction · 0.92
WithIndexFileFunction · 0.92
CurrentQueryFunction · 0.85
GetOrEvalMethod · 0.80

Tested by

no test coverage detected