summaryrefslogtreecommitdiff
path: root/transport.c
diff options
context:
space:
mode:
authorSrinidhi Kaushik <shrinidhi.kaushik@gmail.com>2020-10-03 12:10:44 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-10-03 16:59:18 (GMT)
commit99a1f9ae10816c2527d7197a5dde714f980b712b (patch)
tree95c75afca2199d9e9531266c4d7d5390a7d6c6f2 /transport.c
parentaed0800ca68806a7bc1dc15995417b9171f22079 (diff)
downloadgit-99a1f9ae10816c2527d7197a5dde714f980b712b.zip
git-99a1f9ae10816c2527d7197a5dde714f980b712b.tar.gz
git-99a1f9ae10816c2527d7197a5dde714f980b712b.tar.bz2
push: add reflog check for "--force-if-includes"
Add a check to verify if the remote-tracking ref of the local branch is reachable from one of its "reflog" entries. The check iterates through the local ref's reflog to see if there is an entry for the remote-tracking ref and collecting any commits that are seen, into a list; the iteration stops if an entry in the reflog matches the remote ref or if the entry timestamp is older the latest entry of the remote ref's "reflog". If there wasn't an entry found for the remote ref, "in_merge_bases_many()" is called to check if it is reachable from the list of collected commits. When a local branch that is based on a remote ref, has been rewound and is to be force pushed on the remote, "--force-if-includes" runs a check that ensures any updates to the remote-tracking ref that may have happened (by push from another repository) in-between the time of the last update to the local branch (via "git-pull", for instance) and right before the time of push, have been integrated locally before allowing a forced update. If the new option is passed without specifying "--force-with-lease", or specified along with "--force-with-lease=<refname>:<expect>" it is a "no-op". Signed-off-by: Srinidhi Kaushik <shrinidhi.kaushik@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'transport.c')
-rw-r--r--transport.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/transport.c b/transport.c
index ffe2115..65fcd22 100644
--- a/transport.c
+++ b/transport.c
@@ -633,6 +633,11 @@ static int print_one_push_report(struct ref *ref, const char *dest, int count,
"stale info",
report, porcelain, summary_width);
break;
+ case REF_STATUS_REJECT_REMOTE_UPDATED:
+ print_ref_status('!', "[rejected]", ref, ref->peer_ref,
+ "remote ref updated since checkout",
+ report, porcelain, summary_width);
+ break;
case REF_STATUS_REJECT_SHALLOW:
print_ref_status('!', "[rejected]", ref, ref->peer_ref,
"new shallow roots not allowed",
@@ -1185,6 +1190,7 @@ static int run_pre_push_hook(struct transport *transport,
if (!r->peer_ref) continue;
if (r->status == REF_STATUS_REJECT_NONFASTFORWARD) continue;
if (r->status == REF_STATUS_REJECT_STALE) continue;
+ if (r->status == REF_STATUS_REJECT_REMOTE_UPDATED) continue;
if (r->status == REF_STATUS_UPTODATE) continue;
strbuf_reset(&buf);