Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@zjhiphop zjhiphop commented Oct 15, 2013

If you're using msysGit which has problem to understand the symbolic link so use this version instead:

#!/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.

# Symlink issue in windows
# http://git.661346.n2.nabble.com/git-clone-doesn-t-work-in-symlink-dir-roots-on-Windows-td7593620.html

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=$@
ROOT=$PWD

for i in $PATTERN
do
    print_header $i && cd $ROOT/$i && git $COMMAND && printf '\n\n\n'
done
exit 0;
@zjhiphop

This comment has been minimized.

Copy link

@zjhiphop zjhiphop commented Oct 17, 2013

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
You can’t perform that action at this time.