Bash: Git субмодуль foreach? - PullRequest
       9

Bash: Git субмодуль foreach?

9 голосов
/ 03 декабря 2011

У меня sup есть псевдоним submodule foreach 'git co master; git up' (co & up - псевдонимы checkout и pull --rebase соответственно.).

Как добавить условие, чтобы, еслиимя подмодуля Libraries/JSONKit, оно проверяет ветвь с именем experimental вместо master?

Ответы [ 2 ]

14 голосов
/ 03 декабря 2011

Сценарий passwd для git submodule запускается с рабочим каталогом, установленным в верхнюю часть данного подмодуля ... так что вы можете просто посмотреть на pwd, чтобы убедиться, что вы находитесь в конкретном подмодуле,Однако, если вы потратите некоторое время на чтение документации git submodule, это окажется еще проще:

foreach
    Evaluates an arbitrary shell command in each checked out submodule. The 
    command has access to the variables $name, $path, $sha1
    and $toplevel: $name is the name of the relevant submodule section in 
    .gitmodules, $path is the name of the submodule directory
    relative to the superproject, $sha1 is the commit as recorded in the superproject, 
    and $toplevel is the absolute path to the top-level of the superproject.

Так что вы можете сделать что-то вроде этого:

git submodule foreach '[ "$path" = "Libraries/JSONKit" ] \
  && branch=experimental \
  || branch=master; git co $branch'
0 голосов
/ 03 декабря 2011

Добавьте следующее к .git/config:

[alias]
    sup = "submodule foreach 'if [ $name == \"Libraries/JSONKit\" ]; then git co experimental; else git co master; fi; git up'"
...