It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Git. No Auto Merge.

Mark Tinsley Jul 07, 2014

We're moving to Git from PVCS. One thing we can't quite figure out: auto-merging. It seems this can get you into trouble. For instance, if we start with:

public function getStuff()
{
    $var1   = 'cool cats';
    $result = null;

    foreach ($this->allStuff as $curStuff)
    {
        if ($curStuff == $var1)
        {
            $result = 'indigo';
            break;
        }
    }

    if ($result === null)
    {
        $result = $this->allStuff;
    }

    return $result;
}

Then coder 1 changes it this way in their branch:

public function getStuff()
{
    $var1   = 'cool cats';
    $result = null;

    foreach ($this->allStuff as $curStuff)
    {
        if ($curStuff == $var1)
        {
            $result = 'indigo';
            break;
        }
    }

    if ($result === null)
    {
        $result = 'chicken nuggets';
    }

    return $result;
}

And, coder 2 changes it this way:

public function getStuff()
{
    $var1   = 'cool cats';
    $result = 'berries';

    foreach ($this->allStuff as $curStuff)
    {
        if ($curStuff == $var1)
        {
            $result = 'indigo';
            break;
        }
    }

    return $result;
}

The result would be this (making coder 1's changes bascially dead code):

public function getStuff()
{
    $var1   = 'cool cats';
    $result = 'berries';

    foreach ($this->allStuff as $curStuff)
    {
        if ($curStuff == $var1)
        {
            $result = 'indigo';
            break;
        }
    }

    if ($result === null)
    {
        $result = 'chicken nuggets';
    }

    return $result;
}

Of course, this is a simplified explanation in order to help explain my question. Has anyone had any trouble with this? Does anyone see this as an issue?

1 answer

1 accepted

0 votes
Answer accepted
Balazs Szakmary Jul 07, 2014

As far as I can see, what you want in the end is exactly the result, minus the last if ($result === null) block.

If you do (you should ;)) have any static analysis of your codebase, it will mark this as dead code and eventually someone will remove it.

From the point of view of the correct functionality of the compiled code this is not really an issue. Also, in practice, anything even slightly more complicated than this will not be auto-merged and then the person doing the merge can solve the conflict in a more intelligent way.

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Bitbucket Pipelines

Building a Bitbucket Pipe as a casual coder

...ipe.sh :  #!/bin/bash source "$(dirname "$0")/common.sh" enable_debug extra_args="" if [[ "${DEBUG}" == "true" ]]; then extra_args="--verbose" fi # mandatory variables R...

1,865 views 1 19
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you