Skip to content

Commit 6cb9ecc

Browse files
committed
Initial test to assure we don't replace objects by default (#364)
It will be followed up by supporting it on various levels, which is more complex than it sounds.
1 parent 30b22a8 commit 6cb9ecc

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
set -eu -o pipefail
3+
4+
git init -q
5+
git config commit.gpgsign false
6+
7+
echo "#include <stdio.h>" > file.c && git add file.c
8+
git commit -m "Initial commit"
9+
echo "// 2nd line" >> file.c && git commit -am "2nd commit"
10+
echo "// 3rd line" >> file.c && git commit -am "3rd commit"
11+
echo "// 4th line" >> file.c && git commit -am "4th commit"
12+
git branch long_history HEAD^ # Create branch off of 3rd commit
13+
new_base=$(echo 'Short history stops here' | git commit-tree 'HEAD~2^{tree}')
14+
git rebase --onto $new_base HEAD~2
15+
git replace HEAD~1 long_history # Here's the git-replace

git-odb/tests/odb/store/dynamic.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,27 @@ fn write() -> crate::Result {
204204
Ok(())
205205
}
206206

207+
#[test]
208+
fn object_replacement() {
209+
let dir = git_testtools::scripted_fixture_repo_read_only("make_replaced_history.sh").unwrap();
210+
let handle = git_odb::at(dir.join(".git/objects")).unwrap();
211+
let mut buf = Vec::new();
212+
let third_commit = handle
213+
.find_commit(hex_to_id("434e5a872d6738d1fffd1e11e52a1840b73668c6"), &mut buf)
214+
.unwrap();
215+
216+
let orphan_of_new_history = hex_to_id("0703c317e28068f39834ae61e7ab941b7d672322");
217+
assert_eq!(
218+
third_commit.parents().collect::<Vec<_>>(),
219+
vec![orphan_of_new_history],
220+
"no replacements are known by default, hence this is the replaced commit, not the replacement"
221+
);
222+
223+
drop(third_commit);
224+
let orphan = handle.find_commit(orphan_of_new_history, &mut buf).unwrap();
225+
assert_eq!(orphan.parents.len(), 0);
226+
}
227+
207228
#[test]
208229
fn contains() {
209230
let handle = db();

0 commit comments

Comments
 (0)