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 '/' in branch names #179

Closed
nielstenboom opened this issue Jan 24, 2023 · 6 comments
Closed

Support '/' in branch names #179

nielstenboom opened this issue Jan 24, 2023 · 6 comments

Comments

@nielstenboom
Copy link
Contributor

Hi there!

Wanted to try out your action. I set the head-ref to the current branch which has a / in it and got the following error:

Error: Branch names must contain only numbers, strings, underscores, periods, and dashes.

Would it be possible to support branch names with slashes? Thanks!

@metcalfc
Copy link
Owner

Hey,

I dug into this. There might be a way but I don't have the git internals knowledge to get it to work. So here is what is happening:

  • GitHub Actions are shallow checkouts of just the branch in question
  • The action "unshallows" the checkout so we've got access to all the tags and branch names.
    git fetch --depth=1 origin +refs/tags/*:refs/tags/* 1>&2
    git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/* 1>&2
    git fetch --prune --unshallow 1>&2
  • Branches with slashes are never realized in that. I'm not sure why.

If you have the magic incantation needed to unshallow a checkout and pull in branches with slashes happy to fix it.

To test this I set a branch test/branch to v0.0.2 and ran the action. This is the error:

fatal: ambiguous argument ''v0.0.1...test/branch'': unknown revision or path not in the working tree.

So one would probably have to check if the refs have slashes and then pull all the refs in that directory but this is beyond my git foo.

@metcalfc
Copy link
Owner

Just in case someone wants to pick up where I left off https://github.com/metcalfc/changelog-generator/tree/slash_branch has the last patch I tried.

@nielstenboom
Copy link
Contributor Author

Thanks for having a look!

I took a stab at getting it to work as well and got it to work (sorta.. 😅 )

It can work with 2 gotchas:

  1. Have the checkout action do all the fetching lifting, so add fetch-depth: 0 and don't have this action do any fetching (see here for the bash file)
  2. Add origin/ in front of the ref that has a / in it, with that the git log ... works (no clue about the git foo underneath)

See here for a succesful run.

So to fix this we could maybe add a parameter to this action to enable fetching or not, sth like fetch: false and then in the readme add that you should put origin in front of branch name refs with forward slashes in them?

@metcalfc
Copy link
Owner

metcalfc commented Feb 8, 2023

I'm good with the parameter to fetch or not. We can default fetch to true so it doesn't break existing users. You and others that want to use slash or other things can set fetch to false and everyone is off to the races.

@github-actions
Copy link

This issue has not had any activity in 30 days. Marking it stale. It will be closed in 14 days.

@metcalfc
Copy link
Owner

Merged in #188

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

Successfully merging a pull request may close this issue.

2 participants