|
|
@@ -3,6 +3,14 @@ |
|
|
#usage: pass to the script (1) the url of the tfs server, (2) the tfs path in the repository, (3) the changeset id |
|
|
#../replace_root.sh "https://urlOfYourTfs/DefaultCollection" "$/EmptyTfs/Trunk" 21 |
|
|
|
|
|
# Command to get Changeset ID |
|
|
# tf history "$/EmptyTfs/Trunk" /collection:"https://urlOfYourTfs/DefaultCollection" /noprompt /stopafter:1 |
|
|
|
|
|
# Clean up any previous attempt |
|
|
rm -rf ./.git/refs/replace |
|
|
git checkout master |
|
|
git branch -D new-root |
|
|
|
|
|
tfsServer=$1 |
|
|
tfsPath=$2 |
|
|
tfsChangesetId=$3 |
|
|
@@ -12,25 +20,32 @@ echo "Creating a root commit with git-tfs metadatas:" |
|
|
echo $gitTfsMetadata |
|
|
|
|
|
root_commit_sha=$(git rev-list --max-parents=0 HEAD) |
|
|
echo "root_commit_sha=" $root_commit_sha |
|
|
git checkout --force --orphan new-root |
|
|
find . -path ./.git -prune -o -exec rm -rf {} \; 2> /dev/null |
|
|
"C:\Program Files\Git\usr\bin\find.exe" . -path ./.git -prune -o -exec rm -rf {} \; 2> /dev/null |
|
|
git add -A |
|
|
GIT_COMMITTER_DATE="2000-01-01T12:00:00" git commit --date==2000-01-01T12:00:00 --allow-empty -m $gitTfsMetadata |
|
|
GIT_COMMITTER_DATE="2000-01-01T12:00:00" git commit --date==2000-01-01T12:00:00 --allow-empty -m "$gitTfsMetadata" |
|
|
new_root_commit_sha=$(git rev-parse HEAD) |
|
|
|
|
|
echo "The commit '$new_root_commit_sha' will be added before existing root commit '$root_commit_sha'..." |
|
|
|
|
|
parent="parent $new_root_commit_sha" |
|
|
replacement_commit=$( |
|
|
git cat-file commit $root_commit_sha | sed "s/author/$parent\nauthor/" | |
|
|
git hash-object -t commit -w --stdin |
|
|
git cat-file commit $root_commit_sha | sed "s/author/$parent\nauthor/" | git hash-object -t commit -w --stdin |
|
|
) || return 3 |
|
|
git replace "$root_commit_sha" "$replacement_commit" |
|
|
|
|
|
git filter-branch -- --all |
|
|
rm -rf ./.git/refs/original |
|
|
rm -rf ./.git/refs/replace |
|
|
git checkout -f master |
|
|
git branch -D new-root |
|
|
read -r -p "Apply changes? [y/N] " response |
|
|
response=${response,,} #tolower |
|
|
if [[ $response =~ ^(yes|y)$ ]] |
|
|
then |
|
|
git filter-branch -- --all |
|
|
rm -rf ./.git/refs/original |
|
|
rm -rf ./.git/refs/replace |
|
|
git checkout -f master |
|
|
git branch -D new-root |
|
|
|
|
|
git tfs bootstrap |
|
|
git tfs bootstrap |
|
|
else |
|
|
echo "Aborting! Feel free to run it again after you've verified your changes." |
|
|
fi |