mirror of
https://github.com/Smaug123/managed-git
synced 2025-10-15 20:58:42 +00:00
A bit of professionalisation (#1)
This commit is contained in:
@@ -14,6 +14,7 @@ type SymbolicRef =
|
||||
| OrigHead
|
||||
// TODO - determine how an arbitrary symbolicref actually behaves
|
||||
| Verbatim of string
|
||||
|
||||
override this.ToString () : string =
|
||||
match this with
|
||||
| CherryPickHead -> "CHERRY_PICK_HEAD"
|
||||
@@ -28,7 +29,9 @@ type SymbolicRef =
|
||||
module SymbolicRef =
|
||||
let getFile (r : Repository) (name : SymbolicRef) : IFileInfo =
|
||||
name.ToString ()
|
||||
|> fun i -> r.Fs.Path.Combine ((Repository.gitDir r).FullName, i) |> r.Fs.FileInfo.FromFileName
|
||||
|> fun i ->
|
||||
r.Fs.Path.Combine ((Repository.gitDir r).FullName, i)
|
||||
|> r.Fs.FileInfo.FromFileName
|
||||
|
||||
type SymbolicRefLookupError =
|
||||
| RefDidNotExist
|
||||
@@ -40,18 +43,21 @@ module SymbolicReference =
|
||||
/// This is effectively `git symbolic-ref NAME`.
|
||||
let lookup (r : Repository) (name : SymbolicRef) : Result<SymbolicRefTarget, SymbolicRefLookupError> =
|
||||
let f = SymbolicRef.getFile r name
|
||||
if not <| f.Exists then Error RefDidNotExist
|
||||
|
||||
if not <| f.Exists then
|
||||
Error RefDidNotExist
|
||||
else
|
||||
r.Fs.File.ReadAllText f.FullName
|
||||
|> fun contents ->
|
||||
if contents.Substring (0, 5) = "ref: " then contents.Substring 5 |> SymbolicRefTarget |> Ok
|
||||
if contents.Substring (0, 5) = "ref: " then
|
||||
contents.Substring 5 |> SymbolicRefTarget |> Ok
|
||||
else
|
||||
Error (MalformedRef contents)
|
||||
|
||||
let write (r : Repository) (name : SymbolicRef) (contents : string) : unit =
|
||||
if not <| contents.StartsWith "refs/" then
|
||||
failwithf "refusing to point %O outside of refs/" name
|
||||
|
||||
r.Fs.File.WriteAllText ((SymbolicRef.getFile r name).FullName, sprintf "ref: %s" contents)
|
||||
|
||||
let delete (r : Repository) (name : SymbolicRef) : unit =
|
||||
(SymbolicRef.getFile r name).Delete ()
|
||||
let delete (r : Repository) (name : SymbolicRef) : unit = (SymbolicRef.getFile r name).Delete ()
|
||||
|
Reference in New Issue
Block a user