Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create .gitattributes to ignore user config. #55

Merged
merged 4 commits into from
Aug 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
* text eol=lf

*.jar binary

*.png binary
*.jpg binary
*.jpeg binary
*.gif binary
*.tif binary
*.tiff binary
*.ico binary
*.svg text
*.eps binary

*.kar binary
*.m4a binary
*.mid binary
*.midi binary
*.mp3 binary
*.ogg binary
*.ra binary

*.7z binary
*.gz binary
*.tar binary
*.tgz binary
*.zip binary

*.patch -text

*.bat text eol=crlf
*.cmd text eol=crlf
*.ps1 text eol=crlf

*autogenerated binary
32 changes: 26 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ plugins {
id 'com.github.gmazzo.buildconfig' version '3.0.3' apply false
id 'com.diffplug.spotless' version '6.7.2' apply false
}
verifySettingsGradle()
if(verifySettingsGradle() || verifyGitAttributes())
throw new GradleException("Settings has been updated, please re-run task.")

dependencies {
implementation 'com.diffplug:blowdryer:1.6.0'
Expand Down Expand Up @@ -666,28 +667,47 @@ if (!project.getGradle().startParameter.isOffline() && isNewBuildScriptVersionAv
}

static URL availableBuildScriptUrl() {
new URL("https://raw.githubusercontent.com/GTNewHorizons/ExampleMod1.7.10/main/build.gradle")
new URL("https://raw.githubusercontent.com/GTNewHorizons/ExampleMod1.7.10/master/build.gradle")
}
static URL exampleSettingsGradleUrl() {
new URL("https://raw.githubusercontent.com/GTNewHorizons/ExampleMod1.7.10/main/settings.gradle.example")
new URL("https://raw.githubusercontent.com/GTNewHorizons/ExampleMod1.7.10/master/settings.gradle.example")
}
static URL exampleGitAttributesUrl() {
new URL("https://raw.githubusercontent.com/GTNewHorizons/ExampleMod1.7.10/master/.gitattributes")
}


def verifySettingsGradle() {
boolean verifyGitAttributes() {
def gitattributesFile = getFile(".gitattributes")
if (!gitattributesFile.exists()) {
println("Downloading default .gitattributes")
exampleGitAttributesUrl().withInputStream { i -> gitattributesFile.withOutputStream { it << i } }
exec {
workingDir '.'
commandLine 'git', 'add', '--renormalize', '.'
}
return true
}
return false
}

boolean verifySettingsGradle() {
def settingsFile = getFile("settings.gradle")
if (!settingsFile.exists()) {
println("Downloading default settings.gradle")
exampleSettingsGradleUrl().withInputStream { i -> settingsFile.withOutputStream { it << i } }
throw new GradleException("Settings.gradle has been updated, please re-run task.")
return true
}
return false
}

boolean performBuildScriptUpdate(String projectDir) {
if (isNewBuildScriptVersionAvailable(projectDir)) {
def buildscriptFile = getFile("build.gradle")
availableBuildScriptUrl().withInputStream { i -> buildscriptFile.withOutputStream { it << i } }
out.style(Style.Success).print("Build script updated. Please REIMPORT the project or RESTART your IDE!")
verifySettingsGradle()
if(verifySettingsGradle() || verifyGitAttributes())
throw new GradleException("Settings has been updated, please re-run task.")
return true
}
return false
Expand Down