Skip to content

Commit 2ff6c34

Browse files
l0b0gitster
authored andcommitted
userdiff: support Bash
Support POSIX, bashism and mixed function declarations, all four compound command types, trailing comments and mixed whitespace. Even though Bash allows locale-dependent characters in function names <https://unix.stackexchange.com/a/245336/3645>, only detect function names with characters allowed by POSIX.1-2017 <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_235> for simplicity. This should cover the vast majority of use cases, and produces system-agnostic results. Since a word pattern has to be specified, but there is no easy way to know the default word pattern, use the default `IFS` characters for a starter. A later patch can improve this. Signed-off-by: Victor Engmark <[email protected]> Acked-by: Johannes Sixt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 69986e1 commit 2ff6c34

18 files changed

+91
-0
lines changed

Documentation/gitattributes.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,9 @@ patterns are available:
802802

803803
- `ada` suitable for source code in the Ada language.
804804

805+
- `bash` suitable for source code in the Bourne-Again SHell language.
806+
Covers a superset of POSIX shell function definitions.
807+
805808
- `bibtex` suitable for files with BibTeX coded references.
806809

807810
- `cpp` suitable for source code in the C and C++ languages.

t/t4018-diff-funcname.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ test_expect_success 'setup' '
2727

2828
diffpatterns="
2929
ada
30+
bash
3031
bibtex
3132
cpp
3233
csharp

t/t4018/bash-arithmetic-function

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
RIGHT() ((
2+
3+
ChangeMe = "$x" + "$y"
4+
))

t/t4018/bash-bashism-style-compact

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function RIGHT {
2+
function InvalidSyntax{
3+
:
4+
echo 'ChangeMe'
5+
}
6+
}

t/t4018/bash-bashism-style-function

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
function RIGHT {
2+
:
3+
echo 'ChangeMe'
4+
}

t/t4018/bash-bashism-style-whitespace

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
function RIGHT ( ) {
2+
3+
ChangeMe
4+
}

t/t4018/bash-conditional-function

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
RIGHT() [[ \
2+
3+
"$a" > "$ChangeMe"
4+
]]

t/t4018/bash-missing-parentheses

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function RIGHT {
2+
functionInvalidSyntax {
3+
:
4+
echo 'ChangeMe'
5+
}
6+
}

t/t4018/bash-mixed-style-compact

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
function RIGHT(){
2+
:
3+
echo 'ChangeMe'
4+
}

t/t4018/bash-mixed-style-function

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
function RIGHT() {
2+
3+
ChangeMe
4+
}

0 commit comments

Comments
 (0)