迁移 TFS 仓库到 Bitbucket 使用 Shell 脚本

huangapple go评论52阅读模式
英文:

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\""

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

英文:

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=&quot;https://bitbucket.org/fm_ebiz/&quot;
migration_directory=&quot;E:\\Migration2&quot;
excel_file=&quot;C:/Scripts/Repos.csv&quot;

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

    cd &quot;$migration_directory/$repo_name&quot;
    pwd
    git remote add bitbucket &quot;$bitbucket_remote&quot;
    git pull origin master

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

    cd &quot;$migration_directory&quot;
    rm -rf &quot;$repo_name&quot;
done &lt; &quot;$excel_file&quot;`

By running above script

$ ./migration.sh
Repo_name: appsmgmt
Bitbucket_remote: https://@bitbucket.org/fm_ebiz/&lt;myrepo&gt;.git
TFS repository can not be root and must start with &quot;$/&quot;.
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/&lt;repo&gt;
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 &quot;git-tfs clone http://mytfs/tfs/ebi \&quot;$repo_path\&quot; \&quot;$migration_directory\$repo_name\&quot;&quot;



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

答案1

得分: 0

我认为问题的原因是自 git 2.5 以来 bash 存在一个“坏”行为,其中 TFVC 路径中的“$”会被展开为一个值,因此路径被损坏,而 git-tfs 不知道要克隆什么。

解决方法是在运行“git-tfs”命令之前使用 MSYS_NO_PATHCONV=1,就像这里定义的一样:https://github.com/git-tfs/git-tfs/issues/845#issuecomment-135395001

英文:

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

huangapple
  • 本文由 发表于 2023年6月29日 02:21:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76575777.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定