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

Not able to merge commit in PR when branches content is same, but different commit id #19603

Closed
jedi7 opened this issue May 4, 2022 · 22 comments · Fixed by #20352
Closed

Not able to merge commit in PR when branches content is same, but different commit id #19603

jedi7 opened this issue May 4, 2022 · 22 comments · Fixed by #20352
Labels

Comments

@jedi7
Copy link
Contributor

jedi7 commented May 4, 2022

Description

Hi,
there is missing button for commit in pull request, when branches are same but there is commit to merge.
steps to reproduce:

  1. "merge --no-ff" from "develop" to "master"
  2. create tag on master
  3. create PR from "master" to "develop"
  4. missing button for merge
    PR says the files diff is empty (that is correct).
    But also in PR is 1 commit with the merge info and created tag, which should be merged into "develop"
    (just usual git flow)

Gitea Version

1.16.7

Can you reproduce the bug on the Gitea demo site?

Yes

https://try.gitea.io/jedi7/test_19603/pulls/1

Log Gist

No response

Screenshots

Git Version

2.25.1

Operating System

ubuntu

How are you running Gitea?

docker container

Database

MySQL

@jedi7 jedi7 added the type/bug label May 4, 2022
@delvh
Copy link
Member

delvh commented May 4, 2022

I think you misunderstood Git slightly:
When you create a tag, you don't create a (new) commit (with changes).
You instead create a pointer to an existing commit.
There is nothing to commit because no changes were made.
So it makes sense that the branches are equal... because they are.
Git simply knows then that the tag to that commit exists (no matter on which branch you are).

@delvh delvh closed this as completed May 4, 2022
@jedi7
Copy link
Contributor Author

jedi7 commented May 4, 2022

can you please try the steps to reproduce? You will see it is real scenario, where the commit is created "

See:

commit 64dc9f325959c7d56f8c48c68b47607d1442d8ed (tag: RELEASE-4.0.0, origin/master, origin/develop, origin/HEAD, develop)
Merge: 24d4a6bcd fbc80940a
Author: censored
Date:   Wed May 4 08:44:03 2022 +0200

    Merge pull request 'release/v4.0' (#135) from release/v4.0 into master

commit fbc80940ac8d6a2fe1ddcfc988865eefda5b94a4 (origin/release/v4.0)
Merge: bffcadfe4 0fc5acd6e
Author: censored
Date:   Fri Apr 29 09:24:24 2022 +0200

$ git diff fbc80940ac8d6a2fe1ddcfc988865eefda5b94a4 64dc9f325959c7d56f8c48c68b47607d1442d8ed
$

As you can see, there is empty commit. But the commit is still valid and it carry the tag.

@jedi7
Copy link
Contributor Author

jedi7 commented May 4, 2022

I must did manual merge and push to develop without PR, to be able get the tag into develop.

@wxiaoguang
Copy link
Contributor

Are the commit IDs the same when you doing step 3 create PR from "master" to "develop"? If yes, that's expected behavior.

If you consider there is something unclear, please show your git branches history before merge.

@jedi7
Copy link
Contributor Author

jedi7 commented May 4, 2022

steps to reproduce:

git init
git add  README.md
git commit -m "initial"
git checkout -b develop
echo "test" > ./README.md
git commit -a -m "test"
git checkout master
git merge --no-ff develop
git log
# now you can see the merge commit, but diff is empty between them, see bellow
git tag MyTag
# tag will be on the merge commit, so no visible in develop

# so I need to merge master into develop, but not possible with gitea PR (bug)
git checkout develop
git merge master
jedi@tpol 11:05:51 ~/Projects-tests/tests-git/xx $ git co master
Switched to branch 'master'
jedi@tpol 11:05:54 ~/Projects-tests/tests-git/xx $ git log
commit 3b2220b16b9a542d2879eebdc7e9bd0f8a6a72d6 (HEAD -> master, tag: MyTag)
Merge: df1d83b fd437e0
Author: Ing. Jaroslav Safka <devel@safka.org>
Date:   Wed May 4 11:02:28 2022 +0200

    Merge branch 'develop'

commit fd437e0498d75cc25d9494f8ff4d807510d72d92 (develop)
Author: Ing. Jaroslav Safka <devel@safka.org>
Date:   Wed May 4 10:57:55 2022 +0200

    test

commit df1d83b5339dfe1155a12e0cc86085e3432addf1
Author: Ing. Jaroslav Safka <devel@safka.org>
Date:   Wed May 4 10:56:09 2022 +0200

    initial
jedi@tpol 11:05:56 ~/Projects-tests/tests-git/xx $ git co develop
Switched to branch 'develop'
jedi@tpol 11:06:02 ~/Projects-tests/tests-git/xx $ git log
commit fd437e0498d75cc25d9494f8ff4d807510d72d92 (HEAD -> develop)
Author: Ing. Jaroslav Safka <devel@safka.org>
Date:   Wed May 4 10:57:55 2022 +0200

    test

commit df1d83b5339dfe1155a12e0cc86085e3432addf1
Author: Ing. Jaroslav Safka <devel@safka.org>
Date:   Wed May 4 10:56:09 2022 +0200

    initial
jedi@tpol 11:06:05 ~/Projects-tests/tests-git/xx $ git diff fd437e0498d75cc25d9494f8ff4d807510d72d92 3b2220b16b9a542d2879eebdc7e9bd0f8a6a72d6
jedi@tpol 11:06:19 ~/Projects-tests/tests-git/xx $

@jedi7
Copy link
Contributor Author

jedi7 commented May 4, 2022

Are the commit IDs the same when you doing step 3 create PR from "master" to "develop"? If yes, that's expected behavior.

If you consider there is something unclear, please show your git branches history before merge.

They are not same, there is 1 commit. (the merge commit)

@wxiaoguang
Copy link
Contributor

wxiaoguang commented May 4, 2022

There seems some misunderstanding.

tag will be on the merge commit, so no visible in develop

tag is not binded to branch. it's visible to the whole git repository after push.

so I need to merge master into develop, but not possible with gitea PR (bug)

you shouldn't (and needn't), because now develop is the parent of master and there is no change at all.

