- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 2.3k
 
fix ambiguous branch name #2224
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
fix ambiguous branch name #2224
Conversation
6fd63ac    to
    4722ac0      
    Compare
  
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
couple things :)
        
          
                pkg/commands/models/branch.go
              
                Outdated
          
        
      | } | ||
| 
               | 
          ||
| func (b *Branch) IsDetachedHead() bool { | ||
| return b.DisplayName != "" | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather add a new field called DetachedHead (bool) than depend on this display name because I can imagine the display name being populated for a branch that's not a detached head
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 done
| ) | ||
| 
               | 
          ||
| var CheckoutByName = NewIntegrationTest(NewIntegrationTestArgs{ | ||
| Description: "Try to checkout branch by name.", | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add some more to this description about the specific bug we're trying to defend against? That will help people understand why the test is slightly more complicated than just directly checking out a branch by name
4e206fa    to
    8982166      
    Compare
  
    8982166    to
    458d68a      
    Compare
  
            
          
                pkg/commands/loaders/branches.go
              
                Outdated
          
        
      | *common.Common | ||
| getRawBranches func() (string, error) | ||
| getCurrentBranchName func() (string, string, error) | ||
| getCurrentBranchName func() (string, string, bool, error) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function returns enough values that we should have it return a struct with those values as fields. That will make it clearer at the call site what's being returned. And then we can call it getCurrentBranchInfo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more thing :)
458d68a    to
    ec6f706      
    Compare
  
    | Branches() (map[string]*config.Branch, error) | ||
| } | ||
| 
               | 
          ||
| type BranchInfo struct { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
define in loaders instead of git_commands to avoid import cycles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It sucks that we have to do this: we ought to either merge the loaders directory into the git_commands directory if it's causing these kinds of issues. But we can do that in another PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've created an issue for this: #2248
ec6f706    to
    9ab9d78      
    Compare
  
            
          
                pkg/commands/loaders/commits_test.go
              
                Outdated
          
        
      | getCurrentBranchName: func() (string, string, error) { | ||
| return scenario.currentBranchName, scenario.currentBranchName, nil | ||
| getCurrentBranchInfo: func() (BranchInfo, error) { | ||
| return BranchInfo{scenario.currentBranchName, scenario.currentBranchName, false}, nil | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use field names here? Just because it makes it clearer what's happening
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ryooooooga just one more thing :)
test: add an integration test for checkout branch by name fix: fix full ref name of detached head refactor: refactor current branch loader chore: use field name explicitly
a09e388    to
    52a2e4c      
    Compare
  
    | 
           @Ryooooooga I've fixed some merge conflicts  | 
    
| 
           Nice work!  | 
    
When we try to create a new branch on a branch named
@, it is created at HEAD.git branch @ HEAD~~~launch lazygit and
n(new branch) orc(checkout by name) on branch@type a branch name and confirm
the new branch is created at
HEADnot@Please check if the PR fulfills these requirements
go run scripts/cheatsheet/main.go generate)docs/Config.md) have been updated if necessary