Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

options not reusable, nodegit destroys it #533

Copy link
Copy link
@callumacrae

Description

@callumacrae
Issue body actions

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));
        });
}
Reactions are currently unavailable

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

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.