Skip to content

resolveRef should be available through a mix-in #142

Open

Description

@binki

function resolveRef(repo, hashish, callback) {

To do something, I have to basically copy this entire function into my own code. It would be useful if this were available through a mix-in.

Activity

  1. binki commented on Jul 7, 2018

    @binki
    Author

    Hi, in fact I need more than resolveRef(). I need something to also expand intermediate refs so that I can expand, for example, HEAD which resolves to a ref. For example, this is what I am using now:

    function resolveRef(repo, ref) {
      // Shouldn’t js-git also expose some helper for this?
      if (/^[0-9a-f]{40}$/.test(ref)) {
        return ref;
      }
      const refRefMatch = /^ref: *(.*)$/.exec(ref);
      if (refRefMatch) {
        return resolveRef(repo, refRefMatch[1]);
      }
      return new Promise((resolve, reject) => repo.readRef(ref, (ex, ref) => ex ? reject(ex) : resolve(ref))).then(ref => {
        if (!ref) {
          // Indicates that the ref could not be resolved to a hash.
          return null;
        }
        return resolveRef(repo, ref);
      });
    }
    
    function resolveRefOrFail(repo, ref) {
      return resolveRef(repo, resolvedRef => {
        if (!resolvedRef) {
          throw new Error(`Unable to resolve ref ${ref}`);
        }
        return resolvedRef;
      });
    }
  2. TheKnarf commented on Jul 13, 2018

    @TheKnarf
    Collaborator

    Feel free to send a pull-request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions