intellij-community icon indicating copy to clipboard operation
intellij-community copied to clipboard

IDEA-157915: Fix symbolic-ref in HEAD #2

Open illabefat opened this issue 9 years ago • 15 comments

illabefat avatar Jul 21 '16 18:07 illabefat

@klikh Here is a fix for problem with packed-refs. For now there is only a problem with drawing of Branch view (ctrl+V->7) It correctly says that master is a current branch. The problem is that you can't switch from sym-link branch to original one: you don't have it 'Local Branches' section. (See the attached image) I don't know what is the best solution here. And I don't know where to look for the code of this dialog =(

Example: Branch view after executing git checkout ilzi, which points to master screen shot 2016-07-21 at 20 07 05

illabefat avatar Jul 21 '16 18:07 illabefat

OK, it seems that the problem is a bit more complex than it seemed at first. I think we have to decide on the UI first, and then make an implementation so that it matches the UI we agree on.

Here are my thoughts on this: 0. Let user checkout ilzi branch which is a link to master.

  1. The Push dialog should treat ilzi the same as master, in particular, use master's tracked branch as ilzi's tracked branch. 1.1. Same for Update Project action.
  2. If I checkout ilzi, I should see "Current branch: ilzi" both in the status bar and in the "Git Branches" popup footer. Here I disagree with the command line prompt that shows master.

What do you think about 2, and what other use cases there are?

klikh avatar Jul 25 '16 15:07 klikh

Hm. Have you rebased the pull request? I don't see neither code comments, nor the pull request discussion. Or are they hidden somewhere inside github UI?

klikh avatar Jul 25 '16 15:07 klikh

I didn't manage to reopen old PR. Either I am github newbie, or github thinks that reopening merged PR is strange, or both of them. So I created a new PR.

illabefat avatar Jul 25 '16 15:07 illabefat

Ah, my bad. I thought that you've opened a new PR, but didn't find it because I didn't look in closed PRs. Here it is for reference: https://github.com/JetBrains/intellij-community/pull/424

klikh avatar Jul 25 '16 15:07 klikh

Regarding usecases, as I understand there are quite few symlink usecases:

  • List of branches
  • Checkout symlink
  • Understand current branch
  • Create, update, delete symlinks (out of scope for now)

All the other time git works with normal physical branches. I don't think that IDEA should behave in different way from 'official' git client. Official git client shows master as a current branch, and I think that we should do the same. I would think about fixing branch view to understand symlinks in head: i.e. 'Current branch: master(ilzi)', not filtering of master from branch list, etc. But we can also introduce some cool method getRealBranchFromHead and call it from almost everywhere...

illabefat avatar Jul 25 '16 15:07 illabefat

It seems that to solve these issues, instead of treating symrefs as normal branches and resolving them while reading the repository, we'll have to introduce a special conception for them, e.g. something like GitSymbolicRef that would link an actual GitBranch (or a symbolic ref of previous level) and resolve to the hash or to the branch when needed.

Btw, could you please share your use cases: why do you use links at all, instead of operating the real branches? AFAIK they are not an official feature of Git: back in 2011 Junio said that only the HEAD and refs/remotes/origin/HEADs are officially supported links. Has something changed after that?

klikh avatar Jul 25 '16 16:07 klikh

Well... we have quite a long names of branches. I want to have alias stable for stable branch =) Actually IntelliJ's branch view solves this problem, but I perform checkout from terminal, because it usually requires couple more actions. Not sure if something has changed since Junio's answer, I just wanted to make my work a bit more comfortable.

illabefat avatar Jul 25 '16 16:07 illabefat

So do you mind trying the approach with separate class for symbolic refs?

And I don't know where to look for the code of this dialog

It is GitBranchPopup. Note that multi-repository case is supported there: branches common for all repositories are displayed at the top-level.

I don't think that IDEA should behave in different way from 'official' git client. Official git client shows master as a current branch, and I think that we should do the same.

Since we see that there is no official support of symbolic refs, following git client looks less necessary. On the other hand, the approach with braces looks nice. Just in reverse order: "stable (master)". IMHO it would be weird to see "Current branch: master" after checking out "stable", wouldn't it? In addition to that, if we display master (or even "master (stable)"), it would be unclear why there is "master" in Git | Branches popup.

klikh avatar Jul 26 '16 15:07 klikh

Yes, I'll probably try to do something about this

Just in reverse order: "stable (master)". IMHO it would be weird to see "Current branch: master" after checking out "stable", wouldn't it?

Well, it a good point =) I've just written first to come in mind.

What is the case of multi-repository? 2 modules from different folders in one project? git repo inside other git repo?

illabefat avatar Jul 26 '16 15:07 illabefat

What is the case of multi-repository? 2 modules from different folders in one project? git repo inside other git repo?

Both, and anything else you can imagine. For example, full intellij-community project consists of 3 repositories nested one into another: this one + /android + /tools-base. We have users with dozens of repositories (usually, some web frameworks with many small repositories for each of web site modules).

And we even have users with mixed VCS projects having e.g. a Git repository, a Hg repository and an SVN repository in a single project. However, this case is not related to the original issue: here we care only about multiple Git repositories.

Repositories are registered in Settings | Version Control by specifying the path and the VCS.

In IDEA some operations are synchronous for all repositories by default (Update Project, Push, Commit), some have no sync support yet (e.g. Git | Pull, Git | Stash). Branches can operate synchronously or individually depending on the value of Settings | Version Control | Git | Control repositories synchronously. If this checkbox is enabled, you can e.g. checkout a common branch in all repositories. See this blog post for details.

klikh avatar Jul 26 '16 15:07 klikh

@klikh Here is a draft of fix. Please, have a look at this. Current branch is written as 'ilzi(master)', symbolic-refs in list of branches point at actual remote. screen shot 2016-08-22 at 22 30 00

Push is being performed to actual remote, pull also works. screen shot 2016-08-22 at 22 32 04

If this is OK, I will continue with some tests for it

illabefat avatar Aug 22 '16 20:08 illabefat

Looks good. I'd add a space between "ilzy" and "(master)".

Will add some comments to the code.

And could you please squash 39b8698 and 7966365, to avoid unfinished work in history ;)

klikh avatar Aug 26 '16 12:08 klikh

Please add tests at least for the following cases:

  1. HEAD points to reflink => current branch is reflink, but its hash is correctly resolved.
  2. reflink points to another reflink which point to a real ref
  3. reflink points to remote branch.
  4. cyclic reflinks don't get resolved (probably absent in the list of branches), but don't crash the whole thing :)

You may use either GitNewRepositoryReader or GitRepositoryReader approach, as you wish. Personally, I find New one more clear since it allows to prepare the case manually, and not to look into testData to understand the test case.

klikh avatar Aug 26 '16 13:08 klikh

@illabefat So is this feature is still actual for you?

klikh avatar Jul 22 '18 16:07 klikh