Create a cohort (i.e. "People") and two courses
in courses as admin create instances of cohort enrolment linking to "People", select "Create new group"
Make sure that in the both courses the automatically created group is called "People cohort" and does not have any increments in the end
Create another course and create "People cohort" group inside it (empty).
Add instance of cohort enrolment and select "Create new group".
Make sure the grou "People cohort (2)" was cretaed and populated with users (if there were any in the cohort)
This was noticed on MDL-17929 by stronk7 (see comment), but the code there was copy-pasted from the function enrol_cohort_create_new_group() introduced in issue MDL-49380
When looking for existing group we look globally instead of within the given course.
Discovered while testing
MDL-17929Auto-Create Groups: Populate groups from Child Courses in META courses
Closed
is a regression caused by
MDL-49380Create new group in the enrol cohort to the course