Skip to content

Instantly share code, notes, and snippets.

@azilber
Last active July 8, 2020 04:24
Show Gist options
  • Select an option

  • Save azilber/a9d744e3e3ff01d6f99c167b191a552c to your computer and use it in GitHub Desktop.

Select an option

Save azilber/a9d744e3e3ff01d6f99c167b191a552c to your computer and use it in GitHub Desktop.

Revisions

  1. azilber revised this gist Jul 8, 2020. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions migrate-repos.sh
    Original file line number Diff line number Diff line change
    @@ -29,7 +29,8 @@ for g in $DIR; do
    if [ $? -gt 0 ]; then
    echo "Skipping $g. It's empty!"
    else
    git config credential.help "!aws codecommit credential-helper --profile $PROFILE \$\@"
    git config credential.helper "!aws codecommit credential-helper --profile $PROFILE \$@"
    git config credential.UseHttpPath true
    URL=`aws codecommit create-repository --repository-name "$D-$g" --tags Terraform=false --repository-description "$DESC" --profile $PROFILE |jq -r '.[].cloneUrlHttp'`
    echo "Adding remote to $g"
    git remote add aws $URL
    @@ -41,4 +42,4 @@ for g in $DIR; do
    echo "Cleaned up"
    done

    echo "Completed $DIR"
    echo "Completed: $DIR"
  2. azilber created this gist Jul 8, 2020.
    44 changes: 44 additions & 0 deletions migrate-repos.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    #!/bin/bash

    P=/home/git/repositories

    ls -altrh $P/

    echo -n "Directory to migrate: "
    read D


    echo -n "Profile to migrate to: "
    read PROFILE

    workdir=/tmp

    DIR=$(ls $P/$D | sed 's/.git//g')

    for g in $DIR; do

    cd $workdir
    echo "Doing $D-$g"
    git clone file://$P/$D/$g.git
    echo "Cloned"
    DESC=`ls -altrh $P/$D/$g.git/ |tail -1 |cut -d\ -f6-20`
    echo "DESC: $DESC"
    echo "Clone url: $URL"
    cd $g
    git log -n 1
    if [ $? -gt 0 ]; then
    echo "Skipping $g. It's empty!"
    else
    git config credential.help "!aws codecommit credential-helper --profile $PROFILE \$\@"
    URL=`aws codecommit create-repository --repository-name "$D-$g" --tags Terraform=false --repository-description "$DESC" --profile $PROFILE |jq -r '.[].cloneUrlHttp'`
    echo "Adding remote to $g"
    git remote add aws $URL
    git push aws master
    fi

    cd $workdir
    rm -Rf $g
    echo "Cleaned up"
    done

    echo "Completed $DIR"