@wxiaoguang

This comment was marked as off-topic.

@jedi7
Copy link
Contributor Author

jedi7 commented May 4, 2022

that is not about tags, sorry if I confuse you. It is about the empty merge commit, which I need merge by PR to develop branch.
Please see the example which I posted

@wxiaoguang
Copy link
Contributor

wxiaoguang commented May 4, 2022

Sorry but it's beyond my knowledge. I can not understand why you need to do that. Let's re-open the issue to see if there are other suggestions.

@wxiaoguang wxiaoguang reopened this May 4, 2022
@jedi7
Copy link
Contributor Author

jedi7 commented May 4, 2022

image

@Gusted
Copy link
Contributor

Gusted commented May 4, 2022

The code responsible for this:

if treeHash == baseTree.ID.String() {
log.Debug("PullRequest[%d]: Patch is empty - ignoring", pr.ID)
pr.Status = models.PullRequestStatusEmpty

More or less because the SHA1 of the merge commit is the same as the develop branch it thinks the pull request is empty... I'm not sure what the correct behavior would be here(maybe add a extra check here, or completely removing it? Changing this check to be more explicit about equal last commit of the branches?)

@jedi7
Copy link
Contributor Author

jedi7 commented May 5, 2022

What about to just take last commit id from the branches and compare them? Is it possible?
If I understand, the write-tree recreates id from files (which are same in this situation), so no usable here :(

What about to use: git rev-parse ?

@Gusted
Copy link
Contributor

Gusted commented May 5, 2022

What about to just take last commit id from the branches and compare them?

The commitID's are equal. I think we should check here if the amount of commits in the tree's aren't equal. Not sure about generating the diff, but seems like that would be more trickier(what's Github/Gitlab's behavior in this situation?)

@jedi7
Copy link
Contributor Author

jedi7 commented May 6, 2022

What about to just take last commit id from the branches and compare them?

The commitID's are equal. I think we should check here if the amount of commits in the tree's aren't equal. Not sure about generating the diff, but seems like that would be more trickier(what's Github/Gitlab's behavior in this situation?)

Good thing is, they are not equal :) If we take them exactly as they are by "git rev-parse" for example.
They are equal only when are recreated by "git write-tree" (because diff / files content are the same).

@Gusted
Copy link
Contributor

Gusted commented May 8, 2022

Good thing is, they are not equal :) If we take them exactly as they are by "git rev-parse" for example.
They are equal only when are recreated by "git write-tree" (because diff / files content are the same).

I personally don't feel comfortable with messing the conflict checker. It's quite specialized in it's setup. So I don't think it's easy to simply change some commands to change the git repo's. AFAIK the commitID's will always be the same, no matter what. We simply have to add another check here that exclude this case.

