push: flag updates that require force
[gitweb.git] / remote.c
index 04fd9ea4bd2f99003c9c5abb7bbbad7dafca3937..4a6f822089c076c10417cee6afc7a09de9777120 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -1279,12 +1279,22 @@ int match_push_refs(struct ref *src, struct ref **dst,
        return 0;
 }
 
+static inline int is_forwardable(struct ref* ref)
+{
+       if (!prefixcmp(ref->name, "refs/tags/"))
+               return 0;
+
+       return 1;
+}
+
 void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
        int force_update)
 {
        struct ref *ref;
 
        for (ref = remote_refs; ref; ref = ref->next) {
+               int force_ref_update = ref->force || force_update;
+
                if (ref->peer_ref)
                        hashcpy(ref->new_sha1, ref->peer_ref->new_sha1);
                else if (!send_mirror)
@@ -1316,15 +1326,24 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
                 *     always allowed.
                 */
 
-               ref->nonfastforward =
-                       !ref->deletion &&
-                       !is_null_sha1(ref->old_sha1) &&
-                       (!has_sha1_file(ref->old_sha1)
-                         || !ref_newer(ref->new_sha1, ref->old_sha1));
+               ref->not_forwardable = !is_forwardable(ref);
 
-               if (ref->nonfastforward && !ref->force && !force_update) {
-                       ref->status = REF_STATUS_REJECT_NONFASTFORWARD;
-                       continue;
+               ref->update =
+                       !ref->deletion &&
+                       !is_null_sha1(ref->old_sha1);
+
+               if (ref->update) {
+                       ref->nonfastforward =
+                               !has_sha1_file(ref->old_sha1)
+                                 || !ref_newer(ref->new_sha1, ref->old_sha1);
+
+                       if (ref->nonfastforward) {
+                               ref->requires_force = 1;
+                               if (!force_ref_update) {
+                                       ref->status = REF_STATUS_REJECT_NONFASTFORWARD;
+                                       continue;
+                               }
+                       }
                }
        }
 }