Skip to content

Commit 6cb5728

Browse files
cpackhamgitster
authored andcommitted
submodule update: allow custom command to update submodule working tree
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d9857bf commit 6cb5728

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

Documentation/git-submodule.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ update::
159159
This will make the submodules HEAD be detached unless `--rebase` or
160160
`--merge` is specified or the key `submodule.$name.update` is set to
161161
`rebase`, `merge` or `none`. `none` can be overridden by specifying
162-
`--checkout`.
162+
`--checkout`. Setting the key `submodule.$name.update` to `!command`
163+
will cause `command` to be run. `command` can be any arbitrary shell
164+
command that takes a single argument, namely the sha1 to update to.
163165
+
164166
If the submodule is not yet initialized, and you just want to use the
165167
setting as stored in .gitmodules, you can automatically initialize the

git-submodule.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,12 @@ Maybe you want to use 'update --init'?")"
860860
say_msg="$(eval_gettext "Submodule path '\$displaypath': merged in '\$sha1'")"
861861
must_die_on_failure=yes
862862
;;
863+
!*)
864+
command="${update_module#!}"
865+
die_msg="$(eval_gettext "Execution of '\$command \$sha1' failed in submodule path '\$prefix\$sm_path'")"
866+
say_msg="$(eval_gettext "Submodule path '\$prefix\$sm_path': '\$command \$sha1'")"
867+
must_die_on_failure=yes
868+
;;
863869
*)
864870
command="git checkout $subforce -q"
865871
die_msg="$(eval_gettext "Unable to checkout '\$sha1' in submodule path '\$displaypath'")"

t/t7406-submodule-update.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,35 @@ test_expect_success 'submodule update - checkout in .git/config' '
294294
)
295295
'
296296

297+
test_expect_success 'submodule update - command in .git/config' '
298+
(cd super &&
299+
git config submodule.submodule.update "!git checkout"
300+
) &&
301+
(cd super/submodule &&
302+
git reset --hard HEAD^
303+
) &&
304+
(cd super &&
305+
(cd submodule &&
306+
compare_head
307+
) &&
308+
git submodule update submodule &&
309+
cd submodule &&
310+
! compare_head
311+
)
312+
'
313+
314+
test_expect_success 'submodule update - command in .git/config catches failure' '
315+
(cd super &&
316+
git config submodule.submodule.update "!false"
317+
) &&
318+
(cd super/submodule &&
319+
git reset --hard HEAD^
320+
) &&
321+
(cd super &&
322+
test_must_fail git submodule update submodule
323+
)
324+
'
325+
297326
test_expect_success 'submodule init picks up rebase' '
298327
(cd super &&
299328
git config -f .gitmodules submodule.rebasing.update rebase &&

0 commit comments

Comments
 (0)