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

Method Run

util/gitutil/cli.go:204–318  ·  view source on GitHub ↗

Run executes a git command with the given args.

(ctx context.Context, args ...string)

Source from the content-addressed store, hash-verified

202
203// Run executes a git command with the given args.
204func (cli *GitCLI) Run(ctx context.Context, args ...string) (_ []byte, rerr error) {
205 ctx, span := Tracer(ctx).Start(ctx, strings.Join(append([]string{"git"}, args...), " "), trace.WithAttributes(
206 attribute.Bool(telemetry.UIEncapsulatedAttr, true),
207 ))
208 defer telemetry.EndWithCause(span, &rerr)
209
210 stdio := telemetry.SpanStdio(ctx, InstrumentationLibrary)
211 defer stdio.Close()
212
213 gitBinary := "git"
214 if cli.git != "" {
215 gitBinary = cli.git
216 }
217 proxyEnvVars := [...]string{
218 "HTTP_PROXY", "HTTPS_PROXY", "NO_PROXY", "ALL_PROXY",
219 "http_proxy", "https_proxy", "no_proxy", "all_proxy",
220 }
221
222 var cmd *exec.Cmd
223 if cli.exec == nil {
224 cmd = exec.CommandContext(ctx, gitBinary)
225 } else {
226 cmd = exec.Command(gitBinary)
227 }
228
229 cmd.Dir = cli.dir
230 if cmd.Dir == "" {
231 cmd.Dir = cli.workTree
232 }
233
234 // Block sneaky repositories from using repos from the filesystem as submodules.
235 cmd.Args = append(cmd.Args, "-c", "protocol.file.allow=user")
236 if cli.workTree != "" {
237 cmd.Args = append(cmd.Args, "--work-tree", cli.workTree)
238 }
239 if cli.gitDir != "" {
240 cmd.Args = append(cmd.Args, "--git-dir", cli.gitDir)
241 }
242 cmd.Args = append(cmd.Args, cli.args...)
243 cmd.Args = append(cmd.Args, args...)
244
245 buf := bytes.NewBuffer(nil)
246 errbuf := bytes.NewBuffer(nil)
247 cmd.Stdin = nil
248 cmd.Stdout = io.MultiWriter(buf, stdio.Stdout)
249 cmd.Stderr = io.MultiWriter(errbuf, stdio.Stderr)
250 if cli.streams != nil {
251 stdout, stderr, flush := cli.streams(ctx)
252 if stdout != nil {
253 cmd.Stdout = io.MultiWriter(stdout, cmd.Stdout)
254 }
255 if stderr != nil {
256 cmd.Stderr = io.MultiWriter(stderr, cmd.Stderr)
257 }
258 defer stdout.Close()
259 defer stderr.Close()
260 defer func() {
261 if rerr != nil {

Callers 6

refJoinFunction · 0.95
CleanedMethod · 0.95
initRemoteMethod · 0.95
LsRemoteMethod · 0.95
WorkTreeMethod · 0.95
GitDirMethod · 0.95

Calls 14

MergeGitConfigEnvFunction · 0.85
translateErrorFunction · 0.85
BytesMethod · 0.80
TracerFunction · 0.70
getGitSSHCommandFunction · 0.70
StartMethod · 0.65
BoolMethod · 0.65
CloseMethod · 0.65
GetenvMethod · 0.65
RunMethod · 0.65
DoneMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected