Skip to content

Commit 8c5f6f7

Browse files
crorvickgitster
authored andcommitted
push: flag updates that require force
Add a flag for indicating an update to a reference requires force. Currently the `nonfastforward` flag is used for this when generating the status message. A separate flag insulates dependent logic from the details of set_ref_status_for_push(). Signed-off-by: Chris Rorvick <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ffe81ef commit 8c5f6f7

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

cache.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,9 @@ struct ref {
999999
unsigned char old_sha1[20];
10001000
unsigned char new_sha1[20];
10011001
char *symref;
1002-
unsigned int force:1,
1002+
unsigned int
1003+
force:1,
1004+
requires_force:1,
10031005
merge:1,
10041006
nonfastforward:1,
10051007
not_forwardable:1,

remote.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,6 +1293,8 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
12931293
struct ref *ref;
12941294

12951295
for (ref = remote_refs; ref; ref = ref->next) {
1296+
int force_ref_update = ref->force || force_update;
1297+
12961298
if (ref->peer_ref)
12971299
hashcpy(ref->new_sha1, ref->peer_ref->new_sha1);
12981300
else if (!send_mirror)
@@ -1335,9 +1337,12 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
13351337
!has_sha1_file(ref->old_sha1)
13361338
|| !ref_newer(ref->new_sha1, ref->old_sha1);
13371339

1338-
if (ref->nonfastforward && !ref->force && !force_update) {
1339-
ref->status = REF_STATUS_REJECT_NONFASTFORWARD;
1340-
continue;
1340+
if (ref->nonfastforward) {
1341+
ref->requires_force = 1;
1342+
if (!force_ref_update) {
1343+
ref->status = REF_STATUS_REJECT_NONFASTFORWARD;
1344+
continue;
1345+
}
13411346
}
13421347
}
13431348
}

transport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ static void print_ok_ref_status(struct ref *ref, int porcelain)
659659
const char *msg;
660660

661661
strcpy(quickref, status_abbrev(ref->old_sha1));
662-
if (ref->nonfastforward) {
662+
if (ref->requires_force) {
663663
strcat(quickref, "...");
664664
type = '+';
665665
msg = "forced update";

0 commit comments

Comments
 (0)