Skip to content

Instantly share code, notes, and snippets.

@garryyao
Created October 15, 2013 07:46
Show Gist options
  • Save garryyao/6987989 to your computer and use it in GitHub Desktop.
Save garryyao/6987989 to your computer and use it in GitHub Desktop.
Shell script to issue git command for each troopjs sub module in bundle repo.
#!/bin/bash
# Issue arbitary git command for each of the sub modules.
# E.g. git-bundle checkout feature/docs
# Check out the feature/docs branch for each of the sub module.
function print_header
{
printf '%.0s-' {1..30} && echo
echo $1
printf '%.0s-' {1..30} && echo
}
# Blobing pattern for directories, replace with whatever u like.
PATTERN="**/troopjs-*"
# Pass all params to git command.
COMMAND=$@
for i in $PATTERN
do
print_header $i
git --git-dir=$i/.git --work-tree=$PWD/$i $COMMAND
printf '\n\n\n'
done
exit 0;
@zjhiphop
Copy link

For windows, i just build a work around for bundle checkout "Bower" linked troopjs repos.
Save the following script in "git-bundle.cmd" and put it to "troopjs" dir.
Please use command: "git-bundle.cmd checkout feature/docs" to checkout all doc branches.

@echo off & setlocal enabledelayedexpansion

set sym=-
set PATTERN="troopjs-"
set COMMOND=%* 
set repoDIR="bower_components"
set bower_link_dir="%appdata%\bower\data\links"
set root=%CD%
set tempA=tmp_ta_.txt
set tempB=tmp_tb_.txt

if "%*"=="" ( set COMMOND=status )

for /l %%i in (1,1,50) do set line=!line!%sym%
dir %repoDIR% | find %PATTERN% | find "<SYMLINKD>" > %tempA%
dir %bower_link_dir% | find %PATTERN% > %tempB%

for /f "tokens=4,5" %%a in (%tempA%) do (  
  for /f "tokens=4,5" %%i in (%tempB%) do ( 
      if %%a==%%i (
        echo !line! 
        set str=%%j
        set str=!str:]=!
        set str=!str:[=!
        echo !str! && cd /d !str! && git %COMMOND%
        echo !line! 
        echo.
        echo.
      )  
      cd /d !root!
  )
)

del %tempA% && del %tempB%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment