pockethub/PocketHub · error · IOException

Reference does not have associated commit SHA-1

Error message

Reference does not have associated commit SHA-1

What it means

getValidRef() fetches a GitReference from the GitHub API and validates that it carries an object SHA-1 via isValidRef(). If the response body parses but the ref has no associated commit SHA (e.g. a symbolic/unresolvable ref), it throws this IOException. It signals an unexpected/invalid API payload rather than a network failure.

Solutions

  1. Verify the branch/tag actually exists and points to a commit (check via web UI or 'git ls-remote').
  2. Inspect isValidRef() and the ref payload; confirm the object type is 'commit'.
  3. Handle the IOException in the RxJava error consumer and fall back to a default ref (e.g. default branch).
  4. Refresh/re-fetch after repo changes; the ref may have been deleted concurrently.

Example fix

// before
ref = task.getValidRef(repo, refName).blockingGet();
// after
GitReference fetchedRef;
try {
    fetchedRef = task.getValidRef(repo, refName).blockingGet();
} catch (IOException e) {
    fetchedRef = task.getValidRef(repo, repo.getDefaultBranch()).blockingGet();
}
Defensive patterns

Strategy: retry

Validate before calling

// verify ref exists via ls-remote or API before use:
// git ls-remote origin refs/heads/<branch>

Type guard

fun isValidRef(ref: GitReference?): Boolean =
    ref?.`object`?.sha?.isNotEmpty() == true

Try / catch

try {
    single.blockingGet()
} catch (IOException e) {
    // fall back to default branch
}

Prevention

When it happens

Trigger: GET of a branch/tag ref returns HTTP 200 but the returned GitReference has a null or malformed object SHA — e.g. ref points at an object type other than a commit, or the API returns a partial body.

Common situations: Repository with an empty branch, renamed/deleted branch still referenced, tag pointing at a blob/tree, or API schema changes (GitHub returns ref without commit object).

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


AI-assisted analysis of pockethub/PocketHub@8228cb8f71 (2026-09-11). Data as JSON: /api/errors/333954ccdc19978d. Report an issue: GitHub.

Appendix: source

Thrown at app/src/main/java/com/github/pockethub/android/core/code/RefreshTreeTask.java:80

        this.repo = repository;
        this.reference = reference;
    }

    private boolean isValidRef(GitReference ref) {
        return ref != null && ref.object() != null
                && !TextUtils.isEmpty(ref.object().sha());
    }

    private Single<GitReference> getValidRef(GitService service, GitReference ref, String branch) {
        if (!isValidRef(ref)) {
            return service.getGitReference(repo.owner().login(), repo.name(), branch)
                    .map(response -> {
                        if (response.isSuccessful()) {
                            GitReference fetchedRef = response.body();
                            if (isValidRef(fetchedRef)) {
                                return fetchedRef;
                            } else {
                                throw new IOException("Reference does not have associated commit SHA-1");
                            }
                        } else {
                            throw new IOException("Request for Git Reference was unsuccessful");
                        }
                    });
        }

        return Single.just(ref);
    }

    private Single<String> getBranch(GitReference ref) {
        String branch = RefUtils.getPath(ref);
        if (branch == null) {
            branch = repo.defaultBranch();
            if (TextUtils.isEmpty(branch)) {
                return ServiceGenerator
                        .createService(context, RepositoryService.class)
                        .getRepository(repo.owner().login(), repo.name())

View on GitHub (pinned to 8228cb8f71)