# [BUG?] Issue with merging from another branch after replacing subdirectory with submodule

3 messages from 2017-04-06 to 2017-04-07. Participants: Ben Nason, Stefan Beller.
Thread: https://gitlist.dev/t/45615

## Ben Nason, 2017-04-06 06:10

Subject: [BUG?] Issue with merging from another branch after replacing subdirectory with submodule
Message-ID: <CAA-fqg2EwfMQ-KoAMHDFca1c7jpQgihhqsLejEK3Zs8O1D4DLg@mail.gmail.com>
URL: https://gitlist.dev/e/CAA-fqg2EwfMQ-KoAMHDFca1c7jpQgihhqsLejEK3Zs8O1D4DLg%40mail.gmail.com

```
Hi,

In git if you replace a subdirectory with a submodule in one branch,
every successive merge from another branch without that change will
cause a conflict. To reproduce this please see below (DOS batch file).

Is this expected behavior?

Thanks,
Benbuck

:: prep simple repo with subdir
git init repo
pushd repo
echo foo > foo.txt
git add --all
git commit -m "foo"
mkdir sub
echo bar > sub\bar.txt
git add --all
git commit -m "bar"
popd

:: prep simple submodule
git init submod
pushd submod
echo baz2 > baz.txt
git add --all
git commit -m "baz2"
popd

:: in a new branch: delete subdir, replace with submodule
pushd repo
git checkout -b resub
git rm -rf sub
git commit -m "delete subdir"
git submodule add ../submod sub
git submodule update --init
git commit -m "add submod"

:: in old branch: make an unrelated change
git checkout master
git clean -fd
git rs --hard master
echo foo2 > foo.txt
git commit --all -m "foo2"

:: switch back to new branch
git checkout resub
git rs --hard resub
git submodule update --init
pushd sub
git reset --hard master
popd

:: all is good so far, now merge
git merge master
git status
@echo !!!!!! note the above merge conflict !!!!!!
pause
:: resolve the conflict to keep the submodule
git reset sub
git commit --no-edit


:: make another change to old branch
git checkout master
git clean -fd
git rs --hard master
echo foo3 > foo.txt
git commit --all -m "foo3"
git checkout resub
git rs --hard resub
git submodule update --init
pushd sub
git reset --hard master
popd

:: merge again
git merge master
git status
@echo !!!!!! note that the conflict happens on every single merge !!!!!!
pause

popd

```

## Stefan Beller, 2017-04-06 23:05

Subject: Re: [BUG?] Issue with merging from another branch after replacing subdirectory with submodule
Message-ID: <CAGZ79kaGQHvGv-ZpfppbATucrJWVdS8Lq33CKs5AbV7qDGE3BA@mail.gmail.com>
URL: https://gitlist.dev/e/CAGZ79kaGQHvGv-ZpfppbATucrJWVdS8Lq33CKs5AbV7qDGE3BA%40mail.gmail.com
In-Reply-To: <CAA-fqg2EwfMQ-KoAMHDFca1c7jpQgihhqsLejEK3Zs8O1D4DLg@mail.gmail.com>

```
On Wed, Apr 5, 2017 at 11:10 PM, Ben Nason <bnason@netflix.com> wrote:
> Hi,
>
> In git if you replace a subdirectory with a submodule in one branch,
> every successive merge from another branch without that change will
> cause a conflict. To reproduce this please see below (DOS batch file).
>
> Is this expected behavior?

Yes.

"git submodule update [--init]" only (creates or) updates existing
submodules. It doesn't take care of removing submodules that are
no longer recorded in the tree.

"git merge" currently also does not touch submodules. (we may have
git merge --recurse-submodules soon, though). So as soon as there
is a conflict between the submodule (or an unrelated repo, who happens
to live inside this other repo), and new directories/files that would appear,
the merge errors out.

Ideally Git would be smarter than the current behavior.

Stefan

```

## Ben Nason, 2017-04-07 15:25

Subject: Re: [BUG?] Issue with merging from another branch after replacing subdirectory with submodule
Message-ID: <CAA-fqg1DGUmdXEAnYfEuK2Wts2wLfEr2hhharAghbCexL1+yAw@mail.gmail.com>
URL: https://gitlist.dev/e/CAA-fqg1DGUmdXEAnYfEuK2Wts2wLfEr2hhharAghbCexL1%2ByAw%40mail.gmail.com
In-Reply-To: <CAGZ79kaGQHvGv-ZpfppbATucrJWVdS8Lq33CKs5AbV7qDGE3BA@mail.gmail.com>

```
Hi Stefan,

Thanks for the reply. Is there any known workaround for this
situation, so that a manual resolve isn't needed for every single
merge in this scenario?

Thanks,
Benbuck


On Thu, Apr 6, 2017 at 4:05 PM, Stefan Beller <sbeller@google.com> wrote:
> On Wed, Apr 5, 2017 at 11:10 PM, Ben Nason <bnason@netflix.com> wrote:
>> Hi,
>>
>> In git if you replace a subdirectory with a submodule in one branch,
>> every successive merge from another branch without that change will
>> cause a conflict. To reproduce this please see below (DOS batch file).
>>
>> Is this expected behavior?
>
> Yes.
>
> "git submodule update [--init]" only (creates or) updates existing
> submodules. It doesn't take care of removing submodules that are
> no longer recorded in the tree.
>
> "git merge" currently also does not touch submodules. (we may have
> git merge --recurse-submodules soon, though). So as soon as there
> is a conflict between the submodule (or an unrelated repo, who happens
> to live inside this other repo), and new directories/files that would appear,
> the merge errors out.
>
> Ideally Git would be smarter than the current behavior.
>
> Stefan

```
