@@ -16,7 +16,12 @@ int asDirectReference(git_reference **out, git_reference *ref) {
1616 return git_reference_dup (out, ref);
1717 }
1818
19- return git_reference_resolve (out, ref);
19+ int error = git_reference_resolve (out, ref);
20+ if (error != GIT_OK) {
21+ *out = NULL ;
22+ }
23+
24+ return GIT_OK;
2025}
2126
2227int lookupDirectReferenceByShorthand (git_reference **out, git_repository *repo, const char *shorthand) {
@@ -442,7 +447,7 @@ void GitRepository::RefreshReferencesWorker::Execute()
442447 git_reference *headRef = NULL ;
443448 baton->error_code = lookupDirectReferenceByShorthand (&headRef, repo, " HEAD" );
444449
445- if (baton->error_code != GIT_OK) {
450+ if (baton->error_code != GIT_OK || headRef == NULL ) {
446451 if (giterr_last () != NULL ) {
447452 baton->error = git_error_dup (giterr_last ());
448453 }
@@ -472,7 +477,7 @@ void GitRepository::RefreshReferencesWorker::Execute()
472477
473478 // START Refresh CHERRY_PICK_HEAD
474479 git_reference *cherrypickRef = NULL ;
475- if (lookupDirectReferenceByShorthand (&cherrypickRef, repo, " CHERRY_PICK_HEAD" ) == GIT_OK) {
480+ if (lookupDirectReferenceByShorthand (&cherrypickRef, repo, " CHERRY_PICK_HEAD" ) == GIT_OK && cherrypickRef != NULL ) {
476481 baton->error_code = RefreshedRefModel::fromReference (&refreshData->cherrypick , cherrypickRef, odb);
477482 git_reference_free (cherrypickRef);
478483 } else {
@@ -483,7 +488,7 @@ void GitRepository::RefreshReferencesWorker::Execute()
483488 // START Refresh MERGE_HEAD
484489 git_reference *mergeRef = NULL ;
485490 // fall through if cherry pick failed
486- if (baton->error_code == GIT_OK && lookupDirectReferenceByShorthand (&mergeRef, repo, " MERGE_HEAD" ) == GIT_OK) {
491+ if (baton->error_code == GIT_OK && lookupDirectReferenceByShorthand (&mergeRef, repo, " MERGE_HEAD" ) == GIT_OK && mergeRef != NULL ) {
487492 baton->error_code = RefreshedRefModel::fromReference (&refreshData->merge , mergeRef, odb);
488493 git_reference_free (mergeRef);
489494 } else {
@@ -536,6 +541,10 @@ void GitRepository::RefreshReferencesWorker::Execute()
536541 if (baton->error_code != GIT_OK) {
537542 break ;
538543 }
544+ if (reference == NULL ) {
545+ // lookup found the reference but failed to resolve it directly
546+ continue ;
547+ }
539548
540549 UpstreamModel *upstreamModel;
541550 if (UpstreamModel::fromReference (&upstreamModel, reference)) {
0 commit comments