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 auto-tag when merging a branch into another branch - unknown revision or path not in the working tree. #299

Open
scottcousens-nas opened this issue Jan 18, 2024 · 5 comments

Comments

@scottcousens-nas
Copy link

scottcousens-nas commented Jan 18, 2024

When merging a developer feature branch into a release branch (off master), this plugin throws an error.

In the section looking for merge commits, get the following error:

++ git log release/2.2patch..HEAD --format=%B
fatal: ambiguous argument 'release/2.2patch..HEAD': unknown revision or path not in the working tree.

I have a lot of commits, many with tags.
Go back to a commit/tag referencing our last release (lets say tag v2.2)
Create a release branch off this
Create a dev branch off this release branch
Add updates/commits to this dev branch and merge into the release branch (the auto-tag runs to create a new tag on the release branch)
This is where we hit the above error

To reproduce or setup the situation, assume a repository with a number of commits. Not at the top we have a tag referencing a past release (v2.2), but dont yet have a branch for it - the commit is on master.

git checkout v2.2
git checkout -b release/2.2patch
git push --set-upstream origin release/2.2patch
git checkout -b  dev/2.2patch
git push --set-upstream origin dev/2.2patch
<update files>
git add src/feature.py
git commit -m 'fix feature'
git push
<PR from dev/2.2patch to release/2.2patch>
<merge PR>
<workflow calling auto-tag runs - verbose output snippet>
++ git show -s --format=%B
++ git log release/2.2patch..HEAD --format=%B
fatal: ambiguous argument 'release/2.2patch..HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
++ git log 34190c7bcbcddd87c4d6f8be0ea39bfca1ccc9db..30da0757b763061e56dc29f9cae97503f77f3617 --format=%B

To manually reproduce the error, I can now clone the repository, checkout dev/2.2patch branch (release/2.2patch is not in the workspace.) I can reproduce the error manually...

> git clone <repo>
> cd <repodir>
> git checkout dev/2.2patch
> git log release/2.2patch..HEAD
fatal: ambiguous argument 'release/2.2patch..HEAD': unknown revision or path not in the working tree.

However if I prefix with 'origin' in the git log call, this now works:

> git log origin/release/2.2patch..HEAD
commit 94eb5e456ab72c0509bed12270a8031c39c7199b (HEAD -> dev/2.2patch, origin/dev/2.2patch)
Author: xxxxxxxx
Date:   yyyyyyyy
@scottcousens-nas
Copy link
Author

By doing a full checkout, I also managed to eliminate this error.
Here is the step before the github-tag-action:

        uses: actions/checkout@v4
        with:
          ref: ${{ github.event.pull_request.merge_commit_sha }}
          ##fetch-depth: '0'      <--- comment tbis out

@sbe-arg
Copy link
Collaborator

sbe-arg commented Jan 19, 2024

According to checkout documentation.

# Number of commits to fetch. 0 indicates all history for all branches and tags. # Default: 1 fetch-depth: ''

Not sure what a full checkout is in your case.

But glad you found a fix to your case problem.

@sbe-arg sbe-arg closed this as completed Jan 19, 2024
@scottcousens-nas
Copy link
Author

After mucking about with this more today, it appears that fetch-depth thing did not 'fix' the issue, I'm still hitting it.
How do I get this issue reopened? @sbe-arg

@sbe-arg sbe-arg reopened this Jan 19, 2024
@scottcousens-nas
Copy link
Author

scottcousens-nas commented Jan 22, 2024

Ok, so I think I found another workaround that actually appears to work. It may drive a README/documentation update.

When I call actions/checkout@v4, if a SHA is supplied (default uses $ GITHUB _ SHA I believe, or if you specify with: ref: ${{ github.event.pull_request.merge_commit_sha }} as per readme) then I get this failure.
However, when I use a head or tags type ref: for the checkout step ( ${{ github.ref_head }} ) then github-tag-actions appears to work as expected and I dont get this error.
This is what we have that appears to work as expected....

     - name: Checkout
        uses: actions/checkout@v4
        with:
          ref: ${{ github.ref_name }}

      - name: Push updated tag
        uses: anothrNick/[email protected]
        env:
          DEFAULT_BUMP: minor
          WITH_V: true
          RELEASE_BRANCHES: master,release/*
          TAG_CONTEXT: branch
          BRANCH_HISTORY: last

Note that the plugin still runs successfully, even if it hits that fatal: ambiguous argument 'release/2.2patch..HEAD': unknown revision or path not in the working tree. error. I have to look at the actual output of the plugin to see the error. The resulting tag may or may not be what you want based on TAG_CONTEXT and using a non-master/main branch (in our case).

@nikitajz
Copy link

I was able to reproduce the issue successfully 😅

I was using a fresh repo so the tag "0.0.0" indeed didn't exist.
But a new tag was created successfully, so then the problem happens when the custom tag is provided, unnecessary steps are still performed (particularly retrieving existing tags).

 * [new branch]      release/v0.0.1-dev8 -> origin/release/v0.0.1-dev8
 * [new tag]         v0.0.1-dev8         -> v0.0.1-dev8
fatal: ambiguous argument '0.0.0': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
History:
---
---
Bumping tag 0.0.0 - New tag 0.1.0
EVENT: creating local tag v0.0.1-dev9
EVENT: pushing tag v0.0.1-dev9 to origin

The solution is likely to skip semver calculations altogether if a custom tag argument is provided, but this likely won't solve the initial issue.

Full workflow to reproduce:
on:
  pull_request:
    types:
      - closed
    branches:
      - main

jobs:
  tag_head_ref:
    if: ${{ github.event.pull_request.merged == true }}
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ github.ref_name }}

      - run: |
          echo "Merge commit: ${{ github.event.pull_request.merge_commit_sha }}. Base branch: ${{ github.base_ref}} Merged branch: ${{ github.head_ref}}"
      - run: | 
          echo "${{ github.head_ref }}" | sed 's/release\//TAG_VERSION=/'>> "$GITHUB_ENV"
      - run: |
          echo "Tag version: [$TAG_VERSION]"

      - name: Bump version and push tag
        uses: anothrNick/[email protected] # Don't use @master or @v1 unless you're happy to test the latest version
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # if you don't want to set write permissions use a PAT token
          CUSTOM_TAG: ${{ env.TAG_VERSION }}

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

No branches or pull requests

3 participants