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

error: Couldn’t not find the SHA of the previous release in the git history. #792

Closed
sgametrio opened this issue Jul 23, 2020 · 12 comments · Fixed by #963
Closed

error: Couldn’t not find the SHA of the previous release in the git history. #792

sgametrio opened this issue Jul 23, 2020 · 12 comments · Fixed by #963

Comments

@sgametrio
Copy link

Hey everybody,
I'm using Sentry on a repository where we have several branches that upload source maps to Sentry, each time with a new release.

When calling these CLI commands:

sentry-cli releases new ${CI_COMMIT_SHA}
sentry-cli releases set-commits --auto ${CI_COMMIT_SHA}  # <--- here I get the error

It happens that sometimes we get the error

error: Couldn’t not find the SHA of the previous release in the git history. Increase your git clone depth.

And if I increase the git depth, it showserror: No commits found. Leaving release alone.

It has to be said that when merging into master we are squashing commits and that could be the cause of our problems, but we can't figure out exactly because sometimes the set-commits command just work as expected.

@kamilogorek
Copy link
Contributor

kamilogorek commented Jul 24, 2020

--auto is a flag, and it doesn't accept any additional value, so this last ${CI_COMMIT_SHA} is ignored.

edit: My bad, it's an actual release name and it should be there.

If you squash or rebase git history, then as you already mentioned there's a chance that hashes will be overridden, and we won't be able to find old release reference. If you cannot change that, then you'll most likely have to explicitly tell the CLI which hash is the one that you want to use as the base, eg.

sentry-cli releases set-commits "$VERSION" --commit "my-repo@from..to"

@vinnymac
Copy link
Contributor

vinnymac commented Sep 12, 2020

@kamilogorek your advice is certainly helpful, but the first thing you mention is that --auto takes no additional value and that ${CI_COMMIT_SHA} is ignored. The documentation for the CLI has examples that show this exact usage however.

Screen Shot 2020-09-12 at 12 00 23 PM

Is the example wrong, or does the auto flag actually accept a value?

I see competing examples here.

Screen Shot 2020-09-12 at 12 01 41 PM

If this wasn't the official documentation I wouldn't be concerned, but others might be led astray here if an inconsistency exists.

@kamilogorek
Copy link
Contributor

kamilogorek commented Sep 14, 2020

@vinnymac good catch, updated my comment. I misread the command 😅 Thanks!

@x-yuri
Copy link

x-yuri commented Sep 18, 2020

@kamilogorek @sgametrio Actually I believe sentry-cli shouldn't fail because of a rebase. Just store in a release a list of associated commits (unless you already do), and look in the git history not for a release name, but for every commit in turn. Unless you find the commit in the previous release, check the one before that. Maybe 2 releases is generally enough. But you can add a switch to specify "how much is too much." You want releases to not branch? Add a --force switch. Or at least document the way to use sentry-cli that doesn't choke on rebases:

VERSION=$(sentry_cli releases propose-version)
sentry_cli releases new -p "$sentry_prj" "$VERSION"
sentry_cli releases set-commits --auto "$VERSION" || {
    PRV_VERSION=`curl -sS \
        -H "Authorization: Bearer $SENTRY_AUTH_TOKEN" \
        "$sentry_base_url/organizations/$sentry_org/releases/$VERSION/previous-with-commits/" \
        | jq -r .version`
    sentry_cli releases delete "$PRV_VERSION"
    sentry_cli releases set-commits --auto "$VERSION"
}

We can discuss the issue if you feel like it.

If you cannot change that, then you'll most likely have to explicitly tell the CLI which hash is the one that you want to use as the base, eg.

This seems reasonable, but in practice seems useless, unless you do it by hand in your local repository. Sorry for being blunt. Where will I find the now non-existent commits on a CI server to determine the base commit? In the reflog?

