checkReferenceAndTruncate reads the reference from the given file, or the `pack-refs` file if the file was empty. Then it checks that the old reference matches the stored reference and truncates the file.
(f billy.File, old *plumbing.Reference)
| 680 | // the file was empty. Then it checks that the old reference matches the stored reference and |
| 681 | // truncates the file. |
| 682 | func (d *DotGit) checkReferenceAndTruncate(f billy.File, old *plumbing.Reference) error { |
| 683 | if old == nil { |
| 684 | return nil |
| 685 | } |
| 686 | |
| 687 | ref, err := d.readReferenceFrom(f, old.Name().String()) |
| 688 | if errors.Is(err, ErrEmptyRefFile) { |
| 689 | // This may happen if the reference is being read from a newly created file. |
| 690 | // In that case, try getting the reference from the packed refs file. |
| 691 | ref, err = d.packedRef(old.Name()) |
| 692 | } |
| 693 | |
| 694 | if err != nil { |
| 695 | return err |
| 696 | } |
| 697 | |
| 698 | if ref.Hash() != old.Hash() { |
| 699 | return storage.ErrReferenceHasChanged |
| 700 | } |
| 701 | _, err = f.Seek(0, io.SeekStart) |
| 702 | if err != nil { |
| 703 | return err |
| 704 | } |
| 705 | return f.Truncate(0) |
| 706 | } |
| 707 | |
| 708 | func (d *DotGit) SetRef(r, old *plumbing.Reference) error { |
| 709 | var content string |
no test coverage detected