Skip to content

Commit fa25075

Browse files
peffgitster
authored andcommitted
fetch: report ref storage DF errors more accurately
When we fail to store a fetched ref, we recommend that the user try running "git prune" to remove up any old refs that have been deleted by the remote, which would clear up any DF conflicts. However, ref storage might fail for other reasons (e.g., permissions problems) in which case the advice is useless and misleading. This patch detects when there is an actual DF situation and only issues the advice when one is found. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f475e08 commit fa25075

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

builtin-fetch.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ static struct ref *get_ref_map(struct transport *transport,
167167
return ref_map;
168168
}
169169

170+
#define STORE_REF_ERROR_OTHER 1
171+
#define STORE_REF_ERROR_DF_CONFLICT 2
172+
170173
static int s_update_ref(const char *action,
171174
struct ref *ref,
172175
int check_old)
@@ -181,9 +184,11 @@ static int s_update_ref(const char *action,
181184
lock = lock_any_ref_for_update(ref->name,
182185
check_old ? ref->old_sha1 : NULL, 0);
183186
if (!lock)
184-
return 2;
187+
return errno == ENOTDIR ? STORE_REF_ERROR_DF_CONFLICT :
188+
STORE_REF_ERROR_OTHER;
185189
if (write_ref_sha1(lock, ref->new_sha1, msg) < 0)
186-
return 2;
190+
return errno == ENOTDIR ? STORE_REF_ERROR_DF_CONFLICT :
191+
STORE_REF_ERROR_OTHER;
187192
return 0;
188193
}
189194

@@ -377,7 +382,7 @@ static int store_updated_refs(const char *url, const char *remote_name,
377382
}
378383
}
379384
fclose(fp);
380-
if (rc & 2)
385+
if (rc & STORE_REF_ERROR_DF_CONFLICT)
381386
error("some local refs could not be updated; try running\n"
382387
" 'git remote prune %s' to remove any old, conflicting "
383388
"branches", remote_name);

0 commit comments

Comments
 (0)