And actually I have a number of questions for which I don't expect to receive answers. Except for possibly here? Anyways, I'm open for suggestions. The first one is that I'm reluctant to install the GitHub application. Judging from the wording it seems like once I do, I can never go back. Then you suggest using cli over api. Why is that? You say that releases are global per organization. Is using commit hashes safe? The documentation makes one think one should do something different if one doesn't want to install the GitHub application. But from I can see, the difference only in the result (more info on Sentry probably).

@JustDoItSascha
Copy link

Is there any progress here? The set-commits command is failing here, but we haven't done a squash or a rebase. Is there any possibility to get around this problem? Because right now the only way to exit this loop hole is to completely disable set-commits command, right? Or is it possible to say "use auto, but if you don't find something, just take the last commit in history"?

@karatekaneen
Copy link

I ran in to this issue on our CI system. It boiled down to that it only fetched a shallow copy of the git repo.
I solved it by running git fetch --unshallow before the sentry_cli releases set-commits --auto "$VERSION".

Hope this can help someone.

@klarkc
Copy link

klarkc commented Jan 21, 2021

@karatekaneen did you found a way to fetch without unshallowing? This make a bottleneck in our CI. Would be nice if we shallow fetch only needed commits for sentry-cli

EDIT:

I found a way to it with help of bash and sentry-ci:

LAST_RELEASE=$(sentry-cli releases list | sed -n 6p | tr '|' '\n' | sed -n 3p | tr -d '[:space:]')
LAST_RELEASE_DATE=$(sentry-cli releases info $LAST_RELEASE | sed -n 5p | tr '|' '\n' | sed -n 3p |  sed 's/^[ \t]*//;s/[ \t]*$//' | tr ' ' '\n' | sed -n 1p)
git fetch --shallow-since=$LAST_RELEASE_DATE

EDIT 2:

If some1 name releases with git describe, and also set commits in each release, you can also use this be able to do in a CI enviroment:

COUNT=30; cc=$COUNT; while [[ $(git tag | wc -l) < 1 ]]; do git fetch --depth=$cc; cc=$(expr $cc + $COUNT); done ;

This script will "git fetch" until find a tag and be able to git describe, and also to be able to set commits. Set COUNT to a pagination value (in this example it increments fetch range by 30 commits). If your last tag was a sentry release, the SHA will be in git history, so also solve this issue.

@Rennzie
Copy link

Rennzie commented Apr 23, 2021

I had a the same issue. Turns out my github integration wasn't liked to the repo. I needed to allow access to the repo in my Github orgs app settings. Then link it in the Sentry org integration for Github config.

@kamilogorek
Copy link
Contributor

Thanks for the info @Rennzie

@FadiAboMsalam
Copy link

adding --ignore-missing solved my issue

sentry-cli releases set-commits "$VERSION" --auto --ignore-missing

@josh-
Copy link

josh- commented Jan 17, 2022

I ran in to this issue on our CI system. It boiled down to that it only fetched a shallow copy of the git repo. I solved it by running git fetch --unshallow before the sentry_cli releases set-commits --auto "$VERSION".

Hope this can help someone.

Just ran into this on GitHub Actions - if anyone is also seeing this error in your workflow when using actions/checkout, it's because this action does a shallow clone by default and can be configured to fetch all or a specified number commits with fetch-depth. For example:

- uses: actions/checkout@v2
        with:
          fetch-depth: 0

@LeonardoRosaa
Copy link

When running the command flutter packages pub run sentry_dart_plugin with the actions/checkout configured as shown below:

- uses: actions/checkout@v4
  with:
    fetch-depth: 0

I encounter the following issue:

Could not determine any commits to be associated with a repo-based integration. Proceeding to find commits from the local git tree.

error: Could not find the SHA of the previous release in the git history. If you limit the clone depth, try to increase it. Otherwise, it means that the commit we are looking for was amended or squashed and cannot be retrieved. Use --ignore-missing flag to skip it and create a new release with the default commits count.

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 a pull request may close this issue.