-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Tweak "conflict markers" diagnostic by detecting git state #150233
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
base: main
Are you sure you want to change the base?
Conversation
When detecting "diff markers", inspect the current `git` repo's state to see if there is an active rebase. If that is the case, we try to identify whether the rebase is caused by `git rebase` or implicitly by `git pull`. In order to do that we query `git` to ask for the path of `.git/rebase-merge` and then inspect the files `orig-head` (the commit we are rebasing from), `onto` (the commit we are rebasing onto) and `head-name` (the branch being rebased). We modify the labels pointing at the markers to be clear on where each section of code is coming from.
`git rebase` case:
```
error: encountered diff marker
--> src/main.rs:2:1
|
2 | <<<<<<< HEAD
| ^^^^^^^ between this marker and `=======` is the code from branch `master` we're rebasing onto
3 | println!("Hello, main!");
4 | =======
| ------- between this marker and `>>>>>>>` is the code you had in branch `branch-2` that you are rebasing
5 | println!("Hello, branch!");
6 | >>>>>>> e644375 (branch)
| ^^^^^^^ this marker concludes the conflict region
|
= note: conflict markers indicate that a merge was started but could not be completed due to merge conflicts
to resolve a conflict, keep only the code you want and then delete the lines containing conflict markers
= note: for an explanation on these markers from the `git` documentation:
visit <https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_checking_out_conflicts>
```
`git pull` case:
```
error: encountered diff marker
--> src/main.rs:2:1
|
2 | <<<<<<< HEAD
| ^^^^^^^ between this marker and `=======` is the code from the remote branch `origin/main` we're rebasing onto
3 | println!("Hello, 1!");
4 | =======
| ------- between this marker and `>>>>>>>` is the code you had in branch `main` that you are rebasing
5 | println!("Hello, 2!");
6 | >>>>>>> ebbeec7 (second)
| ^^^^^^^ this marker concludes the conflict region
|
= note: conflict markers indicate that a merge was started but could not be completed due to merge conflicts
to resolve a conflict, keep only the code you want and then delete the lines containing conflict markers
= note: for an explanation on these markers from the `git` documentation:
visit <https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_checking_out_conflicts>
```
Also, the generic `help` description had the `git pull` case flipped from what it should have been.
|
rustbot has assigned @petrochenkov. Use |
| msg_start = | ||
| format!("from the remote branch {branch} we're rebasing onto"); | ||
| } else { | ||
| msg_start = format!("from the remote branch we're rebasing onto"); |
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.
Given the logic above this might need to be more generic, calling it a branch instead of a remote branch, or reference the commit sha...



When detecting "diff markers", inspect the current
gitrepo's state to see if there is an active rebase. If that is the case, we try to identify whether the rebase is caused bygit rebaseor implicitly bygit pull. In order to do that we querygitto ask for the path of.git/rebase-mergeand then inspect the filesorig-head(the commit we are rebasing from),onto(the commit we are rebasing onto) andhead-name(the branch being rebased). We modify the labels pointing at the markers to be clear on where each section of code is coming from.git rebasecase:git pullcase:Also, the generic
helpdescription had thegit pullcase flipped from what it should have been.