emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 843f3d4: automerge: handle upstream changes during


From: Glenn Morris
Subject: [Emacs-diffs] master 843f3d4: automerge: handle upstream changes during operation
Date: Tue, 30 Jan 2018 21:43:39 -0500 (EST)

branch: master
commit 843f3d4f34c2f54fac19d97c32399671f98ccc51
Author: Glenn Morris <address@hidden>
Commit: Glenn Morris <address@hidden>

    automerge: handle upstream changes during operation
    
    * admin/automerge (merge): New function, split from pre-existing code.
    (main): If upstream changed during building and testing,
    reset local and try merging again.
---
 admin/automerge | 75 ++++++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 53 insertions(+), 22 deletions(-)

diff --git a/admin/automerge b/admin/automerge
index 54ac88d..94b41d2 100755
--- a/admin/automerge
+++ b/admin/automerge
@@ -1,5 +1,5 @@
 #!/bin/bash
-### automerge - merge the Emacs release branch to master
+### automerge - automatically merge the Emacs release branch to master
 
 ## Copyright (C) 2018 Free Software Foundation, Inc.
 
@@ -23,7 +23,12 @@
 ### Commentary:
 
 ## Automatically merge the Emacs release branch to master.
-## No warranty, etc.
+## If the merge succeeds, optionally build and test the results,
+## and then push it.
+## Intended usage:
+## Have a dedicated git directory just for this.
+## Have a cron job that does a hard reset (to clean up after any
+## previous failures), then a git pull, then calls this script with -p.
 
 die ()                 # write error to stderr and exit
 {
@@ -116,23 +121,35 @@ trap "rm -f $tempfile 2> /dev/null" EXIT
 }
 
 
-echo "Merging..."
+rev=$(git rev-parse HEAD)
 
-if $emacs --batch -Q -l ./admin/gitmerge.el \
-       --eval "(setq gitmerge-minimum-missing $nmin)" -f gitmerge \
-       >| $tempfile 2>&1; then
-    echo "merged ok"
+[ $(git rev-parse @{u}) = $rev ] || die "Local state does not match origin"
 
-else
-    grep -qE "Nothing to merge|Number of missing commits" $tempfile && {
-        echo "Fewer than $nmin commits to merge"
-        exit 0
-    }
 
-    cat "$tempfile" 1>&2
+merge ()
+{
+    echo "Merging..."
 
-    die "merge error"
-fi
+    if $emacs --batch -Q -l ./admin/gitmerge.el \
+              --eval "(setq gitmerge-minimum-missing $nmin)" -f gitmerge \
+              >| $tempfile 2>&1; then
+        echo "merged ok"
+        return 0
+
+    else
+        grep -qE "Nothing to merge|Number of missing commits" $tempfile && {
+            echo "Fewer than $nmin commits to merge"
+            exit 0
+        }
+
+        cat "$tempfile" 1>&2
+
+        die "merge error"
+    fi
+}
+
+
+merge
 
 
 [ "$build" ] || exit 0
@@ -181,14 +198,28 @@ echo "Tests finished ok"
 
 
 ## In case someone else pushed while we were working.
-#echo "Checking for remote changes..."
-#git fetch || die "fetch error"
-## NB If there were remote changes, this would rewrite the release
-## branch commits, which is not what we want.
-## Ref eg http://lists.gnu.org/r/emacs-devel/2014-12/msg01435.html
-## git >= 1.8.5 has "pull --rebase=preserve"
-#git rebase --preserve-merges || die "rebase error"
+echo "Checking for remote changes..."
+git fetch || die "fetch error"
+
+[ $(git rev-parse @{u}) = $rev ] || {
+
+    echo "Upstream has changed"
 
+    ## Rebasing would be incorrect, since it would rewrite the
+    ## (already published) release branch commits.
+    ## Ref eg http://lists.gnu.org/r/emacs-devel/2014-12/msg01435.html
+    ## Instead, we throw away what we just did, and do the merge again.
+    echo "Resetting..."
+    git reset --hard $rev
+
+    echo "Pulling..."
+    git pull --ff-only || die "pull error"
+
+    merge
+
+    ## If the merge finished ok again, we don't bother doing a second
+    ## build and test.
+}
 
 echo "Pushing..."
 git push || die "push error"



reply via email to

[Prev in Thread] Current Thread [Next in Thread]