1

我有一个包含许多子模块的 git repo。当我在子模块中提交时,我有一个应该在“超级模块”中提交的 git 钩子。不幸的是,提交后挂钩中的提交失败,因为“超级模块”似乎无法检测到其子模块中的更改。

有没有其他方法可以实现这种行为?

grunt-githooks我通过 Grunt 使用and设置了所有这些grunt-git

下面是我的 gruntfile:

module.exports = function(grunt) {

  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),

    githooks: {
      all: {
        options: {
            dest: '../../../.git/modules/server/modules/mymodule/hooks'
        },
        'post-commit': 'updateSuperModule'
      }
    },

    gitcommit: {
        all: {
            options: {
                message: 'Updated Submodule',
                cwd: '../../..',
                verbose: true
            },
            files: {
                src: ['.']
            }
        }
    },

    gitpush: {
        all: {
            options: {
                cwd: '../../..',
                verbose: true
            }
        }
    }
  });

  grunt.loadNpmTasks('grunt-githooks');
  grunt.loadNpmTasks('grunt-git');
};
4

1 回答 1

0

当一个 repo(这里是一个子模块)的提交想要在另一个 repo(这里是父 repo,在 ' ../../..' 中)执行 git 操作时,更改文件夹是不够的。

您需要先取消设置GIT_DIR,然后执行 git 命令(如在此挂钩中)。

如果你不这样做,状态或添加操作将在子模块的上下文中运行(它刚刚有一个新的提交,并且有一个干净的状态)。

于 2014-07-10T06:41:32.283 回答