FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

`options` not reusable, nodegit destroys it · Issue #533 · nodegit/nodegit · GitHub

Repository navigation

options not reusable, nodegit destroys it #533

Description

https://github.com/nodegit/nodegit/blob/master/lib/clone.js#L21

Why are you doing this? This prevents reuse, e.g. I want to clone, and then fetch.

let remoteOpts = {
    remoteCallbacks: {
        certificateCheck: function () {
            return 1;
        },
        credentials: function (url, username) {
            return git.Cred.sshKeyFromAgent(username);
        }
    }
};

function getFileFromBranch(branch, filePath) {
    let repository;

    return git.Repository.open(config.git.cloneTo)
        .catch(function (err) {
            if (err.message.startsWith('Failed to resolve')) {
                winston.info('Repo not found, cloning');

                // USED HERE
                return git.Clone(config.git.repo, config.git.cloneTo, remoteOpts);
            } else {
                winston.error(err);
                throw err;
            }
        })
        .then(function (repo) {
            repository = repo;

            winston.log('verbose', 'Changing branch');
            return repo.checkoutBranch(branch);
        })
        .catch(function (err) {
            if (/Reference '([^']+)' not found/.test(err.message)) {
                winston.info('Branch not found, fetching');

                // USED HERE
                let remoteCallbacks = remoteOpts.remoteCallbacks;
                return repository.fetch('origin', remoteCallbacks, true)
                    .then(function () {
                        return repository.checkoutBranch(branch);
                    });
            } else {
                winston.error(err);
                throw err;
            }
        })
        .then(function () {
            return fs.readFile(path.join(config.git.cloneTo, filePath));
        });
}

Activity

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

Metadata

Metadata

Assignees

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


    Back | FazBrowse Home | New Git URL