diff --git a/README.md b/README.md index 2e4ca63..802311f 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ February 2024: * Add `gerrit-rest-change-get-description` and `gerrit-rest-change-set-description`. +* `gerrit-upload`: Do nothing if remote SHA1 matches SHA1 of HEAD. Dezember 2023: diff --git a/gerrit.el b/gerrit.el index 87a69d3..a3b2f5d 100644 --- a/gerrit.el +++ b/gerrit.el @@ -1356,11 +1356,29 @@ workspace of the project." (defun gerrit-upload () (interactive) - (condition-case err - (gerrit-get-changeid-from-current-commit) - (error - (gerrit--ensure-commit-msg-hook-exists) ;; create commit-msg hook - (error (error-message-string err)))) + + ;; Sanity checks: + ;; * Check if the latest commit contains a ChangeId in the commit msg. + ;; * Check if the sha1 of the latest PS on the server is the same as + ;; the SHA1 of the local HEAD. + (let* ((changeid + (condition-case err + (gerrit-get-unique-changeid-from-current-commit) + (error + (gerrit--ensure-commit-msg-hook-exists) ;; create commit-msg hook + (error (error-message-string err))))) + (change-info + (condition-case nil + (gerrit-rest-get-change-info changeid) + (error nil))) + (remote-revision (alist-get 'current_revision change-info)) + (current-revision (magit-rev-parse "HEAD"))) + + (when (and remote-revision current-revision) + ;; (message "Remote revision: %s\nCurrent revision: %s" + ;; remote-revision current-revision) + (when (string= remote-revision current-revision) + (error "The remote change/relation-chain is up to date.")))) (call-interactively #'gerrit-upload-transient))