@@ -1090,6 +1090,15 @@ int delete_ref(const char *refname, const unsigned char *sha1, int delopt)
10901090 return ret ;
10911091}
10921092
1093+ /*
1094+ * People using contrib's git-new-workdir have .git/logs/refs ->
1095+ * /some/other/path/.git/logs/refs, and that may live on another device.
1096+ *
1097+ * IOW, to avoid cross device rename errors, the temporary renamed log must
1098+ * live into logs/refs.
1099+ */
1100+ #define TMP_RENAMED_LOG "logs/refs/.tmp-renamed-log"
1101+
10931102int rename_ref (const char * oldref , const char * newref , const char * logmsg )
10941103{
10951104 static const char renamed_ref [] = "RENAMED-REF" ;
@@ -1123,8 +1132,8 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg)
11231132 if (write_ref_sha1 (lock , orig_sha1 , logmsg ))
11241133 return error ("unable to save current sha1 in %s" , renamed_ref );
11251134
1126- if (log && rename (git_path ("logs/%s" , oldref ), git_path ("tmp-renamed-log" )))
1127- return error ("unable to move logfile logs/%s to tmp-renamed-log : %s" ,
1135+ if (log && rename (git_path ("logs/%s" , oldref ), git_path (TMP_RENAMED_LOG )))
1136+ return error ("unable to move logfile logs/%s to " TMP_RENAMED_LOG " : %s" ,
11281137 oldref , strerror (errno ));
11291138
11301139 if (delete_ref (oldref , orig_sha1 , REF_NODEREF )) {
@@ -1150,7 +1159,7 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg)
11501159 }
11511160
11521161 retry :
1153- if (log && rename (git_path ("tmp-renamed-log" ), git_path ("logs/%s" , newref ))) {
1162+ if (log && rename (git_path (TMP_RENAMED_LOG ), git_path ("logs/%s" , newref ))) {
11541163 if (errno == EISDIR || errno == ENOTDIR ) {
11551164 /*
11561165 * rename(a, b) when b is an existing
@@ -1163,7 +1172,7 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg)
11631172 }
11641173 goto retry ;
11651174 } else {
1166- error ("unable to move logfile tmp-renamed-log to logs/%s: %s" ,
1175+ error ("unable to move logfile " TMP_RENAMED_LOG " to logs/%s: %s" ,
11671176 newref , strerror (errno ));
11681177 goto rollback ;
11691178 }
@@ -1203,8 +1212,8 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg)
12031212 error ("unable to restore logfile %s from %s: %s" ,
12041213 oldref , newref , strerror (errno ));
12051214 if (!logmoved && log &&
1206- rename (git_path ("tmp-renamed-log" ), git_path ("logs/%s" , oldref )))
1207- error ("unable to restore logfile %s from tmp-renamed-log : %s" ,
1215+ rename (git_path (TMP_RENAMED_LOG ), git_path ("logs/%s" , oldref )))
1216+ error ("unable to restore logfile %s from " TMP_RENAMED_LOG " : %s" ,
12081217 oldref , strerror (errno ));
12091218
12101219 return 1 ;
0 commit comments