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

Expected ref refs/remotes/origin/main #18

Closed
geoHeil opened this issue Mar 13, 2021 · 7 comments
Closed

Expected ref refs/remotes/origin/main #18

geoHeil opened this issue Mar 13, 2021 · 7 comments

Comments

@geoHeil
Copy link

geoHeil commented Mar 13, 2021

As mentioned in #16 my issue is not yet fixed by the update to 2.0.1 I still get a:

gradle changelogPush
> Task :changelogCheck FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':changelogCheck'.
> Expected ref refs/remotes/origin/main

when executing it.

NOTICE: I run it in a normal non-bare repository where the remote is named origin and the branch origin/main as required by the default settings.

git ls-remote
From [email protected]:geoHeil/my_repository.git
hash1	HEAD
hash2	refs/heads/origin/main

And refs/heads/origin/main is not equal to refs/remotes/origin/main.

When I create a remote-tracking branch to get the refs/remotes/xxx:

git checkout --track origin/main
Branch 'main' folgt nun lokalem Branch 'origin/main'.
Zu neuem Branch 'main' gewechselt
my-repo git:(main) git ls-remote
From .
c1	HEAD
c1	refs/heads/main
c1	refs/heads/origin/main
c1	refs/remotes/origin/HEAD
c1	refs/remotes/origin/origin/main

However, refs/remotes/origin/origin/main still is not equal to: refs/remotes/origin/main and thus spotless-changelog fails again with the same error.

Here is my stack trace for version 2.0.1 and Gradle version 6.8.3

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':changelogCheck'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$3(ExecuteActionsTaskExecuter.java:186)
        ...
Caused by: java.lang.NullPointerException: Expected ref refs/remotes/origin/main
        at com.diffplug.spotless.changelog.GitActions.checkCanPush(GitActions.java:66)
        at com.diffplug.spotless.changelog.gradle.ChangelogPlugin$CheckTask.check(ChangelogPlugin.java:99)
        ...
@nedtwigg
Copy link
Member

Hmm... I wonder if you are using a custom refspec. If I just do a clean clone of this repo, for example:

foo@bar:~$ git clone https://github.com/diffplug/spotless-changelog
<clone progress etc>
foo@bar:~$ cat .git/config
[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
	ignorecase = true
	precomposeunicode = true
[remote "origin"]
	url = https://github.com/diffplug/spotless-changelog
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
	remote = origin
	merge = refs/heads/main

So for the spotless default config:

spotlessChangelog {
  remote 'origin'
  branch 'main'
}

It is looking for refs/heads/main and refs/remotes/origin/main. That's the default, plain-jane setup.

I wonder if your origin fetch isn't +refs/heads/*:refs/remotes/origin/* but instead something more exotic. I guess one solution is to make

Ref remoteRef = repository.getRefDatabase().exactRef(Constants.R_REMOTES + cfg.remote + "/" + cfg.branch);

smarter, so that it feeds through the origin fetch refspec. A worse option would be to replace remote with remoteRefOverride which would be null by default, but allow users to bypass the default refs/remotes/<remote>/<branch> convention.

Can you confirm the fetch key in your [remote "origin"] block?

@geoHeil
Copy link
Author

geoHeil commented Mar 13, 2021

I observe:

[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
	ignorecase = true
	precomposeunicode = true
[remote "origin"]
	url = [email protected]:geoHeil/my_repository.git
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
	remote = c
	merge = refs/heads/main
+refs/heads/*:refs/remotes/origin/* # yours
+refs/heads/*:refs/remotes/origin/* # mine

these are the same.

@nedtwigg
Copy link
Member

Bizarre. One thing is that it looks like spotless-changelog is on JGit 5.5.1.201910021850-r, but the latest version is 5.10.0.202012080955-r. Could be that you've got some cutting edge native git that old JGit can't read.

Maybe try this workaround to force the latest JGit version to see if that fixes it?

Also, what's in your spotlessChangelog block?

@geoHeil
Copy link
Author

geoHeil commented Mar 13, 2021

My version of git is: 2.30.1

It is not present - as I completely stick to the defaults.

But also changing to:

spotlessChangelog { // only necessary if you need to change the defaults below
    changelogFile 'CHANGELOG.md'
    enforceCheck true
}

is not changing anything and keeps failing with the above-mentioned issue.
The same is true for applying the suggested workaround.

@nedtwigg
Copy link
Member

Looks like you are using origin/main as your branch, with origin/origin/main as the remote tracking branch?

Seems like some confusion leftover from a previous fix attempt. I would just use main, tracking against origin/main.

@geoHeil
Copy link
Author

geoHeil commented Mar 14, 2021

Indeed, this is true / finally works.

> You can set user/pass with any of these environment variables: [GRGIT_USER, GRGIT_PASS, gh_token]

this is the next step - as I had set up SSH keys & was using the SSH URL I would have expected it to work - will try with the token.

@geoHeil
Copy link
Author

geoHeil commented Mar 14, 2021

Works now, but GRGIT_USER must point to the user and gh_token to the access token and the URL must be an HTTP (not ssh) URL.

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

2 participants