ref: free the last ref when cancelling git_branch_foreach()

Also fixed an assert typo on nulltoken's HEAD
Merge pull request #1655 from yorah/fix/ref-memleak

ref: free the last ref when cancelling git_branch_foreach()