Instead of figuring out why renames of submodules are not detected by git 
merge, I worked around the issue by writing a script to delete and re-add 
the submodule separately in the maintenance and development branches:


#!/bin/bash -ex

# -e: Exit on error
# -x: Print commands as they are executed

# move_submodule: Move a submodule in a development branch while keeping
# it in the same location in a maintenance branch.  If git mv is used to
# move the submodule instead, there will be a merge conflict every time
# changes are merged up to the development branch from the maintenance
# branch.  This script works by deleting the submodule and then readding
# it separately in both branches.  If git mv has already been attempted,
# the moved submodule is also deleted.

if [ $# -ne 5 ]; then
    echo $0: usage: $0 maintenance_branch development_branch submodule_url 
old_path new_path
    exit 1
fi

maintenance=$1
development=$2
submodule_url=$3
old_path=$4
new_path=$5

repository=`git rev-parse --show-toplevel`
cd $repository

# Get branches ready
git checkout $maintenance
git pull
git checkout $development
git pull
git submodule update --init --recursive
git merge $maintenance --no-edit
git push

# Delete submodule in $development if you already moved it with git mv.
if [ -d "$new_path" ]; then
    git rm $new_path
    git commit -m"Remove $new_path temporarily to resolve conflict with 
$maintenance."
    git push
fi

# Delete submodule in $maintenance and merge up.
git checkout $maintenance
git submodule update --init --recursive
git rm $old_path
git commit -m"Remove $old_path temporarily to resolve conflict with 
$development."
git push
git checkout $development
git submodule update --init --recursive
git merge $maintenance --no-edit
git push

# Re-add submodule in new location in $development.
git submodule add --force $submodule_url $new_path
git commit -m"Re-add $new_path"
git push

# Re-add submodule in original location in $maintenance.
git checkout $maintenance
rm -rf $new_path
git submodule update --init --recursive
git submodule add --force $submodule_url $old_path
git commit -m"Re-add $old_path."
git push

# Merge up, discarding maintenance submodule change.
git checkout $development
rm -rf $old_path
git submodule update --init --recursive
git merge $maintenance --no-edit -s ours
git push



On Tuesday, July 10, 2018 at 12:51:48 PM UTC-5, waxline wrote:
>
> After moving a submodule in a development branch, I get a merge conflict 
> every time I merge changes up from the master branch. To resolve, I must git 
> add mysubmodule. How can I avoid resolving this conflict every time I 
> merge up?  Here is a script which illustrates the problem:
>
> cd ~/src
> git init MyProduct
> git init MySubmodule
> cd MySubmodule
> echo "foo" > foo.txt
> git add foo.txt
> git commit -m "Add foo.txt"
> cd ../MyProduct
> echo "bar" > bar.txt
> git add bar.txt
> git commit -m "Add bar.txt"
> git submodule add ../MySubmodule
> git commit -m "Add MySubmodule"
> git branch development
> git checkout development
> git mv MySubmodule OurSubmodule
> git commit -m "Move MySubmodule to OurSubmodule."
> git checkout master
> rm -rf OurSubmodule
> git submodule update --init
> echo "barbar" > bar.txt
> git commit -am"Update bar.txt"
> git checkout development
> rm -rf MySubmodule
> git submodule update --init
> git merge master
> git add OurSubmodule
> git commit -am"Resolve conflict"
>
>
>

-- 
You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to