Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support non-origin remotes #44

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

paulirish
Copy link
Contributor

@paulirish paulirish commented May 11, 2018

fixes #38

src/core.js Outdated
@@ -104,8 +104,12 @@ async function sync(cloneUrl, localDirectory, {ref, checkout}) {
}

await git.cwd(localDirectory);

await git.removeRemote(cloneName).catch((error) => {}); // eslint-disable-line no-unused-vars
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this cloneUrl is specific to the github-token so if a token is revoked, then all the old remotes with invalid tokens are still there and will fail on the fetch.

always doing a .removeRemote() right here means the cloneUrl provided is always used.

log.info(`> Fetching ${ref}...`);
await git.fetch('origin', ref);
const remoteName = cloneName || 'origin';
await git.removeRemote(remoteName).catch((error) => {}); // eslint-disable-line no-unused-vars
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this cloneUrl is specific to the github-token so if a token is revoked, then all the old remotes with invalid tokens are still there and will fail on the fetch.

always doing a .removeRemote() right here means the cloneUrl provided is always used.

removeRemote caught because we don't care if it's removing something that isn't there.

await git.fetch('origin', ref);
const remoteName = cloneName || 'origin';
await git.removeRemote(remoteName).catch((error) => {}); // eslint-disable-line no-unused-vars
await git.addRemote(remoteName, cloneUrl);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fwiw these strings are like "username/reponame", and git is totally cool with slashes in remote names, afaict.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also shouldn't have to validate because GitHub users shouldn't be able to create a branch with invalid characters to begin with! Should fail further upstream, not at the stage-ci level 🚀

Copy link
Contributor

@hugomd hugomd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@paulirish This looks perfect!

From looking at the GitLab docs, it looks like the equivalent of pull_request.head.repo.full_name is pull_request.project.path_with_namespace but I'll have a play around in my own branch 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot find remote ref <branchname>
2 participants