Skip to content

Commit 950b568

Browse files
davvidgitster
authored andcommitted
mergetools/p4merge: Honor $TMPDIR for the /dev/null placeholder
Use $TMPDIR when creating the /dev/null placeholder for p4merge. This prevents users from finding a seemingly random untracked file in their worktree. This is different than what mergetool does with $LOCAL and $REMOTE because those files exist to aid users when resolving merges. p4merge's /dev/null placeholder is not helpful in that situation so it is sensible to keep it out of the worktree. Reported-by: Jeremy Morton <[email protected]> Signed-off-by: David Aguilar <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 18499ba commit 950b568

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

mergetools/p4merge

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
11
diff_cmd () {
2+
empty_file=
3+
24
# p4merge does not like /dev/null
3-
rm_local=
4-
rm_remote=
55
if test "/dev/null" = "$LOCAL"
66
then
7-
LOCAL="./p4merge-dev-null.LOCAL.$$"
8-
>"$LOCAL"
9-
rm_local=true
7+
LOCAL="$(create_empty_file)"
108
fi
119
if test "/dev/null" = "$REMOTE"
1210
then
13-
REMOTE="./p4merge-dev-null.REMOTE.$$"
14-
>"$REMOTE"
15-
rm_remote=true
11+
REMOTE="$(create_empty_file)"
1612
fi
1713

1814
"$merge_tool_path" "$LOCAL" "$REMOTE"
1915

20-
if test -n "$rm_local"
21-
then
22-
rm -f "$LOCAL"
23-
fi
24-
if test -n "$rm_remote"
16+
if test -n "$empty_file"
2517
then
26-
rm -f "$REMOTE"
18+
rm -f "$empty_file"
2719
fi
2820
}
2921

@@ -33,3 +25,10 @@ merge_cmd () {
3325
"$merge_tool_path" "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
3426
check_unchanged
3527
}
28+
29+
create_empty_file () {
30+
empty_file="${TMPDIR:-/tmp}/git-difftool-p4merge-empty-file.$$"
31+
>"$empty_file"
32+
33+
printf "$empty_file"
34+
}

0 commit comments

Comments
 (0)