Skip to content

Commit

Permalink
filter-repo
Browse files Browse the repository at this point in the history
  • Loading branch information
cirosantilli committed Oct 1, 2020
1 parent 2bf83d5 commit 260a269
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
1 change: 1 addition & 0 deletions other-test-repos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ There are also some tests that could not be included here conveniently:
- <https://github.com/cirosantilli/test-empty-commit>
- <https://github.com/cirosantilli/test-empty-subdir>
- <https://github.com/cirosantilli/test-git-partial-clone>: [partial-clone.sh](partial-clone.sh) | https://stackoverflow.com/questions/600079/how-do-i-clone-a-subdirectory-only-of-a-git-repository/52269934#52269934
- <https://github.com/cirosantilli/test-git-filter-repo>: [filter-repo.sh](filter-repo.sh)
- <https://github.com/cirosantilli/test-invalid-utf8>
- <https://github.com/cirosantilli/test-large-file>
- <https://github.com/cirosantilli/test-long-filename-1024>
Expand Down
61 changes: 61 additions & 0 deletions other-test-repos/filter-repo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env bash
set -eu

# Reproducibility.
export GIT_COMMITTER_NAME='a'
export GIT_COMMITTER_EMAIL='a'
export GIT_AUTHOR_NAME='a'
export GIT_AUTHOR_EMAIL='a'
export GIT_COMMITTER_DATE='2000-01-01T00:00:00+0000'
export GIT_AUTHOR_DATE='2000-01-01T00:00:00+0000'

# https://stackoverflow.com/questions/600079/how-do-i-clone-a-subdirectory-only-of-a-git-repository/52269934#52269934
rm -rf filter-repo.tmp
mkdir -p filter-repo.tmp
cd filter-repo.tmp
git init

# Create repo.
git init --quiet

# First commit.
# Directories present in all branches.
mkdir d1 d2
printf 'd1/a' > ./d1/a
printf 'd1/b' > ./d1/b
printf 'd2/a' > ./d2/a
printf 'd2/b' > ./d2/b
# Present only in root.
mkdir 'root'
printf 'root' > ./root/root
git add .
git commit -m 'root' --quiet
root_commmit_sha="$(git log -1 --format="%H")"

# Second commit only on master.
git rm --quiet -r ./root
mkdir 'master'
printf 'master' > ./master/master
printf 'd1/a' > ./d1/a2
git add .
git commit -m 'master commit' --quiet

# Third commit only on master.
printf 'd1/b' > ./d1/b2
git add .
git commit -m 'master commit' --quiet

# Second commit only on mybranch.
git checkout -b mybranch --quiet "$root_commmit_sha"
git rm --quiet -r ./root
mkdir 'mybranch'
printf 'mybranch' > ./mybranch/mybranch
git add .
git commit -m 'mybranch commit' --quiet

# Restore master.
git checkout --quiet master

# To easily compare with the original repo.
git remote add origin https://github.com/cirosantilli/test-git-filter-repository
git fetch
4 changes: 1 addition & 3 deletions other-test-repos/partial-clone.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#!/usr/bin/env bash
set -eu

# https://stackoverflow.com/questions/600079/how-do-i-clone-a-subdirectory-only-of-a-git-repository/52269934#52269934
rm -rf partial-clone.tmp
mkdir -p partial-clone.tmp
cd partial-clone.tmp

#!/usr/bin/env bash
set -eu

list-objects() (
git rev-list --all --objects
echo "master commit SHA: $(git log -1 --format="%H")"
Expand Down

0 comments on commit 260a269

Please sign in to comment.