|
36 | 36 |
|
37 | 37 | start_dir=$(pwd) |
38 | 38 |
|
39 | | -# needed to access tar utility |
| 39 | +# All the file paths returned by the diff command are relative to the root |
| 40 | +# of the working copy. So if the script is called from a subdirectory, it |
| 41 | +# must switch to the root of working copy before trying to use those paths. |
40 | 42 | cdup=$(git rev-parse --show-cdup) && |
41 | 43 | cd "$cdup" || { |
42 | 44 | echo >&2 "Cannot chdir to $cdup, the toplevel of the working tree" |
43 | 45 | exit 1 |
44 | 46 | } |
45 | 47 |
|
46 | | -# mktemp is not available on all platforms (missing from msysgit) |
47 | | -# Use a hard-coded tmp dir if it is not available |
48 | | -tmp="$(mktemp -d -t tmp.XXXXXX 2>/dev/null)" || { |
49 | | - tmp=/tmp/git-diffall-tmp.$$ |
50 | | - mkdir "$tmp" || exit 1 |
51 | | -} |
52 | | - |
53 | | -trap 'rm -rf "$tmp" 2>/dev/null' EXIT |
| 48 | +# set up temp dir |
| 49 | +tmp=$(perl -e 'use File::Temp qw(tempdir); |
| 50 | + $t=tempdir("/tmp/git-diffall.XXXXX") or exit(1); |
| 51 | + print $t') || exit 1 |
| 52 | +trap 'rm -rf "$tmp"' EXIT |
54 | 53 |
|
55 | 54 | left= |
56 | 55 | right= |
|
180 | 179 | mkdir -p "$tmp/$left_dir" "$tmp/$right_dir" |
181 | 180 |
|
182 | 181 | # Populate the tmp/right_dir directory with the files to be compared |
183 | | -if test -n "$right" |
184 | | -then |
185 | | - while read name |
186 | | - do |
| 182 | +while read name |
| 183 | +do |
| 184 | + if test -n "$right" |
| 185 | + then |
187 | 186 | ls_list=$(git ls-tree $right "$name") |
188 | 187 | if test -n "$ls_list" |
189 | 188 | then |
190 | 189 | mkdir -p "$tmp/$right_dir/$(dirname "$name")" |
191 | 190 | git show "$right":"$name" >"$tmp/$right_dir/$name" || true |
192 | 191 | fi |
193 | | - done < "$tmp/filelist" |
194 | | -elif test -n "$compare_staged" |
195 | | -then |
196 | | - while read name |
197 | | - do |
| 192 | + elif test -n "$compare_staged" |
| 193 | + then |
198 | 194 | ls_list=$(git ls-files -- "$name") |
199 | 195 | if test -n "$ls_list" |
200 | 196 | then |
201 | 197 | mkdir -p "$tmp/$right_dir/$(dirname "$name")" |
202 | 198 | git show :"$name" >"$tmp/$right_dir/$name" |
203 | 199 | fi |
204 | | - done < "$tmp/filelist" |
205 | | -else |
206 | | - # Mac users have gnutar rather than tar |
207 | | - (tar --ignore-failed-read -c -T "$tmp/filelist" | (cd "$tmp/$right_dir" && tar -x)) || { |
208 | | - gnutar --ignore-failed-read -c -T "$tmp/filelist" | (cd "$tmp/$right_dir" && gnutar -x) |
209 | | - } |
210 | | -fi |
| 200 | + else |
| 201 | + if test -e "$name" |
| 202 | + then |
| 203 | + mkdir -p "$tmp/$right_dir/$(dirname "$name")" |
| 204 | + cp "$name" "$tmp/$right_dir/$name" |
| 205 | + fi |
| 206 | + fi |
| 207 | +done < "$tmp/filelist" |
211 | 208 |
|
212 | 209 | # Populate the tmp/left_dir directory with the files to be compared |
213 | 210 | while read name |
|
236 | 233 | fi |
237 | 234 | done < "$tmp/filelist" |
238 | 235 |
|
239 | | -cd "$tmp" |
240 | | -LOCAL="$left_dir" |
241 | | -REMOTE="$right_dir" |
| 236 | +LOCAL="$tmp/$left_dir" |
| 237 | +REMOTE="$tmp/$right_dir" |
242 | 238 |
|
243 | 239 | if test -n "$diff_tool" |
244 | 240 | then |
|
0 commit comments