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

Gitlab refs compatibility #160

Open
juanmcasanova opened this issue Jan 3, 2020 · 5 comments
Open

Gitlab refs compatibility #160

juanmcasanova opened this issue Jan 3, 2020 · 5 comments

Comments

@juanmcasanova
Copy link
Contributor

When using GitLab CI, a couple of custom refs are created in the GIT repository by GitLab to prevent errors with force-pushes and such (as far as I know "refs/pipelines/" and "refs/merge-requests/").

The problem is that this library checks every ref type in the repository and throws a RuntimeException if it doesn't recognize one:

foreach ($parser->references as $row) {
list($commitHash, $fullname) = $row;
if (preg_match('#^refs/(heads|remotes)/(.*)$#', $fullname)) {
if (preg_match('#.*HEAD$#', $fullname)) {
continue;
}
$reference = new Branch($this->repository, $fullname, $commitHash);
$this->references[$fullname] = $reference;
$this->branches[] = $reference;
} elseif (preg_match('#^refs/tags/(.*)$#', $fullname)) {
$reference = new Tag($this->repository, $fullname, $commitHash);
$this->references[$fullname] = $reference;
$this->tags[] = $reference;
} elseif ($fullname === 'refs/stash') {
$reference = new Stash($this->repository, $fullname, $commitHash);
$this->references[$fullname] = $reference;
} elseif (preg_match('#^refs/pull/(.*)$#', $fullname)) {
// Do nothing here
} elseif ($fullname === 'refs/notes/gtm-data') {
// Do nothing here
} else {
throw new RuntimeException(sprintf('Unable to parse "%s"', $fullname));
}
}

I can make a pull request to fix this, but wouldn't it be better to ignore any unknown reference instead of having to manually include each of them in this file?

@alexandresalome
Copy link
Member

I think it's a good idea.

@GrahamCampbell
Copy link
Member

NB GitHub also has refs of the format refs/pull/{pr}/head where {pr} is an integer PR number.

@GrahamCampbell
Copy link
Member

I was going to say that skipping unknown stuff would be a bad idea, because it would make the count() function confusing, but we already skip stuff, looking at the code. Maybe skipping everything unknown is going to be the best approach.

@alexandresalome
Copy link
Member

And for backward compatibility, that would be better.

Maybe we could start a list of "things to do for next major version".

@juanmcasanova
Copy link
Contributor Author

I agree it is better to do it in a major version, as it could break things for some people if they expect gitlib to ignore those references.

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

No branches or pull requests

3 participants