Skip to content

Commit

Permalink
add UpdateBranchHash (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
JunNishimura committed Jun 10, 2023
1 parent 8d1f43c commit 201e7ba
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions internal/store/refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,26 @@ func (r *Refs) DeleteBranch(rootGoitPath, headBranchName, deleteBranchName strin

return nil
}

func (r *Refs) UpdateBranchHash(rootGoitPath, branchName string, newHash sha.SHA1) error {
n := r.getBranchPos(branchName)
if n == NewBranchFlag {
return fmt.Errorf("branch '%s' does not exist", branchName)
}

branch := r.Heads[n]
branch.hash = newHash

branchPath := filepath.Join(rootGoitPath, "refs", "heads", branchName)
f, err := os.Create(branchPath)
if err != nil {
return fmt.Errorf("fail to create %s: %w", branchPath, err)
}
defer f.Close()

if _, err := f.WriteString(newHash.String()); err != nil {
return fmt.Errorf("fail to write hash: %w", err)
}

return nil
}

0 comments on commit 201e7ba

Please sign in to comment.