2018-11-05 15:30:50 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
test_description='Basic filter-repo tests'
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
export PATH=$(dirname $TEST_DIRECTORY):$PATH # Put git-filter-repo in PATH
|
|
|
|
|
|
|
|
DATA="$TEST_DIRECTORY/t9390"
|
|
|
|
|
|
|
|
filter_testcase() {
|
|
|
|
INPUT=$1
|
|
|
|
OUTPUT=$2
|
|
|
|
shift 2
|
|
|
|
REST=("$@")
|
|
|
|
|
|
|
|
|
|
|
|
NAME="check: $INPUT -> $OUTPUT using '${REST[@]}'"
|
|
|
|
test_expect_success "$NAME" '
|
|
|
|
# Clean up from previous run
|
|
|
|
git pack-refs --all &&
|
|
|
|
rm .git/packed-refs &&
|
|
|
|
|
|
|
|
# Run the example
|
2019-02-19 02:24:33 +01:00
|
|
|
cat $DATA/$INPUT | git filter-repo --stdin --quiet --force "${REST[@]}" &&
|
2018-11-05 15:30:50 +01:00
|
|
|
|
|
|
|
# Compare the resulting repo to expected value
|
|
|
|
git fast-export --use-done-feature --all >compare &&
|
|
|
|
test_cmp $DATA/$OUTPUT compare
|
|
|
|
'
|
|
|
|
}
|
|
|
|
|
|
|
|
filter_testcase basic basic-filename --path filename
|
|
|
|
filter_testcase basic basic-twenty --path twenty
|
|
|
|
filter_testcase basic basic-ten --path ten
|
2019-02-19 02:24:33 +01:00
|
|
|
filter_testcase basic basic-numbers --path ten --path twenty
|
|
|
|
filter_testcase basic basic-filename --invert-paths --path-glob 't*en*'
|
|
|
|
filter_testcase basic basic-numbers --invert-paths --path-regex 'f.*e.*e'
|
2019-01-29 02:26:49 +01:00
|
|
|
filter_testcase basic basic-mailmap --mailmap ../t9390/sample-mailmap
|
filter-repo: add text removal (or replacement) via file of expressions
Make it easy for users to search and replace text throughout the
repository history. Instead of inventing some new syntax, reuse the
same syntax used by BFG repo filter's --replace-text option, namely,
a file with one expression per line of the form
[regex:|glob:|literal:]$MATCH_EXPR[==>$REPLACEMENT_EXPR]
Where "$MATCH_EXPR" is by default considered to be literal text, but
could be a regex or a glob if the appropriate prefix is used. Also,
$REPLACEMENT_EXPR defaults to '***REMOVED***' if not specified. If
you want a literal '==>' to be part of your $MATCH_EXPR, then you
must also manually specify a replacement expression instead of taking
the default. Some examples:
sup3rs3kr3t
(replaces 'sup3rs3kr3t' with '***REMOVED***')
HeWhoShallNotBeNamed==>Voldemort
(replaces 'HeWhoShallNotBeNamed' with 'Voldemort')
very==>
(replaces 'very' with the empty string)
regex:(\d{2})/(\d{2})/(\d{4})==>\2/\1/\3
(replaces '05/17/2012' with '17/05/2012', and vice-versa)
The format for regex is as from
re.sub(<pattern>, <repl>, <string>) from
https://docs.python.org/2/library/re.html
The <string> comes from file contents of the repo, and you specify
the <pattern> and <repl>.
glob:Copy*t==>Cartel
(replaces 'Copyright' or 'Copyleft' or 'Copy my st' with 'Cartel')
Signed-off-by: Elijah Newren <newren@gmail.com>
2019-01-30 09:56:22 +01:00
|
|
|
filter_testcase basic basic-replace --replace-text ../t9390/sample-replace
|
2019-03-04 23:29:54 +01:00
|
|
|
filter_testcase empty empty-keepme --path keepme
|
2019-02-23 17:15:07 +01:00
|
|
|
filter_testcase degenerate degenerate-keepme --path moduleA/keepme
|
|
|
|
filter_testcase degenerate degenerate-moduleA --path moduleA
|
|
|
|
filter_testcase degenerate degenerate-globme --path-glob *me
|
2018-11-05 15:30:50 +01:00
|
|
|
|
2019-03-07 19:49:39 +01:00
|
|
|
test_expect_success 'setup path_rename' '
|
|
|
|
test_create_repo path_rename &&
|
|
|
|
(
|
|
|
|
cd path_rename &&
|
|
|
|
mkdir sequences values &&
|
|
|
|
test_seq 1 10 >sequences/tiny &&
|
|
|
|
test_seq 100 110 >sequences/intermediate &&
|
|
|
|
test_seq 1000 1010 >sequences/large &&
|
|
|
|
test_seq 1000 1010 >values/large &&
|
|
|
|
test_seq 10000 10010 >values/huge &&
|
|
|
|
git add sequences values &&
|
|
|
|
git commit -m initial &&
|
|
|
|
|
|
|
|
git mv sequences/tiny sequences/small &&
|
|
|
|
cp sequences/intermediate sequences/medium &&
|
|
|
|
echo 10011 >values/huge &&
|
|
|
|
git add sequences values &&
|
|
|
|
git commit -m updates &&
|
|
|
|
|
|
|
|
git rm sequences/intermediate &&
|
|
|
|
echo 11 >sequences/small &&
|
|
|
|
git add sequences/small &&
|
|
|
|
git commit -m changes &&
|
|
|
|
|
|
|
|
echo 1011 >sequences/medium &&
|
|
|
|
git add sequences/medium &&
|
|
|
|
git commit -m final
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '--path-rename sequences/tiny:sequences/small' '
|
|
|
|
(
|
|
|
|
git clone file://"$(pwd)"/path_rename path_rename_single &&
|
|
|
|
cd path_rename_single &&
|
|
|
|
git filter-repo --path-rename sequences/tiny:sequences/small &&
|
|
|
|
git log --format=%n --name-only | sort | uniq >filenames &&
|
|
|
|
test_line_count = 7 filenames &&
|
|
|
|
! grep sequences/tiny filenames &&
|
|
|
|
git rev-parse HEAD~3:sequences/small
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '--path-rename sequences:numbers' '
|
|
|
|
(
|
|
|
|
git clone file://"$(pwd)"/path_rename path_rename_dir &&
|
|
|
|
cd path_rename_dir &&
|
|
|
|
git filter-repo --path-rename sequences:numbers &&
|
|
|
|
git log --format=%n --name-only | sort | uniq >filenames &&
|
|
|
|
test_line_count = 8 filenames &&
|
|
|
|
! grep sequences/ filenames &&
|
|
|
|
grep numbers/ filenames &&
|
|
|
|
grep values/ filenames
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '--path-rename-prefix values:numbers' '
|
|
|
|
(
|
|
|
|
git clone file://"$(pwd)"/path_rename path_rename_dir_2 &&
|
|
|
|
cd path_rename_dir_2 &&
|
|
|
|
git filter-repo --path-rename values/:numbers/ &&
|
|
|
|
git log --format=%n --name-only | sort | uniq >filenames &&
|
|
|
|
test_line_count = 8 filenames &&
|
|
|
|
! grep values/ filenames &&
|
|
|
|
grep sequences/ filenames &&
|
|
|
|
grep numbers/ filenames
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '--path-rename squashing' '
|
|
|
|
(
|
|
|
|
git clone file://"$(pwd)"/path_rename path_rename_squash &&
|
|
|
|
cd path_rename_squash &&
|
|
|
|
git filter-repo \
|
|
|
|
--path-rename sequences/tiny:sequences/small \
|
|
|
|
--path-rename sequences:numbers \
|
|
|
|
--path-rename values:numbers \
|
|
|
|
--path-rename numbers/intermediate:numbers/medium &&
|
|
|
|
git log --format=%n --name-only | sort | uniq >filenames &&
|
|
|
|
# Just small, medium, large, huge, and a blank line...
|
|
|
|
test_line_count = 5 filenames &&
|
|
|
|
! grep sequences/ filenames &&
|
|
|
|
! grep values/ filenames &&
|
|
|
|
grep numbers/ filenames
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '--path-rename inability to squash' '
|
|
|
|
(
|
|
|
|
git clone file://"$(pwd)"/path_rename path_rename_bad_squash &&
|
|
|
|
cd path_rename_bad_squash &&
|
|
|
|
test_must_fail git filter-repo \
|
|
|
|
--path-rename values/large:values/big \
|
|
|
|
--path-rename values/huge:values/big 2>../err &&
|
|
|
|
test_i18ngrep "File renaming caused colliding pathnames" ../err
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2019-03-08 01:14:35 +01:00
|
|
|
test_expect_success 'setup tag_rename' '
|
|
|
|
test_create_repo tag_rename &&
|
|
|
|
(
|
|
|
|
cd tag_rename &&
|
|
|
|
mkdir numbers &&
|
|
|
|
test_seq 1 10 >numbers/small &&
|
|
|
|
test_seq 100 110 >numbers/medium &&
|
|
|
|
git add numbers &&
|
|
|
|
git commit -m initial &&
|
|
|
|
git tag v1.0 &&
|
|
|
|
|
|
|
|
mkdir words &&
|
|
|
|
echo foo >words/important &&
|
|
|
|
echo bar >words/whimsical &&
|
|
|
|
echo baz >words/sequences &&
|
|
|
|
git add words &&
|
|
|
|
git commit -m some.words &&
|
|
|
|
git branch another_branch &&
|
|
|
|
git tag v2.0 &&
|
|
|
|
|
|
|
|
echo spam >words/to &&
|
|
|
|
echo spam >words/know &&
|
|
|
|
git add words
|
|
|
|
git commit -m more.words &&
|
|
|
|
git tag -a -m "Look, ma, I made a tag" v3.0
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'check --tag-rename' '
|
|
|
|
(
|
|
|
|
git clone file://"$(pwd)"/tag_rename tag_rename_actual &&
|
|
|
|
cd tag_rename_actual &&
|
|
|
|
git filter-repo \
|
|
|
|
--tag-rename "":"myrepo-" \
|
|
|
|
--path words &&
|
|
|
|
test_must_fail git cat-file -t v1.0 &&
|
|
|
|
test_must_fail git cat-file -t v2.0 &&
|
|
|
|
test_must_fail git cat-file -t v3.0 &&
|
|
|
|
test_must_fail git cat-file -t myrepo-v1.0 &&
|
|
|
|
test $(git cat-file -t myrepo-v2.0) = commit &&
|
|
|
|
test $(git cat-file -t myrepo-v3.0) = tag
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2018-11-05 15:30:50 +01:00
|
|
|
test_done
|