英文:
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="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. "
答案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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论