MCPcopy
hub / github.com/harness/harness / RawDiff

Method RawDiff

git/api/diff.go:160–268  ·  view source on GitHub ↗

nolint:gocognit

(
	ctx context.Context,
	w io.Writer,
	repoPath string,
	baseRef string,
	headRef string,
	mergeBase bool,
	ignoreWhitespace bool,
	alternates []string,
	files ...FileDiffRequest,
)

Source from the content-addressed store, hash-verified

158
159//nolint:gocognit
160func (g *Git) RawDiff(
161 ctx context.Context,
162 w io.Writer,
163 repoPath string,
164 baseRef string,
165 headRef string,
166 mergeBase bool,
167 ignoreWhitespace bool,
168 alternates []string,
169 files ...FileDiffRequest,
170) error {
171 if repoPath == "" {
172 return ErrRepositoryPathEmpty
173 }
174
175 baseTag, err := g.GetAnnotatedTag(ctx, repoPath, baseRef)
176 if err == nil {
177 baseRef = baseTag.TargetSHA.String()
178 }
179
180 headTag, err := g.GetAnnotatedTag(ctx, repoPath, headRef)
181 if err == nil {
182 headRef = headTag.TargetSHA.String()
183 }
184
185 cmd := command.New("diff",
186 command.WithFlag("-M"),
187 command.WithFlag("--full-index"),
188 command.WithAlternateObjectDirs(alternates...),
189 )
190 if mergeBase {
191 cmd.Add(command.WithFlag("--merge-base"))
192 }
193
194 if ignoreWhitespace {
195 // Ignore whitespace when comparing lines.
196 cmd.Add(command.WithFlag("-w"))
197 }
198
199 perFileDiffRequired := false
200 paths := make([]string, 0, len(files))
201 if len(files) > 0 {
202 for _, file := range files {
203 paths = append(paths, file.Path)
204 if file.StartLine > 0 || file.EndLine > 0 {
205 perFileDiffRequired = true
206 }
207 }
208 }
209
210 processed := 0
211
212again:
213 startLine := 0
214 endLine := 0
215
216 newCmd := cmd.Clone()
217

Callers

nothing calls this directly

Calls 15

GetAnnotatedTagMethod · 0.95
NewFunction · 0.92
WithFlagFunction · 0.92
WithAlternateObjectDirsFunction · 0.92
WithArgFunction · 0.92
WithPostSepArgFunction · 0.92
WithDirFunction · 0.92
WithStdoutFunction · 0.92
AsErrorFunction · 0.92
NotFoundFunction · 0.92
processGitErrorfFunction · 0.85
cutLinesFromFullFileDiffFunction · 0.85

Tested by

no test coverage detected