stash: prevent warning about null bytes in input

The `no_changes` function calls the `untracked_files` function through command substitution. `untracked_files` will return null bytes because it runs ls-files with the '-z' option. Bash since version 4.4 warns about these null bytes. As they are not required for the test that is being done, make sure `untracked_files` does not output null bytes when not required. This is achieved by adding a parameter to the `untracked_files` function to specify wither `-z` should be passed to ls-files or not. This warning is triggered when running git stash save -u resulting in two warnings: git-stash: line 43: warning: command substitution: ignored null byte in input Signed-off-by: Kevin Daudt <me@ikke.info> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Kevin Daudt committed Aug 14, 2017 at 23:43 UTC 5fc92f8828b117d042344e4733e16195b264365b
1 file changed +9 -2
git-stash.sh
+9 -2
@@ -43,9 +43,16 @@ no_changes () {
43 }
44
45 untracked_files () {
46 + if test "$1" = "-z"
47 + then
48 + shift
49 + z=-z
50 + else
51 + z=
52 + fi
53 excl_opt=--exclude-standard
54 test "$untracked" = "all" && excl_opt=
48 - git ls-files -o -z $excl_opt -- "$@"
55 + git ls-files -o $z $excl_opt -- "$@"
56 }
57
58 clear_stash () {
@@ -114,7 +121,7 @@ create_stash () {
121 # Untracked files are stored by themselves in a parentless commit, for
122 # ease of unpacking later.
123 u_commit=$(
117 - untracked_files "$@" | (
124 + untracked_files -z "$@" | (
125 GIT_INDEX_FILE="$TMPindex" &&
126 export GIT_INDEX_FILE &&
127 rm -f "$TMPindex" &&