Search code examples
gitshellcmdgit-bashgit-tfs

Migrating TFS repo to bitbucket using shell script


I have migrated manually by referring https://github.com/git-tfs/git-tfs from my windows server. But I have lot many repos in TFS . So I have written a shell script using same commands and trying to run from git bash in same windows machine. I am facing error due to special characters.

bitbucket_base_url="https://bitbucket.org/fm_ebiz/"
migration_directory="E:\\Migration2"
excel_file="C:/Scripts/Repos.csv"

while IFS=',' read -r repo_path || [[ -n "$repo_path" ]]; do
    repo_name=$(basename "$(dirname "$repo_path")")
    repo_name=${repo_name,,}
    echo "Repo_name: $repo_name"
    
    bitbucket_remote="$bitbucket_base_url$repo_name.git"
    echo "Bitbucket_remote: $bitbucket_remote"
  
    
    mkdir -p "$migration_directory/$repo_name"
    git-tfs clone "http://mytfs_url/tfs/ebi" "$repo_path" "$migration_directory\\$repo_name"
    echo "Repo_Path: $repo_path"

    cd "$migration_directory/$repo_name"
    pwd
    git remote add bitbucket "$bitbucket_remote"
    git pull origin master

    if [[ $repo_name == "Release" ]]; then
        git push bitbucket master:"$repo_name" --set-upstream
    else
        git push bitbucket master:"$repo_name"
        git push bitbucket "$repo_name:$repo_name" --set-upstream
    fi

    cd "$migration_directory"
    rm -rf "$repo_name"
done < "$excel_file"`

By running above script

$ ./migration.sh
Repo_name: appsmgmt
Bitbucket_remote: https://@bitbucket.org/fm_ebiz/<myrepo>.git
TFS repository can not be root and must start with "$/".
You may be able to resolve this problem.
- Try using $/C:/Program Files/Git/TFS_repo path/repo/branch_name
All the logs could be found in the log file: C:\Users\myuser\AppData\Local\git-tfs\git-tfs_log.txt
Repo_Path: $/My TFS repo path/Its printing correctly/
/e/Migration2/<repo>
fatal: not a git repository (or any of the parent directories): .git
fatal: not a git repository (or any of the parent directories): .git
fatal: not a git repository (or any of the parent directories): .git
fatal: not a git repository (or any of the parent directories): .git
Repo_name: myrepo
Bitbucket_remote: https://bitbucket.org/fm_ebiz/myrepo.git

so I have changed git-tfs clone to cmd to make it run as a window command ,like



cmd.exe /C "git-tfs clone http://mytfs/tfs/ebi \"$repo_path\" \"$migration_directory\\$repo_name\""



Its throwing error " '$' is not recognized as an internal or external command, operable program or batch file. "


Solution

  • I think the reason is a 'bad' behavior of bash (since git 2.5) where the '$' of the TFVC path is expanded to a value and so the path is corrupted and git-tfs don't know what to clone.

    The workaround is to use MSYS_NO_PATHCONV=1 just before the "git-tfs" command run like defined here: https://github.com/git-tfs/git-tfs/issues/845#issuecomment-135395001