【问题标题】:Commit Git "Supermodule" using post-commit hook of submodule with grunt-git and grunt-githooks使用带有 grunt-git 和 grunt-githooks 的子模块的提交后钩子提交 Git“超级模块”
【发布时间】:2014-08-31 06:16:21
【问题描述】:

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

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

我通过 Grunt 使用 grunt-githooksgrunt-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');
};

【问题讨论】:

    标签: git gruntjs git-submodules githooks post-commit-hook


    【解决方案1】:

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

    你需要先取消设置GIT_DIR,然后执行git命令(as in this hook)。

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

    【讨论】:

      猜你喜欢
      • 2012-06-06
      • 2021-12-07
      • 1970-01-01
      • 2012-09-13
      • 2013-01-03
      • 1970-01-01
      • 1970-01-01
      • 2021-05-06
      • 2012-05-31
      相关资源
      最近更新 更多