@jedi7
Copy link
Contributor Author

jedi7 commented May 8, 2022

@Gusted Not sure what you mean by commits id will be always the same. When you try the example above, you can compare them and see they have different ID's.
Do you have idea, why the commits ID's are recreated from files (by write-tree) and are not used the real already present ID (taken by rev-parse for example) ?

@Gusted
Copy link
Contributor

Gusted commented May 8, 2022

@Gusted Not sure what you mean by commits id will be always the same. When you try the example above, you can compare them and see they have different ID's.

In sense of write-tree it will always be the same CommitID, which the current code relies on.

Do you have idea, why the commits ID's are recreated from files (by write-tree) and are not used the real already present ID (taken by rev-parse for example) ?

No idea, most likely it was the best solution then.

@jedi7 jedi7 changed the title Not able to merge commit in PR when branches are same Not able to merge commit in PR when branches content is same, but different commit id May 9, 2022
@jedi7
Copy link
Contributor Author

jedi7 commented May 9, 2022

Actually I found it is even worst.
When I will have 2 branches with different history but same content, ten the "write-tree" also return same commit id for both.
Which means I will not be able to merge them together to create just one branch.

@jedi7
Copy link
Contributor Author

jedi7 commented May 10, 2022

Tests are done on this git repo:
You can try merge branch paralel into master. Or master into develop.

test-empty-merge-commit2.tar.gz

@jedi7
Copy link
Contributor Author

jedi7 commented May 10, 2022

@zeripath Maybe as author will be interested?

jedi7 added a commit to jedi7/gitea that referenced this issue Jun 16, 2022
* Fixes issue go-gitea#19603
* fill HeadCommitID in PullRequest
* compare real commits ID as check for merging
jedi7 added a commit to jedi7/gitea that referenced this issue Jul 10, 2022
* Fixes issue go-gitea#19603
* fill HeadCommitID in PullRequest
* compare real commits ID as check for merging
* basd on zeripath patch
wxiaoguang pushed a commit that referenced this issue Jul 13, 2022
* Fixes issue #19603 (Not able to merge commit in PR when branches content is same, but different commit id)
* fill HeadCommitID in PullRequest
* compare real commits ID as check for merging
* based on @zeripath patch in #19738
jedi7 added a commit to jedi7/gitea that referenced this issue Jul 13, 2022
* Fixes issue go-gitea#19603
* fill HeadCommitID in PullRequest
* compare real commits ID as check for merging
* basd on zeripath patch
@wxiaoguang wxiaoguang linked a pull request Jul 13, 2022 that will close this issue
zeripath added a commit that referenced this issue Jul 13, 2022
Backport #20290

* Fix #19603
* fill HeadCommitID in PullRequest
* compare real commits ID as check for merging


Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: Andrew Thornton <art27@cantab.net>
@wxiaoguang
Copy link
Contributor

zjjhot added a commit to zjjhot/gitea that referenced this issue Jul 14, 2022
* giteaofficial/main:
  Fix icon margin in user/settings/repos (go-gitea#20281)
  Fix org label open count, including close count issue (go-gitea#20353)
  [skip ci] Updated translations via Crowdin
  Prevent context deadline error propagation in GetCommitsInfo (go-gitea#20346)
  Add missing return for when topic isn't found (go-gitea#20351)
  Upgrade to Node 18 on CI (go-gitea#20340)
  Fix checks in PR for empty commits go-gitea#19603 (go-gitea#20290)
  Use default values when provided values are empty (go-gitea#20318)
  Add tests for the host checking logic, clarify the behaviors (go-gitea#20328)
  Changelog for 1.16.9 (update) (go-gitea#20341) (go-gitea#20343)
  Fix various typos (go-gitea#20338)
  Correctly handle draft releases without a tag (go-gitea#20314)
  Add write check for creating Commit status (go-gitea#20332)
  Remove blue text on migrate page (go-gitea#20273)
  Updated dead link to Madeleine.js source (go-gitea#20322)
vsysoev pushed a commit to IntegraSDL/gitea that referenced this issue Aug 10, 2022
* Fixes issue go-gitea#19603 (Not able to merge commit in PR when branches content is same, but different commit id)
* fill HeadCommitID in PullRequest
* compare real commits ID as check for merging
* based on @zeripath patch in go-gitea#19738
@go-gitea go-gitea locked and limited conversation to collaborators May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants