protected function getExistingAliases($currentGroup, $previousGroup = null)
    {
        $aliases = [];
        foreach (array_filter([$currentGroup, $previousGroup]) as $groupName) {
            foreach ($this->drush->getAliases($groupName) as $name => $alias) {
                // Remove the group prefix from the alias name.
                $name = ltrim($name, '@');
                if (strpos($name, $groupName . '.') === 0) {
                    $name = substr($name, strlen($groupName . '.'));
                }

                $aliases[$name] = $alias;
            }
        }

        return $aliases;
    }