Its impossible for basePath to be on a different file system than tmp.  Above we construct tmp to be a temporary file in the same directory as the file named by basePath.  No system that I know of permits a single directory to have its file contents spread across different file systems such that a rename within that directory would fail.

Its sufficient here to assume that all files in the same directory are part of the same filesystem, and that we can rename safely from a unique temporary file name in that directory to a stable name within the same directory.  If that fails, its either because the stable name already exists (made at the same time by another thread or process perhaps?) OR the filesystem is utter crap and we can't work with it.  In the former case we'll just retry to read the file made by the other process, and probably succeed at using it.  In the latter case, well, the filesystem is utter crap.  If I can't rename a file in the same directory, I can't provide most of the data safety rules that Git normally provides.  Users should get a better filesystem.