let pointer = try LFSPointer(fromFile: URL(fileURLWithPath: "path/to/file"))
The pointer is represented as a Swift struct.
public struct LFSPointer {
/// The version of the pointer. Example: "https://git-lfs.github.com/spec/v1".
public let version: String
/// An SHA 256 hash for the pointer.
public let oid: String
/// The size of the converted file.
public let size: Int
/// The name of the file.
public let filename: String
/// The full path of the file.
public let filePath: String
/// String representation of this pointer.
public var stringRep: String
...
}
Folder Conversion
To convert a folder of files to pointers, you could write:
let pointer = try LFSPointer(...)
try JSONEncoder().encode(pointer)
and to convert an array of LFSPointers:
let pointers = try LFSPointer.pointers(...)
JSONEncoder().encode(pointers)
The JSON for the LFSPointer array will be structured as shown here, and the JSON for the single LFSPointer will be structured as shown here.
Command Line
If you want to use the Docker image, prefix all the following commands with: docker run --rm -v $(pwd):/src -w /src ghcr.io/lebje/lfs-pointers:latest <command>
Let’s imagine you have a directory of large png and jpg files called Project Logos. If you wanted to convert the files with the extension png to LFS pointers, you could run
. The first argument is the path to the directory, and the second argument is a regular expression used to search for png files that your shell will convert to a list of filenames. But wait! It’s not safe to run random programs on your computer! To backup your files just in case something goes wrong, add -b path/to/backup-directory to the previous command, like this:
LFS Pointers
A Swift library and CLI that allows you to convert a Git repository of large files to Git LFS pointers.
4.0.1 is the last release in which the executable is named
LFSPointers
. All future releases will name itlfs-pointers
.Table of Contents
Created by gh-md-toc
It it recommended that you read the Git-LFS Homepage before continuing.
Install Program
Mint
Homebrew
If you would like to install from
HEAD
then make sureswift --version
succeeds (Install Swift otherwise) then run:From DEB or RPM
DEB
RPM
Manually
Build Using Docker
If you are on Ubuntu 16.04, 18.04, 20.04, or CentOS 8, you can build
LFSPointers
using:Ubuntu 16.04
Ubuntu 18.04
Ubuntu 20.04
CentOS 8
Then run
mv .build/release/LFSPointers .
to move the binary to your current directory.Build Without Docker
If you don’t or can’t use Docker, you can Install Swift, then run:
The binary will be located at
/path/to/LFSPointers/.build/release/LFSPointers
.Build on Windows
Install Swift, open
Windows Powershell
, navigate to the directory that containsLFSPointers
, and run:the executable will be located at
C:\path\to\LFSPointers\.build\release\LFSPointers.exe
.From GitHub Release
Simply download the release asset. The binary is statically linked, so there is no need to install additional software.
Setup Shell Completions
ZSH
Oh My ZSH
Create a file called
~/.oh-my-zsh/completions/_LFSPointers
, then run:Without Oh My ZSH
Add
to your
.zshrc
, then create~/.zsh/completion
, and run:Bash
Create a directory to store Bash completions, (
~/.bash_completions/
), and add this to your.bashrc
or.bash_profile
:, then run:
Install Library
Swift Package Manager
Add this to the
dependencies
array inPackage.swift
:. Also add this to the
targets
array in the aforementioned file:Usage
Library
Import
File Conversion
To convert a file to a pointer you could write:
The pointer is represented as a Swift
struct
.Folder Conversion
To convert a folder of files to pointers, you could write:
The search types available are:
That function returns an array of
LFSPointer
s.Writing Pointers
After you generate a pointer, write it to a file using:
Generating JSON
To convert a pointer to JSON:
and to convert an array of
LFSPointer
s:The JSON for the
LFSPointer
array will be structured as shown here, and the JSON for the singleLFSPointer
will be structured as shown here.Command Line
If you want to use the Docker image, prefix all the following commands with:
docker run --rm -v $(pwd):/src -w /src ghcr.io/lebje/lfs-pointers:latest <command>
Let’s imagine you have a directory of large
png
andjpg
files calledProject Logos
. If you wanted to convert the files with the extensionpng
to LFS pointers, you could run. The first argument is the path to the directory, and the second argument is a regular expression used to search for
png
files that your shell will convert to a list of filenames.But wait! It’s not safe to run random programs on your computer! To backup your files just in case something goes wrong, add
-b path/to/backup-directory
to the previous command, like this:If you want to generate JSON output instead, run:
The JSON will be structured as shown here.
Dependencies
More Information
Run
LFSPointers --help
.Tested Platforms
Mac
Tested on MacOS 10.15 and 11, using Swift 5.2 and 5.3.
Linux
Tested on Ubuntu 18.04 (
x86_64
andaarch64
), also using Swift 5.2 and 5.3.iOS
This project has not been tested on iOS yet, although, at the time of writing the sample project in
Samples/FileToPointer
is currently working.Windows
LFSPointers
is currently being built and tested on Windows, but there are a few problems:C:\Users\user\file
=>C:/Users/user/file
JSON Structure for LFSPointer Array
JSON Structure for Single LFSPointer
Install Swift
Download Swift, then follow the instructions for your platform:
Linux (
aarch64
)More information at swift-arm64.
Ubuntu
Contributing
Before committing, please install pre-commit, and swift-format and install the pre-commit hook:
To install pre-commit on other platforms, refer to the documentation.