mirror of
https://github.com/Smaug123/managed-git
synced 2025-10-11 10:48:42 +00:00
Rename main branch (#2)
This commit is contained in:
4
.github/workflows/dotnet.yml
vendored
4
.github/workflows/dotnet.yml
vendored
@@ -2,9 +2,9 @@ name: .NET
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ master ]
|
branches: [ main ]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ master ]
|
branches: [ main ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
@@ -79,3 +79,7 @@ module TestObject =
|
|||||||
for subStringEnd in 0 .. expected.Length - 1 do
|
for subStringEnd in 0 .. expected.Length - 1 do
|
||||||
property expected.[0..subStringEnd]
|
property expected.[0..subStringEnd]
|
||||||
|> shouldEqual true
|
|> shouldEqual true
|
||||||
|
|
||||||
|
expected.[0..subStringEnd].ToUpperInvariant ()
|
||||||
|
|> property
|
||||||
|
|> shouldEqual true
|
||||||
|
@@ -21,17 +21,21 @@ type Object =
|
|||||||
module Object =
|
module Object =
|
||||||
/// Get the object hashes which match this start.
|
/// Get the object hashes which match this start.
|
||||||
let disambiguate (r : Repository) (startOfHash : string) : Hash list =
|
let disambiguate (r : Repository) (startOfHash : string) : Hash list =
|
||||||
|
let objectDir = Repository.objectDir r
|
||||||
|
|
||||||
match startOfHash.Length with
|
match startOfHash.Length with
|
||||||
| 0 -> (Repository.objectDir r).EnumerateFiles ("*", SearchOption.AllDirectories)
|
| 0 -> objectDir.EnumerateFiles ("*", SearchOption.AllDirectories)
|
||||||
| 1 ->
|
| 1 ->
|
||||||
(Repository.objectDir r).EnumerateFiles ("*", SearchOption.AllDirectories)
|
if r.IsCaseSensitive then
|
||||||
|> Seq.filter (fun i ->
|
objectDir.EnumerateDirectories ("*", SearchOption.AllDirectories)
|
||||||
i.Directory.Name.Length > 0
|
|> Seq.filter (fun dir -> dir.Name.[0] = startOfHash.[0])
|
||||||
&& i.Directory.Name.[0] = startOfHash.[0]
|
|> Seq.collect (fun dir -> dir.EnumerateFiles "*")
|
||||||
)
|
else
|
||||||
|
objectDir.EnumerateDirectories (sprintf "%c*" startOfHash.[0], SearchOption.AllDirectories)
|
||||||
|
|> Seq.collect (fun dir -> dir.EnumerateFiles "*")
|
||||||
| 2 ->
|
| 2 ->
|
||||||
let subDir =
|
let subDir =
|
||||||
r.Fs.Path.Combine ((Repository.objectDir r).FullName, startOfHash)
|
r.Fs.Path.Combine (objectDir.FullName, startOfHash)
|
||||||
|> r.Fs.DirectoryInfo.FromDirectoryName
|
|> r.Fs.DirectoryInfo.FromDirectoryName
|
||||||
|
|
||||||
if subDir.Exists then
|
if subDir.Exists then
|
||||||
@@ -40,15 +44,19 @@ module Object =
|
|||||||
Seq.empty
|
Seq.empty
|
||||||
| _ ->
|
| _ ->
|
||||||
let prefix = startOfHash.Substring (0, 2)
|
let prefix = startOfHash.Substring (0, 2)
|
||||||
let suffix = startOfHash.Substring (2, startOfHash.Length - 2)
|
let suffix = startOfHash.Substring 2
|
||||||
|
|
||||||
let subDir =
|
let subDir =
|
||||||
r.Fs.Path.Combine ((Repository.objectDir r).FullName, prefix)
|
r.Fs.Path.Combine (objectDir.FullName, prefix)
|
||||||
|> r.Fs.DirectoryInfo.FromDirectoryName
|
|> r.Fs.DirectoryInfo.FromDirectoryName
|
||||||
|
|
||||||
if subDir.Exists then
|
if subDir.Exists then
|
||||||
subDir.EnumerateFiles ()
|
if r.IsCaseSensitive then
|
||||||
|> Seq.filter (fun i -> i.Name.StartsWith suffix)
|
subDir.EnumerateFiles ()
|
||||||
|
|> Seq.filter (fun i -> i.Name.StartsWith suffix)
|
||||||
|
else
|
||||||
|
subDir.EnumerateFiles ()
|
||||||
|
|> Seq.filter (fun i -> i.Name.StartsWith (suffix, true, null))
|
||||||
else
|
else
|
||||||
Seq.empty
|
Seq.empty
|
||||||
|
|
||||||
|
@@ -7,6 +7,7 @@ type Repository =
|
|||||||
private
|
private
|
||||||
{
|
{
|
||||||
Directory : IDirectoryInfo
|
Directory : IDirectoryInfo
|
||||||
|
IsCaseSensitive : bool
|
||||||
}
|
}
|
||||||
|
|
||||||
member this.Fs = this.Directory.FileSystem
|
member this.Fs = this.Directory.FileSystem
|
||||||
@@ -38,34 +39,37 @@ module Repository =
|
|||||||
output
|
output
|
||||||
|
|
||||||
let make (dir : IDirectoryInfo) : Repository option =
|
let make (dir : IDirectoryInfo) : Repository option =
|
||||||
if
|
let fs = dir.FileSystem
|
||||||
dir.Exists
|
let gitPath = fs.Path.Combine (dir.FullName, ".git")
|
||||||
&& dir.EnumerateDirectories ()
|
|
||||||
|> Seq.map (fun i -> i.Name)
|
if dir.Exists && fs.Directory.Exists gitPath then
|
||||||
|> Seq.contains ".git"
|
{
|
||||||
then
|
Directory = dir
|
||||||
Some { Directory = dir }
|
IsCaseSensitive =
|
||||||
|
// Yes, if someone's made both `.git` and `.GIT` then we may think
|
||||||
|
// the filesystem is case insensitive.
|
||||||
|
not (fs.Directory.Exists (gitPath.ToUpperInvariant ()))
|
||||||
|
}
|
||||||
|
|> Some
|
||||||
else
|
else
|
||||||
None
|
None
|
||||||
|
|
||||||
let init (dir : IDirectoryInfo) : Result<Repository, InitFailure> =
|
let init (dir : IDirectoryInfo) : Result<Repository, InitFailure> =
|
||||||
|
match make dir with
|
||||||
|
| Some _ -> Error AlreadyGit
|
||||||
|
| None ->
|
||||||
|
|
||||||
if not dir.Exists then
|
if not dir.Exists then
|
||||||
Error DirectoryDoesNotExist
|
Error DirectoryDoesNotExist
|
||||||
elif
|
|
||||||
not
|
|
||||||
<| Seq.isEmpty (dir.EnumerateDirectories ".git")
|
|
||||||
then
|
|
||||||
Error AlreadyGit
|
|
||||||
else
|
else
|
||||||
|
|
||||||
let r = { Directory = dir }
|
// TODO do this atomically
|
||||||
|
|
||||||
let gitDir = createSubdir dir ".git"
|
let gitDir = createSubdir dir ".git"
|
||||||
let objectDir = createSubdir gitDir "objects"
|
let objectDir = createSubdir gitDir "objects"
|
||||||
let packDir = createSubdir objectDir "pack"
|
let _packDir = createSubdir objectDir "pack"
|
||||||
let infoDir = createSubdir objectDir "info"
|
let _infoDir = createSubdir objectDir "info"
|
||||||
let refsDir = createSubdir gitDir "refs"
|
let refsDir = createSubdir gitDir "refs"
|
||||||
let headsDir = createSubdir refsDir "heads"
|
let _headsDir = createSubdir refsDir "heads"
|
||||||
let tagsDir = createSubdir refsDir "tags"
|
let _tagsDir = createSubdir refsDir "tags"
|
||||||
|
|
||||||
r |> Ok
|
make dir |> Option.get |> Ok
|
||||||
|
Reference in New Issue
Block a user