MCPcopy Index your code
hub / github.com/google/git-appraise / ArchiveRef

Method ArchiveRef

repository/git.go:398–433  ·  view source on GitHub ↗

ArchiveRef adds the current commit pointed to by the 'ref' argument under the ref specified in the 'archive' argument. Both the 'ref' and 'archive' arguments are expected to be the fully qualified names of git refs (e.g. 'refs/heads/my-change' or 'refs/devtools/archives/reviews'). If the ref point

(ref, archive string)

Source from the content-addressed store, hash-verified

396// If the ref pointed to by the 'archive' argument does not exist
397// yet, then it will be created.
398func (repo *GitRepo) ArchiveRef(ref, archive string) error {
399 refHash, err := repo.GetCommitHash(ref)
400 if err != nil {
401 return err
402 }
403 refDetails, err := repo.GetCommitDetails(ref)
404 if err != nil {
405 return err
406 }
407
408 commitTreeArgs := []string{"commit-tree"}
409 archiveHash, err := repo.GetCommitHash(archive)
410 if err != nil {
411 archiveHash = ""
412 } else {
413 if isAncestor, err := repo.IsAncestor(refHash, archiveHash); err != nil {
414 return err
415 } else if isAncestor {
416 // The ref has already been archived, so we have nothing to do
417 return nil
418 }
419 commitTreeArgs = append(commitTreeArgs, "-p", archiveHash)
420 }
421 commitTreeArgs = append(commitTreeArgs, "-p", refHash, "-m", fmt.Sprintf("Archive %s", refHash), refDetails.Tree)
422 newArchiveHash, err := repo.runGitCommand(commitTreeArgs...)
423 if err != nil {
424 return err
425 }
426 newArchiveHash = strings.TrimSpace(newArchiveHash)
427 updateRefArgs := []string{"update-ref", archive, newArchiveHash}
428 if archiveHash != "" {
429 updateRefArgs = append(updateRefArgs, archiveHash)
430 }
431 _, err = repo.runGitCommand(updateRefArgs...)
432 return err
433}
434
435// MergeRef merges the given ref into the current one.
436//

Callers

nothing calls this directly

Calls 4

GetCommitHashMethod · 0.95
GetCommitDetailsMethod · 0.95
IsAncestorMethod · 0.95
runGitCommandMethod · 0.95

Tested by

no test coverage detected