Skip to content

Commit

Permalink
GradleLintPatchAction: attach executable metadata if we modify an exe…
Browse files Browse the repository at this point in the history
…cutable file (#407)
  • Loading branch information
rpalcolea authored Jul 24, 2024
1 parent 9a80404 commit 4546dfb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ class GradleLintPatchAction extends GradleLintViolationAction {
headers += "deleted file mode ${fileMode.mode}"
break
case Update:
// no hint necessary
if(fileMode == FileMode.Executable) {
headers += "new mode ${fileMode.mode}"
}
break
}
return headers.collect { "|$it" }.join('\n')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -797,4 +797,40 @@ class GradleLintPatchActionSpec extends Specification {
+e
'''.substring(1).stripIndent()
}
def 'replace honors file mode when executable'() {
setup:
def f = temp.newFile('my.sh')
f.setExecutable(true)
f.text = '''\
a
b
c
'''.stripIndent()
def changes = '''\
hello
multiline
'''.stripIndent()
when:
def lines = f.readLines()
def fix = new GradleLintReplaceWith(violation, f, 1..lines.size(), 1, lines[-1].length() + 1, changes)
def patch = new GradleLintPatchAction(project).patch([fix])
then:
patch == '''
diff --git a/my.sh b/my.sh
new mode 100755
--- a/my.sh
+++ b/my.sh
@@ -1,3 +1,2 @@
-a
-b
-c
+hello
+multiline
'''.substring(1).stripIndent()
}
}

0 comments on commit 4546dfb

Please sign in to comment.