Skip to content

Commit

Permalink
Add SHA1 version check to gerrit-upload
Browse files Browse the repository at this point in the history
Related: #48
Change-Id: Id09506e21af0c593e1aa7175a61d232ca1c0b655
  • Loading branch information
twmr committed Feb 21, 2024
1 parent 4a26e61 commit 8b33776
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
28 changes: 23 additions & 5 deletions gerrit.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down

0 comments on commit 8b33776

Please sign in to comment.