Skip to content

Commit

Permalink
Create .gitattributes to ignore user config. (#55)
Browse files Browse the repository at this point in the history
* Create .gitattributes

* Auto download and repo renormalization

* Ensure to run both

* And here
  • Loading branch information
kuba6000 authored Aug 20, 2022
1 parent ed22d22 commit 7abb5fe
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 6 deletions.
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

0 comments on commit 7abb5fe

Please sign in to comment.