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

GitConflictMarkerBear #1334

Open
yukiisbored opened this issue Jan 21, 2017 · 12 comments
Open

GitConflictMarkerBear #1334

yukiisbored opened this issue Jan 21, 2017 · 12 comments

Comments

@yukiisbored
Copy link
Member

yukiisbored commented Jan 21, 2017

There should a bear to avoid left over git conflict markers to easily find these markers and avoid them from reaching production or being merged.

An example of a conflict marker generated by git:

+<<<<<<< HEAD
+                  <input id="query" id="query" name="query" type="text" placeholder="Query Text" class="form-control input-md" required>
+=======
+                   <input id="query" id="query" name="query" type="text" placeholder="Query Text" class="form-control input-md" required="">
+>>>>>>> add0f2f... 
+=======
@adhikasp
Copy link
Member

adhikasp commented Feb 3, 2017

Hi, cool idea!
I'm interested to take on this issue. 👷‍♂️

@yukiisbored
Copy link
Member Author

yukiisbored commented Feb 4, 2017

@adhikasp It looks like you're new, have you tried doing the newcomer issues, first?
It helps as an introduction to the code base

@yukiisbored
Copy link
Member Author

yukiisbored commented Feb 4, 2017

Ah, I just found your first PR for coala, please finish that one first before you do this one, thanks <3
If you want help with anything related to coala or your PR, feel free to ask on our gitter

@kaustubhhiware
Copy link
Member

I am interested to work on this.
Can I assign it to myself ? Or should I take on this after I've made some more merged PR's ? (I've only completed a difficulty/newcomer issue)

@yukiisbored
Copy link
Member Author

yukiisbored commented Mar 9, 2017

@kaustubhhiware You can do this one, right away. Just do cobot assign <issue link> in our gitter chat.

@palash25
Copy link
Member

@yukiisbored the PR to this issue hasn't been updated since April, I think the assignee has abandoned it. I would like to work on this, seems like a cool bear.

@Makman2
Copy link
Member

Makman2 commented Dec 28, 2017

Reassigning due to inactivity.

@palash25
Copy link
Member

palash25 commented Jan 5, 2018

I'm a little confused about what this bear would do?
Will it just detect all the merge conflicts in a file? or will it provide the user some functionality to rectify merge conflicts? or will it just be used to detect conflict markers and remove them from the file?

@Makman2
Copy link
Member

Makman2 commented Jan 5, 2018

or will it just be used to detect conflict markers and remove them from the file?

that's it 👍

@palash25
Copy link
Member

palash25 commented Jan 18, 2018

@Makman2 I wrote some logic to detect the possible merge conflicts. The merge conflicts are detected and printed as debug messages in the correct order but when I yield the results the first conflict appears at the last and the rest are ordered.
Here's the code:

class GitConflictBear(LocalBear):
    def run(self, filename, file):
        self.debug('Checking file', filename)
        merge_conflict_starts = -1
        merge_conflict_split = -1
        merge_conflict_ends = -1
        
        conflict_free_code = ''
        local_commit = ''
        remote_commit = ''
        
        for line_number, line in enumerate(file):
            if merge_conflict_starts == -1:
                if line.startswith('<<<<<<< '):
                    merge_conflict_starts = line_number
                else:
                    conflict_free_code += line

            if merge_conflict_split == -1:
                if line.startswith('========='):
                    merge_conflict_split = line_number
                else:
                    conflict_free_code += line

            if merge_conflict_ends == -1:
                if line.startswith('>>>>>>> '):
                    merge_conflict_ends = line_number
                else:
                    conflict_free_code += line
            else:
                self.debug(merge_conflict_starts+1, merge_conflict_split+1, merge_conflict_ends+1)
                yield self.new_result(message="Possible merge conflict found between {} and {}"
                .format(merge_conflict_starts+1, merge_conflict_ends+1), file=filename)(diffs)

                merge_conflict_starts = -1
                merge_conflict_ends = -1
                merge_conflict_split = -1

Here's the coala output:

[DEBUG][18:07:34] 4 7 9
[DEBUG][18:07:34] 11 13 14
[DEBUG][18:07:34] 20 23 25
[DEBUG][18:07:34] 27 29 30

conflict.txt
**** GitConflictBear [Section: cli | Severity: NORMAL] ****
!    ! Possible merge conflict found between 11 and 14
[    ] *0. Do (N)othing
[    ]  1. (O)pen file
[    ]  2. Add (I)gnore comment
[    ] Enter number (Ctrl-D to exit): 

conflict.txt
**** GitConflictBear [Section: cli | Severity: NORMAL] ****
!    ! Possible merge conflict found between 20 and 25
[    ] *0. Do (N)othing
[    ]  1. (O)pen file
[    ]  2. Add (I)gnore comment
[    ] Enter number (Ctrl-D to exit): 

conflict.txt
**** GitConflictBear [Section: cli | Severity: NORMAL] ****
!    ! Possible merge conflict found between 27 and 30
[    ] *0. Do (N)othing
[    ]  1. (O)pen file
[    ]  2. Add (I)gnore comment
[    ] Enter number (Ctrl-D to exit): 

conflict.txt
**** GitConflictBear [Section: cli | Severity: NORMAL] ****
!    ! Possible merge conflict found between 4 and 9
[    ] *0. Do (N)othing
[    ]  1. (O)pen file
[    ]  2. Add (I)gnore comment
[    ] Enter number (Ctrl-D to exit): 

Shouldn't the conflict found at lines 4 and 9 be at the top?
Here's the conflict file:

# A file with merge conflict markers
print 'Line 1 does something'
print 'No issues till here'
<<<<<<< HEAD: mergetest
print 'This is my third line'
print 'Original fourth line unchanged'
=========
print 'This is a fourth line I am adding'
>>>>>>> 4e2b407f501b68f8588aa645acafffa0224b9b78: mergetest

<<<<<<< HEAD: mergetest
print 'Fifth line that could be removed in the next commit'
=========
>>>>>>> 4e2b407f501b68f8588aa645acafffa0224b9b78: mergetest
print 'Let me know how this looks'

# A file with merge conflict markers
print 'Line 1 does something'
print 'No issues till here'
<<<<<<< HEAD: mergetest
print 'This is my third line'
print 'Original fourth line unchanged'
=========
print 'This is a fourth line I am adding'
>>>>>>> 4e2b407f501b68f8588aa645acafffa0224b9b78: mergetest

<<<<<<< HEAD: mergetest
print 'Fifth line that could be removed in the next commit'
=========
>>>>>>> 4e2b407f501b68f8588aa645acafffa0224b9b78: mergetest
print 'Let me know how this looks'

@Makman2
Copy link
Member

Makman2 commented Jan 18, 2018

Could you move such code discussions rather to the PR? Discussing implementation details on issues blasts the discussion log.

@palash25
Copy link
Member

Ok I'll make a half baked PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

6 participants