Merge branch 'cauthmann/git-lfs-checks' into 'master'

Build script: check if git-lfs works

See merge request veloren/veloren!455
This commit is contained in:
Joshua Barretto 2019-08-22 18:18:51 +00:00
commit 8653c3e60a

View File

@ -1,10 +1,13 @@
use std::env; use std::env;
use std::fs::File; use std::fs::File;
use std::io::Read;
use std::io::Write; use std::io::Write;
use std::path::Path; use std::path::Path;
use std::path::PathBuf;
use std::process::Command; use std::process::Command;
fn main() { fn main() {
// Get the current githash
match Command::new("git") match Command::new("git")
.args(&["rev-parse", "--short", "HEAD"]) .args(&["rev-parse", "--short", "HEAD"])
.output() .output()
@ -26,4 +29,33 @@ fn main() {
}, },
Err(e) => panic!("failed to retrieve current git commit hash: {}", e), Err(e) => panic!("failed to retrieve current git commit hash: {}", e),
} }
// Check if git-lfs is working
let asset_path: PathBuf = ["..", "assets", "voxygen", "background", "bg_main.png"]
.iter()
.collect();
let asset_file = match File::open(&asset_path) {
Ok(file) => file,
Err(e) => panic!(
"failed to open asset file {}: {}",
asset_path.to_str().unwrap(),
e
),
};
const LFS_MARKER: &[u8] = b"version https://git-lfs.github.com/spec/";
let mut buffer = Vec::new();
let bytes_read = asset_file
.take(LFS_MARKER.len() as u64)
.read_to_end(&mut buffer)
.expect("failed to read asset file");
if bytes_read == LFS_MARKER.len() && buffer == LFS_MARKER {
panic!(
"\n\nGit Large File Storage (git-lfs) has not been set up correctly.\n\
Most common reasons:\n\
\t- git-lfs was not installed before cloning this repository\n\
\t- this repository was not cloned from the primary gitlab mirror.\n\
\t The github mirror does not support lfs.\n\
See the book at https://book.veloren.net/ for details.\n\n"
);
}
} }