Skip to content

Commit eb03804

Browse files
cgarlinggiordano
andauthored
Support git-lfs (large file storage) (#64)
* Support git-lfs (large file storage) * Update readme to state git LFS support * Silence lfs git tests * Check for CI private key in test * fix check on CI private key * update env var check * Read path from `git_cmd`, not global The path can be modified by preceding code, so we need to read it from `git_cmd`, append the `git-lfs` directory, then write back to `git_cmd`. * Try using `windows_verbatim` if git-lfs loaded CI issue could be related to single quotes in `cmd.exec` entries? * try removing single quotes from cmd.exec * revert quote filtering scheme * bump Julia compat to 1.8 Need bugfix to multiple calls to `addenv` on Windows * julia compat revision * Add CI job for Windows with Julia = 1.7.3 the `version: 'min'` jobs hit Julia 1.6.6 but we should also test against 1.7.3 on Windows to ensure the `addenv` calls are working * Implement Mose's suggestions Co-authored-by: Mosè Giordano <[email protected]>
1 parent d03efd1 commit eb03804

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ jobs:
5151
- os: ubuntu-22.04-arm
5252
arch: 'default'
5353
version: 'nightly'
54+
- os: windows-latest
55+
arch: 'default'
56+
version: '1.7.3'
5457
steps:
5558
- uses: actions/checkout@v4
5659
- uses: julia-actions/setup-julia@v2

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
name = "Git"
22
uuid = "d7ba0133-e1db-5d97-8f8c-041e4b3a1eb2"
3-
version = "1.4.0"
43
authors = ["Dilum Aluthge", "contributors"]
4+
version = "1.5.0"
55

66
[deps]
7+
Git_LFS_jll = "020c3dae-16b3-5ae5-87b3-4cb189e250b2"
78
Git_jll = "f8c6e375-362e-5223-8a59-34ff63f689eb"
89
JLLWrappers = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210"
910
OpenSSH_jll = "9bd350c2-7e96-507f-8002-3f2e150b4e1b"
1011

1112
[compat]
13+
Git_LFS_jll = "3.7"
1214
Git_jll = "2.44"
1315
JLLWrappers = "1.1"
1416
OpenSSH_jll = "9, 10"

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ not need to have Git installed on your computer, and neither do the users of
88
your packages!
99

1010
Git.jl provides a Git binary via
11-
[Git_jll.jl](https://github.com/JuliaBinaryWrappers/Git_jll.jl).
11+
[Git_jll.jl](https://github.com/JuliaBinaryWrappers/Git_jll.jl)
12+
and a Git LFS binary for large file support via
13+
[Git_LFS_jll.jl](https://github.com/JuliaBinaryWrappers/Git_LFS_jll.jl).
1214
The latest version of Git.jl requires at least Julia 1.6.
1315

1416
Git.jl is intended to work on any platform that supports Julia,

src/git_function.jl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using OpenSSH_jll: OpenSSH_jll
2+
using Git_LFS_jll: Git_LFS_jll
23
using JLLWrappers: pathsep, LIBPATH_env
34

45
"""
@@ -21,6 +22,9 @@ julia> run(git(["clone", "https://github.com/JuliaRegistries/General"]))
2122
to bypass the parsing of the command string.
2223
"""
2324
function git(; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true)
25+
path = split(get(ENV, "PATH", ""), pathsep)
26+
libpath = split(get(ENV, LIBPATH_env, ""), pathsep)
27+
2428
git_cmd = @static if Sys.iswindows()
2529
Git_jll.git(; adjust_PATH, adjust_LIBPATH)::Cmd
2630
else
@@ -53,20 +57,23 @@ function git(; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true)
5357

5458
# Use OpenSSH from the JLL: <https://github.com/JuliaVersionControl/Git.jl/issues/51>.
5559
if !Sys.iswindows() && OpenSSH_jll.is_available()
56-
path = split(get(ENV, "PATH", ""), pathsep)
57-
libpath = split(get(ENV, LIBPATH_env, ""), pathsep)
58-
5960
path = vcat(dirname(OpenSSH_jll.ssh_path), path)
6061
libpath = vcat(OpenSSH_jll.LIBPATH_list, libpath)
6162
path = vcat(dirname(Git_jll.git_path), path)
6263
libpath = vcat(Git_jll.LIBPATH_list, libpath)
6364

6465
unique!(filter!(!isempty, path))
6566
unique!(filter!(!isempty, libpath))
67+
end
6668

67-
git_cmd = addenv(git_cmd, "PATH" => join(path, pathsep), LIBPATH_env => join(libpath, pathsep))
69+
# Add git-lfs
70+
if Git_LFS_jll.is_available()
71+
path = vcat(dirname(Git_LFS_jll.git_lfs_path), path)
72+
unique!(filter!(!isempty, path))
6873
end
6974

75+
git_cmd = addenv(git_cmd, "PATH" => join(path, pathsep), LIBPATH_env => join(libpath, pathsep))
76+
7077
return git_cmd
7178
end
7279

test/runtests.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ end
3434
@test isdir("Git.jl")
3535
@test isfile(joinpath("Git.jl", "Project.toml"))
3636
end
37+
38+
# git-lfs tests
39+
withtempdir() do tmp_dir
40+
rname = "repo-with-large-file-storage"
41+
@test !isdir(rname)
42+
@test !isfile(joinpath(rname, "LargeFile.zip"))
43+
run(`$(git()) clone --quiet https://github.com/Apress/repo-with-large-file-storage`)
44+
run(pipeline(`$(git()) -C $rname lfs install --local`; stdout=devnull))
45+
run(pipeline(`$(git()) -C $rname lfs pull`; stdout=devnull))
46+
@test isdir(rname)
47+
@test isfile(joinpath(rname, "LargeFile.zip"))
48+
# Test filesize to make sure we got real file and not small LFS pointer file
49+
@test filesize(joinpath(rname, "LargeFile.zip")) > 10^6
50+
end
3751
end
3852

3953
@testset "Safety" begin

0 commit comments

Comments
 (0)