1

Since mina uses local deployment code, it would be useful if before deployments a check would run ensuring both local branch and origin branch (on github) are in sync.

So far I have solved this by defining a checker method in deploy.rb

def heads_match?
  `git fetch`     
  if `git diff #{branch} origin/#{branch}`.size < 1
    puts "Yay, HEADs match"
    return true
  else
    puts "Noo, Branches are not in sync"
    return false
  end
end

And calling in the deploy task

task :deploy => :environment do
  if heads_match?
    deploy do          
      # Rest of deployment code here
    end
  end
end

The problem is that git fetch takes several seconds and is probably overhead if I could get by with checking whether last commits of local branch and remote branch are the same.

How to check local and remote branch last commit equality quickly?

Epigene
  • 3,634
  • 1
  • 26
  • 31
  • [This discussion](http://stackoverflow.com/questions/3258243/check-if-pull-needed-in-git?lq=1) on checking git pull necessity is promising. – Epigene May 17 '16 at 10:03

1 Answers1

1

You can only check for this using git fetch, but you do not need to merge the changes if you don't want to.

This answer for a similar question states that the easiest way to do this is by running:

git fetch origin

# See if there are any incoming changes
git log HEAD..origin/master --oneline

If you want to do this with other methods, you'll have to hit GitHub with a REST client, in order to check if the last commit matches your local one, but that's a bit of heavy scripting compared to the simple command above and in my opinion git fetch shouldn't take long in a normal network setup in a repo that doesn't contain large files.

Hope this helps.

Community
  • 1
  • 1
bitoiu
  • 6,893
  • 5
  • 38
  • 60