| 202 | } |
| 203 | |
| 204 | RefSyncStatus Repository::getSyncStatusOfBranch(const Reference& reference) |
| 205 | { |
| 206 | RefSyncStatus status; |
| 207 | |
| 208 | auto trackedBranch = reference.getUpstream(); |
| 209 | |
| 210 | if (!trackedBranch) throw GitException(_("The current branch doesn't track a remote, cannot check sync status")); |
| 211 | |
| 212 | git_revwalk* walker = nullptr; |
| 213 | git_revwalk_new(&walker, _repository); |
| 214 | |
| 215 | // Start from remote |
| 216 | git_revwalk_push_ref(walker, trackedBranch->getName().c_str()); |
| 217 | |
| 218 | // End at local |
| 219 | git_oid refOid; |
| 220 | git_reference_name_to_id(&refOid, _repository, reference.getName().c_str()); |
| 221 | git_revwalk_hide(walker, &refOid); |
| 222 | |
| 223 | git_oid id; |
| 224 | while (!git_revwalk_next(&id, walker)) |
| 225 | { |
| 226 | //rMessage() << Reference::OidToString(&id) << " => "; |
| 227 | ++status.remoteCommitsAhead; |
| 228 | } |
| 229 | //rMessage() << std::endl; |
| 230 | |
| 231 | git_revwalk_free(walker); |
| 232 | |
| 233 | // Another walk from local to remote |
| 234 | git_revwalk_new(&walker, _repository); |
| 235 | |
| 236 | git_revwalk_push(walker, &refOid); |
| 237 | git_revwalk_hide_ref(walker, trackedBranch->getName().c_str()); |
| 238 | |
| 239 | while (!git_revwalk_next(&id, walker)) |
| 240 | { |
| 241 | //rMessage() << Reference::OidToString(&id) << " => "; |
| 242 | ++status.localCommitsAhead; |
| 243 | } |
| 244 | //rMessage() << std::endl; |
| 245 | |
| 246 | git_revwalk_free(walker); |
| 247 | |
| 248 | // Initialise the convenience flags |
| 249 | status.localIsUpToDate = status.localCommitsAhead == 0 && status.remoteCommitsAhead == 0; |
| 250 | status.localCanBePushed = status.localCommitsAhead > 0 && status.remoteCommitsAhead == 0; |
| 251 | |
| 252 | return status; |
| 253 | } |
| 254 | |
| 255 | bool Repository::isUpToDateWithRemote() |
| 256 | { |
no test coverage detected