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

Compare branches, commits and tags with each other #6991

Merged
merged 26 commits into from
Jun 7, 2019

Conversation

saitho
Copy link
Contributor

@saitho saitho commented May 19, 2019

Resolves #4567

Currently the comparing branches and commits is two separate routes and the logic is spread on multiple files. This pull request puts that logic in one place and allows comparing commits, branches and tags among each other (e.g. compare a branch with a commit, compare a tag with a branch, etc).

When comparing two branches there will be a button "Create pull request" (similarly to GitHub) which will show the pull request form.

Screenshots

Comparing branches (=> Pull Request)

compare_branch_forkedBranch

Comparing commit and tag

compare_commit_tag

Comparing tag and branch

compare_tag_branch

Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
…ith eachother

Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
…e_tags

# Conflicts:
#	public/css/index.css
#	routers/repo/pull.go
Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
@lunny lunny added the type/feature Completely new functionality. Can only be merged if feature freeze is not active. label May 19, 2019
routers/repo/compare.go Outdated Show resolved Hide resolved
routers/repo/pull.go Outdated Show resolved Hide resolved
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label May 19, 2019
@codecov-io
Copy link

codecov-io commented May 19, 2019

Codecov Report

Merging #6991 into master will increase coverage by 0.05%.
The diff coverage is 57.84%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6991      +/-   ##
==========================================
+ Coverage   41.58%   41.64%   +0.05%     
==========================================
  Files         446      447       +1     
  Lines       60873    60888      +15     
==========================================
+ Hits        25317    25358      +41     
+ Misses      32271    32243      -28     
- Partials     3285     3287       +2
Impacted Files Coverage Δ
routers/repo/commit.go 29.43% <0%> (+5.2%) ⬆️
models/pull.go 49.76% <0%> (+0.04%) ⬆️
routers/routes/routes.go 82.85% <100%> (-0.07%) ⬇️
routers/repo/pull.go 31.05% <50%> (-5.31%) ⬇️
routers/repo/compare.go 53.67% <53.67%> (ø)
routers/api/v1/repo/pull.go 37.89% <85.71%> (ø) ⬆️
modules/git/repo_commit.go 48.1% <85.71%> (+1.02%) ⬆️
modules/git/repo_compare.go 66.66% <88.46%> (ø)
models/unit.go 62.16% <0%> (-5.41%) ⬇️
routers/repo/view.go 42.02% <0%> (-1.02%) ⬇️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bd55f6f...76c6fa9. Read the comment docs.

routers/repo/compare.go Outdated Show resolved Hide resolved
Co-Authored-By: zeripath <art27@cantab.net>
@lafriks lafriks added this to the 1.9.0 milestone May 23, 2019
@zeripath
Copy link
Contributor

I'm not a fan of polluting the main repository and sticking objects within its object database. (Although this is not your fault.)

I think we should be either, creating a new temporary repository with references to the head branches and then pulling the changes there, or setting:

GitAlternativeObjectDirectories = "GIT_ALTERNATE_OBJECT_DIRECTORIES"
GitObjectDirectory = "GIT_OBJECT_DIRECTORY"

appropriately as per:

env := append(os.Environ(),
private.GitAlternativeObjectDirectories+"="+gitAlternativeObjectDirectories,
private.GitObjectDirectory+"="+gitObjectDirectory,
private.GitQuarantinePath+"="+gitObjectDirectory,
)

And fetch into a non-reffed branch.

Now this doesn't have to be done in this PR, but we should do it.

…e_tags

# Conflicts:
#	templates/repo/diff/page.tmpl
Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
@saitho
Copy link
Contributor Author

saitho commented May 27, 2019

I'm not a fan of polluting the main repository and sticking objects within its object database.
...
Now this doesn't have to be done in this PR, but we should do it.

We should create a new issue for that. :)

@richmahn
Copy link
Contributor

richmahn commented May 29, 2019

Can we compare commits with their 9 character hash that we usually see in lists of commits? I can't do this: http://localhost:3000/root/test/compare/3c5db14a4...d2f998efb but can do this: http://localhost:3000/root/test/compare/3c5db140a4f6778cd4a50217fafd3a0a0d3d6481...d42f998efbe325b5d4431ec1e56d227a94cb777a. On Github I can do it with the short hash that they show
(e.g. richmahn/test@ff58894...a877a10)

While we show 9 characters of the commit SHA and GitHub shows only 7, Gitea commit URL allows for 7, so would be great if compare also took 7 or more characters to find the commit SHA to compare.

@saitho
Copy link
Contributor Author

saitho commented May 29, 2019

Can we compare commits with their 9 character hash that we usually see in lists of commits?

No, we can't. Gitea uses go-git to interact with Git repositories. As I explained in #4567, go-git does not support short hashes at the moment.

@richmahn
Copy link
Contributor

@saitho Ah, thanks for that explanation. Didn't know.

@richmahn
Copy link
Contributor

@saitho Moving our conversation from the issue to here. I know from https://github.com/go-gitea/gitea/blob/master/routers/repo/commit.go#L200 that this is what figures out the commit ID for a short hash or a branch name if the string isn't 40 characters long. Uses rev-parse of the git command, such as git rev-parse 9406344 => 940634488e90fc72315bba52795806a942f0622d. Would think and hope that can be used?

routers/repo/compare.go Outdated Show resolved Hide resolved
Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
@saitho
Copy link
Contributor Author

saitho commented May 30, 2019

Now this doesn't have to be done in this PR, but we should do it.

We should do that here, because the temporary branch I created when head repository is a fork shows up in the branch list. Even if we deleted it afterwards a user might still be able to check it out. ^^

EDIT: At least I was left with a temporary branch still being visible in Gitea...

@saitho
Copy link
Contributor Author

saitho commented May 30, 2019

We should do that here, because the temporary branch I created when head repository is a fork shows up in the branch list.

Might have been a leftover from development. Removed it once and it didn't come back when I tested the compare functionality.
The temporary branch even belongs to the remote repository which is removed after comparing. So that should be okay for now.

routers/api/v1/repo/pull.go Outdated Show resolved Hide resolved
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jun 3, 2019
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jun 6, 2019
@techknowlogick techknowlogick merged commit 311ce2d into go-gitea:master Jun 7, 2019
jeffliu27 pushed a commit to jeffliu27/gitea that referenced this pull request Jul 18, 2019
* Supports tags when comparing commits or branches

Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>

* Hide headline when only comparing and don't load unused data

Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>

* Merges compare logics to allow comparing branches, commits and tags with eachother

Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>

* Display branch or tag instead of commit when used for comparing

Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>

* Show pull request form after click on button

Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>

* Transfers relevant pull.go changes from master to compare.go

Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>

* Fixes error when comparing forks against a commit or tag

Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>

* Removes console.log from JavaScript file

Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>

* Show icon next to commit reference when comparing branch or tag

Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>

* Updates css file

Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>

* Fixes import order

* Renames template variable

* Update routers/repo/compare.go

Co-Authored-By: zeripath <art27@cantab.net>

* Update from master

Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>

* Allow short-shas in compare

* Renames prInfo to compareInfo

Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>

* Check PR permissions only if compare is pull request

Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>

* Adjusts comment

Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>

* Use compareInfo instead of prInfo
@saitho saitho deleted the feature/4567-Compare_tags branch December 18, 2019 18:53
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhance /compare/ for tags and abbreviated commit shas
8 participants