File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change @@ -204,6 +204,27 @@ fn write() -> crate::Result {
204
204
Ok ( ( ) )
205
205
}
206
206
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
+
207
228
#[ test]
208
229
fn contains ( ) {
209
230
let handle = db ( ) ;
You can’t perform that action at this time.
0 commit comments