| 163 | } |
| 164 | |
| 165 | void Repository::fastForwardToTrackedRemote() |
| 166 | { |
| 167 | auto head = getHead(); |
| 168 | if (!head) throw GitException(_("Could not retrieve HEAD reference from repository")); |
| 169 | |
| 170 | auto upstream = head->getUpstream(); |
| 171 | if (!upstream) throw GitException(_("No tracked remote branch configured")); |
| 172 | |
| 173 | // Lookup the target object |
| 174 | git_oid targetOid; |
| 175 | git_reference_name_to_id(&targetOid, _repository, upstream->getName().c_str()); |
| 176 | |
| 177 | git_object* target; |
| 178 | auto error = git_object_lookup(&target, _repository, &targetOid, GIT_OBJECT_COMMIT); |
| 179 | GitException::ThrowOnError(error); |
| 180 | |
| 181 | rMessage() << "Fast-fowarding " << head->getName() << " to upstream " << upstream->getName() << std::endl; |
| 182 | |
| 183 | try |
| 184 | { |
| 185 | // Checkout the result so the workdir is in the expected state |
| 186 | git_checkout_options checkoutOptions = GIT_CHECKOUT_OPTIONS_INIT; |
| 187 | checkoutOptions.checkout_strategy = GIT_CHECKOUT_SAFE; |
| 188 | |
| 189 | error = git_checkout_tree(_repository, target, &checkoutOptions); |
| 190 | GitException::ThrowOnError(error); |
| 191 | |
| 192 | // Move the target reference to the target OID |
| 193 | head->setTarget(&targetOid); |
| 194 | |
| 195 | rMessage() << "Fast-foward done, " << head->getName() << " is now at " << Reference::OidToString(&targetOid) << std::endl; |
| 196 | } |
| 197 | catch (const GitException& ex) |
| 198 | { |
| 199 | git_object_free(target); |
| 200 | throw ex; |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | RefSyncStatus Repository::getSyncStatusOfBranch(const Reference& reference) |
| 205 | { |
no test coverage detected