]> git.ipfire.org Git - thirdparty/git.git/commitdiff
submodule update: allow custom command to update submodule working tree
authorChris Packham <judge.packham@gmail.com>
Wed, 3 Jul 2013 09:02:02 +0000 (21:02 +1200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 3 Jul 2013 17:15:15 +0000 (10:15 -0700)
Users can set submodule.$name.update to '!command' which will cause
'command' to be run instead of checkout/merge/rebase. This allows
the user finer-grained control over how the update is done.

The primary motivation for this was interoperability with stgit;
however being able to intercept the submodule update process may
prove useful for integrating with or extending other tools.

Signed-off-by: Chris Packham <judge.packham@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-submodule.txt
git-submodule.sh
t/t7406-submodule-update.sh

index e5767134b1a2a84c284e87c900948e4530b25576..2f18f7daf80139802e787b9dd22899776dd67ec9 100644 (file)
@@ -159,7 +159,9 @@ update::
        This will make the submodules HEAD be detached unless `--rebase` or
        `--merge` is specified or the key `submodule.$name.update` is set to
        `rebase`, `merge` or `none`. `none` can be overridden by specifying
-       `--checkout`.
+       `--checkout`. Setting the key `submodule.$name.update` to `!command`
+       will cause `command` to be run. `command` can be any arbitrary shell
+       command that takes a single argument, namely the sha1 to update to.
 +
 If the submodule is not yet initialized, and you just want to use the
 setting as stored in .gitmodules, you can automatically initialize the
index 945e296d304a1d1f108571946a6d50fbf238302f..c87515de10037a280dfed3b4751f8f60c4bcbea3 100755 (executable)
@@ -860,6 +860,12 @@ Maybe you want to use 'update --init'?")"
                                say_msg="$(eval_gettext "Submodule path '\$displaypath': merged in '\$sha1'")"
                                must_die_on_failure=yes
                                ;;
+                       !*)
+                               command="${update_module#!}"
+                               die_msg="$(eval_gettext "Execution of '\$command \$sha1' failed in submodule  path '\$prefix\$sm_path'")"
+                               say_msg="$(eval_gettext "Submodule path '\$prefix\$sm_path': '\$command \$sha1'")"
+                               must_die_on_failure=yes
+                               ;;
                        *)
                                command="git checkout $subforce -q"
                                die_msg="$(eval_gettext "Unable to checkout '\$sha1' in submodule path '\$displaypath'")"
index cdb0538392feaffa69675dcd40e7ecf4094f136a..bc7cfcd835a22fbfcdd2105aa8c2410884a52cb2 100755 (executable)
@@ -294,6 +294,35 @@ test_expect_success 'submodule update - checkout in .git/config' '
        )
 '
 
+test_expect_success 'submodule update - command in .git/config' '
+       (cd super &&
+        git config submodule.submodule.update "!git checkout"
+       ) &&
+       (cd super/submodule &&
+         git reset --hard HEAD^
+       ) &&
+       (cd super &&
+        (cd submodule &&
+         compare_head
+        ) &&
+        git submodule update submodule &&
+        cd submodule &&
+        ! compare_head
+       )
+'
+
+test_expect_success 'submodule update - command in .git/config catches failure' '
+       (cd super &&
+        git config submodule.submodule.update "!false"
+       ) &&
+       (cd super/submodule &&
+         git reset --hard HEAD^
+       ) &&
+       (cd super &&
+        test_must_fail git submodule update submodule
+       )
+'
+
 test_expect_success 'submodule init picks up rebase' '
        (cd super &&
         git config -f .gitmodules submodule.rebasing.update rebase &&