0b0af4df6aab075d257d4a0dcfd1bf42318fc69a

Author
Marc Cornellà <hello@mcornella.com>
Committer
Marc Cornellà <hello@mcornella.com>
Date

Message

fix(updater): fix check for latest commit in local repository

The previous check simply compared whether the last commit of the branch
was the same in the local and the remote repository.

This commit also checks whether the remote commit is an ancestor of the
local commit. This fixes the case where the local repository has new
commits after the last published commit.

Diff

 1diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh
 2index 2ad1fca9288b43d2b0043b97cb435d7b94a68260..76d42d3884d353534b2cdd654d97c58be58162bc 100644
 3--- a/tools/check_for_upgrade.sh
 4+++ b/tools/check_for_upgrade.sh
 5@@ -75,8 +75,17 @@ function is_update_available() {
 6     fi
 7   ) || return 1
 8 
 9-  # Compare local and remote HEADs
10-  [[ "$local_head" != "$remote_head" ]]
11+  # Compare local and remote HEADs (if they're equal there are no updates)
12+  [[ "$local_head" != "$remote_head" ]] || return 1
13+
14+  # If local and remote HEADs don't match, check if there's a common ancestor
15+  # If the merge-base call fails, $remote_head might not be downloaded so assume there are updates
16+  local base
17+  base=$(cd -q "$ZSH"; git merge-base $local_head $remote_head 2>/dev/null) || return 0
18+
19+  # If the common ancestor ($base) is not $remote_head,
20+  # the local HEAD is older than the remote HEAD
21+  [[ $base != $remote_head ]]
22 }
23 
24 function update_last_updated_file() {