def _update_gitmodules(config, location, shadow=False):
    gitmodules_list = __salt__['file.find'](location, name='.gitmodules')
    for gitmodules in gitmodules_list:
        gitmodules_dir = os.path.dirname(gitmodules)
        # Check to see if this is even a repo with submodules. Some repos
        # have git repositories checked into the repository and kept the
        # git configuration files when doing so. This will cause our submodule
        # calls to fail.
        cmd = '/usr/bin/git submodule status --quiet'
        status = __salt__['cmd.retcode'](cmd, gitmodules_dir)
        if status != 0:
            continue
        # Ensure we're working with an unmodified .gitmodules file
        cmd = '/usr/bin/git checkout .gitmodules'
        status = __salt__['cmd.retcode'](cmd, gitmodules_dir)
        if status != 0:
            return status
        # Get a list of the submodules
        submodules = []
        f = open(gitmodules, 'r')
        for line in f.readlines():
            keyval = line.split(' = ')
            if keyval[0].strip() == "path":
                submodules.append(keyval[1].strip())
        f.close()
        if shadow:
            # Tranform .gitmodules based on reference. Point the submodules
            # to the local git repository this repo references.
            reference_dir = gitmodules_dir.replace(location,
                                                   config['location'])
            f = open(gitmodules, 'w')
            for submodule in submodules:
                f.write('[submodule "{0}"]\n'.format(submodule))
                f.write('\tpath = {0}\n'.format(submodule))
                f.write('\turl = {0}/{1}\n'.format(reference_dir, submodule))
            f.close()
        else:
            # Transform .gitmodules file based on url. Point the submodules
            # to the appropriate place on the deployment server. We can base
            # this on a subpath of the repository since the deployment server
            # isn't a bare clone.
            cmd = '/usr/bin/git config remote.origin.url'
            remote = __salt__['cmd.run'](cmd, gitmodules_dir)
            if not remote:
                return 1
            f = open(gitmodules, 'w')
            for submodule in submodules:
                submodule_path = 'modules/{0}'.format(submodule)
                f.write('[submodule "{0}"]\n'.format(submodule))
                f.write('\tpath = {0}\n'.format(submodule))
                f.write('\turl = {0}/{1}\n'.format(remote, submodule_path))
            f.close()
        # Have git update its submodule configuration from the .gitmodules
        # file.
        cmd = '/usr/bin/git submodule sync'
        status = __salt__['cmd.retcode'](cmd, gitmodules_dir)
        if status != 0:
            return status
    return 0
Finds all .gitmodules in a repository, changes all submodules within them
dataset/ETHPy150Open trebuchet-deploy/trebuchet/modules/deploy.py/_update_gitmodules