UEScripts/ue4-git-setup.ps1

224 lines
4.6 KiB
PowerShell
Raw Normal View History

2020-05-21 17:54:00 +01:00
[CmdletBinding()] # Fail on unknown args
param (
[string]$src,
# Ignore project structure problems
[switch]$skipstructurecheck = $false,
[switch]$overwriteprops = $false,
[switch]$dryrun = $false,
[switch]$help = $false
)
function Print-Usage {
Write-Output "Steve's UE4 Git Repo Setup Tool"
Write-Output " Run this on your just-created UE4 project folder."
Write-Output " .gitattributes and .gitignore will be overwritten"
Write-Output "Usage:"
Write-Output " ue4-git-setup.ps1 [[-src:]sourcefolder] [Options]"
Write-Output " "
Write-Output " -src : Source folder (current folder if omitted)"
Write-Output " : (should be root of trunk in new repo)"
Write-Output " -dryrun : Don't perform any actual actions, just report on what you would do"
Write-Output " -help : Print this help"
}
$gitPluginURL = "git@github.com:sinbad/UE4GitPlugin.git"
$gitPluginBranch = "ue4_24-fixes"
2020-05-21 17:54:00 +01:00
$gitlfs_notlocked = @"
*.fbx
*.zip
*.bmp
*.afphoto
*.exr
*.dll
*.mlt
*.png
*.jpg
*.afdesign
*.blend
*.wav
*.pdf
*.tiff
*.mp3
"@
$gitlfs_locked = @"
*.uasset
*.umap
"@
$gitignore = @"
# Visual Studio
.vs/
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
*.ipa
# These project files can be generated by the engine
*.xcodeproj
*.xcworkspace
*.sln
*.suo
*.opensdf
*.sdf
*.VC.db
*.VC.opendb
# Binary Files
Binaries/*
Plugins/*/Binaries/*
# Builds
Build/*
# Whitelist PakBlacklist-<BuildConfiguration>.txt files
!Build/*/
Build/*/**
!Build/*/PakBlacklist*.txt
# Don't ignore icon files in Build
!Build/**/*.ico
# Built data for maps
*_BuiltData.uasset
# Configuration files generated by the Editor
Saved/*
# Compiled source files for the engine to use
Intermediate/*
Plugins/*/Intermediate/*
# Cache files for the editor to use
DerivedDataCache/*
# Localisation intermediate / export files
Content/Localization/**/*.csv
Content/Localization/**/*.po
Content/Localization/**/*.archive
# Temp files
*.blend1
# Exported files in Content
Content/**/*.bmp
Content/**/*.png
Content/**/*.jpg
Content/**/*.tif
Content/**/*.tiff
Content/**/*.tga
Content/**/*.fbx
Content/**/*.exr
Content/**/*.mp3
Content/**/*.wav
"@
if ($help) {
Print-Usage
Exit 0
}
if (-not (Get-Module -ListAvailable -Name PsIni)) {
Write-Output "Missing module: PsIni"
Write-Output "This script uses PsIni to update the UE4 DefaultEngine.ini"
Write-Output "Install it using 'Install-Module PsIni [-Scope CurrentUser]'"
Exit 2
}
2020-05-21 17:54:00 +01:00
if ($src.Length -eq 0) {
$src = "."
Write-Verbose "-src not specified, assuming current directory"
}
$ErrorActionPreference = "Stop"
if ($src -ne ".") {
Push-Location $src
if ($LASTEXITCODE -ne 0) {
Write-Output "ERROR: Unable to change directory to '$src', exiting"
Exit 1
}
}
try {
# Check if we're a git repo already
if (-not (Test-Path ".git")) {
Write-Output "Creating git repo"
git init
}
# Add .gitignore FIRST before LFS
# Otherwise lockable files that are ignored can be made read-only
Write-Output "Creating .gitignore"
Set-Content .gitignore $gitignore
# init LFS
Write-Output "Enabling Git LFS"
git lfs install
# track, including lockable types
Write-Output "Tracking Git LFS Files"
foreach($f in $gitlfs_notlocked -split "\r?\n") {
git lfs track "$f"
}
foreach($f in $gitlfs_locked -split "\r?\n") {
git lfs track --lockable "$f"
}
# Configure DefaultEngine.ini to make Git LFS operations MUCH faster
# [SystemSettingsEditor]
# r.Editor.SkipSourceControlCheckForEditablePackages = 1
# Seriously, without this saving a locked LFS file takes ~5s vs 0.5s
Import-Module PsIni
$engineIni = Get-IniContent "Config/DefaultEngine.ini"
$engineIni["SystemSettingsEditor"] = @{"r.Editor.SkipSourceControlCheckForEditablePackages" = "1"}
Out-IniFile -Force -InputObject $engineIni -FilePath "Config/DefaultEngine.ini"
# git submodule UE4Plugin
if (!(Test-Path "Plugins/UE4GitPlugin/GitSourceControl.uplugin")) {
Write-Output "Checking out $gitPluginURL/$gitPluginBranch..."
if (!(Test-Path Plugins)) {
New-Item -ItemType Directory Plugins > $null
}
git submodule add -b $gitPluginBranch $gitPluginURL Plugins/UE4GitPlugin
}
2020-05-21 17:54:00 +01:00
} catch {
Write-Output $_.Exception.Message
Exit 9
}
if ($src -ne ".") { Pop-Location }