Skip to content
This repository was archived by the owner on Mar 10, 2022. It is now read-only.

Conversation

@tjkandala
Copy link
Contributor

Closes #145

Background

Existing implementation split upstream and branch by /, but refname components can contain /. Instead of splitting on /, subtract the upstream and branch by branch name (two separate git command invocations).

Progress

  • Support remote and branch names with slashes
  • Refactor for testability
  • Add unit tests

Copy link
Contributor

@felixfbecker felixfbecker left a comment

Choose a reason for hiding this comment

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

Awesome that you refactored and added tests! I didn't look at the logic in depth, I'll defer to @sourcegraph/extensibility

src/git.ts Outdated
branch = stdout.slice(remoteName.length + 1) // remove '/' from start of branch
}
} catch {
// noop. upstream may not be set
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you narrow down this error a bit so we don't blanket-swallow all errors, including e.g. the git executable not being found? Is there a certain exit code or stderr output?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Git doesnt seem to return specific error codes.
Some examples:
Screen Shot 2021-02-16 at 11 09 16 AM
Screen Shot 2021-02-16 at 11 07 34 AM

If stderr starts with fatal: no upstream configured for branch we could swallow, else rethrow.

However, errors like git executable not being found or git repo not existing would be thrown when we execute git.remotes or git.branches (both are executed before git.upstreamAndBranch)

Comment on lines +35 to +52
// Used to determine which part of upstreamAndBranch is the remote name, or as fallback if no upstream is set
const remotes = await git.remotes(repoDirectory)
const branch = await git.branch(repoDirectory)

try {
const upstreamAndBranch = await git.upstreamAndBranch(repoDirectory)
// Subtract $BRANCH_NAME from $UPSTREAM_REMOTE/$BRANCH_NAME.
// We can't just split on the delineating `/`, since refnames can include `/`:
// https://sourcegraph.com/github.com/git/git@454cb6bd52a4de614a3633e4f547af03d5c3b640/-/blob/refs.c#L52-67

// Example:
// stdout: remote/two/tj/feature
// remoteName: remote/two, branch: tj/feature

const branchPosition = upstreamAndBranch.lastIndexOf(branch)
const maybeRemote = upstreamAndBranch.slice(0, branchPosition - 1)
if (maybeRemote) {
remoteName = maybeRemote
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Core logic to be reviewed

@tjkandala
Copy link
Contributor Author

Merging as we reviewed in hack time

@tjkandala tjkandala merged commit 1b10752 into master Feb 22, 2021
@tjkandala tjkandala deleted the tj/slash branch February 22, 2021 16:20
@github-actions
Copy link

🎉 This PR is included in version 1.2.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@tjkandala tjkandala changed the title Fix: support remote and branch names with slashes Fix: support valid remote and branch names Feb 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Open in Sourcegraph command/shortcut returns 'repoInfo(...): Error: no configured git remotes' when branch name has / in it

3 participants