reflog expire --fix-stale
The logic in an earlier round to detect reflog entries that
point at a broken commit was not sufficient. Just like we do
not trust presense of a commit during pack transfer (we trust
only our refs), we should not trust a commit's presense, even if
the tree of that commit is complete.
A repository that had reflog enabled on some of the refs that
was rewound and then run git-repack or git-prune from older
versions of git can have reflog entries that point at a commit
that still exist but lack commits (or trees and blobs needed for
that commit) between it and some commit that is reachable from
one of the refs.
This revamps the logic -- the definition of "broken commit"
becomes: a commit that is not reachable from any of the refs and
there is a missing object among the commit, tree, or blob
objects reachable from it that is not reachable from any of the
refs. Entries in the reflog that refer to such a commit are
expired.
Since this computation involves traversing all the reachable
objects, i.e. it has the same cost as 'git prune', it is enabled
only when a new option --fix-stale. Fortunately, once this is
run, we should not have to ever worry about missing objects,
because the current prune and pack-objects know about reflogs
and protect objects referred by them.
Unfortunately, this will be absolutely necessary to help people
migrate to the newer prune and repack.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-01-06 11:16:19 +01:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2007 Junio C Hamano
|
|
|
|
#
|
|
|
|
|
|
|
|
test_description='Test prune and reflog expiration'
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
check_have () {
|
|
|
|
gaah= &&
|
|
|
|
for N in "$@"
|
|
|
|
do
|
|
|
|
eval "o=\$$N" && git cat-file -t $o || {
|
|
|
|
echo Gaah $N
|
|
|
|
gaah=$N
|
|
|
|
break
|
|
|
|
}
|
|
|
|
done &&
|
|
|
|
test -z "$gaah"
|
|
|
|
}
|
|
|
|
|
|
|
|
check_fsck () {
|
2007-01-29 01:33:58 +01:00
|
|
|
output=$(git fsck --full)
|
reflog expire --fix-stale
The logic in an earlier round to detect reflog entries that
point at a broken commit was not sufficient. Just like we do
not trust presense of a commit during pack transfer (we trust
only our refs), we should not trust a commit's presense, even if
the tree of that commit is complete.
A repository that had reflog enabled on some of the refs that
was rewound and then run git-repack or git-prune from older
versions of git can have reflog entries that point at a commit
that still exist but lack commits (or trees and blobs needed for
that commit) between it and some commit that is reachable from
one of the refs.
This revamps the logic -- the definition of "broken commit"
becomes: a commit that is not reachable from any of the refs and
there is a missing object among the commit, tree, or blob
objects reachable from it that is not reachable from any of the
refs. Entries in the reflog that refer to such a commit are
expired.
Since this computation involves traversing all the reachable
objects, i.e. it has the same cost as 'git prune', it is enabled
only when a new option --fix-stale. Fortunately, once this is
run, we should not have to ever worry about missing objects,
because the current prune and pack-objects know about reflogs
and protect objects referred by them.
Unfortunately, this will be absolutely necessary to help people
migrate to the newer prune and repack.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-01-06 11:16:19 +01:00
|
|
|
case "$1" in
|
|
|
|
'')
|
|
|
|
test -z "$output" ;;
|
|
|
|
*)
|
|
|
|
echo "$output" | grep "$1" ;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
corrupt () {
|
|
|
|
aa=${1%??????????????????????????????????????} zz=${1#??}
|
|
|
|
mv .git/objects/$aa/$zz .git/$aa$zz
|
|
|
|
}
|
|
|
|
|
|
|
|
recover () {
|
|
|
|
aa=${1%??????????????????????????????????????} zz=${1#??}
|
|
|
|
mkdir -p .git/objects/$aa
|
|
|
|
mv .git/$aa$zz .git/objects/$aa/$zz
|
|
|
|
}
|
|
|
|
|
|
|
|
check_dont_have () {
|
|
|
|
gaah= &&
|
|
|
|
for N in "$@"
|
|
|
|
do
|
|
|
|
eval "o=\$$N"
|
|
|
|
git cat-file -t $o && {
|
|
|
|
echo Gaah $N
|
|
|
|
gaah=$N
|
|
|
|
break
|
|
|
|
}
|
|
|
|
done
|
|
|
|
test -z "$gaah"
|
|
|
|
}
|
|
|
|
|
|
|
|
test_expect_success setup '
|
|
|
|
mkdir -p A/B &&
|
|
|
|
echo rat >C &&
|
|
|
|
echo ox >A/D &&
|
|
|
|
echo tiger >A/B/E &&
|
|
|
|
git add . &&
|
|
|
|
|
|
|
|
test_tick && git commit -m rabbit &&
|
|
|
|
H=`git rev-parse --verify HEAD` &&
|
|
|
|
A=`git rev-parse --verify HEAD:A` &&
|
|
|
|
B=`git rev-parse --verify HEAD:A/B` &&
|
|
|
|
C=`git rev-parse --verify HEAD:C` &&
|
|
|
|
D=`git rev-parse --verify HEAD:A/D` &&
|
|
|
|
E=`git rev-parse --verify HEAD:A/B/E` &&
|
|
|
|
check_fsck &&
|
|
|
|
|
2009-02-28 21:12:57 +01:00
|
|
|
test_chmod +x C &&
|
reflog expire --fix-stale
The logic in an earlier round to detect reflog entries that
point at a broken commit was not sufficient. Just like we do
not trust presense of a commit during pack transfer (we trust
only our refs), we should not trust a commit's presense, even if
the tree of that commit is complete.
A repository that had reflog enabled on some of the refs that
was rewound and then run git-repack or git-prune from older
versions of git can have reflog entries that point at a commit
that still exist but lack commits (or trees and blobs needed for
that commit) between it and some commit that is reachable from
one of the refs.
This revamps the logic -- the definition of "broken commit"
becomes: a commit that is not reachable from any of the refs and
there is a missing object among the commit, tree, or blob
objects reachable from it that is not reachable from any of the
refs. Entries in the reflog that refer to such a commit are
expired.
Since this computation involves traversing all the reachable
objects, i.e. it has the same cost as 'git prune', it is enabled
only when a new option --fix-stale. Fortunately, once this is
run, we should not have to ever worry about missing objects,
because the current prune and pack-objects know about reflogs
and protect objects referred by them.
Unfortunately, this will be absolutely necessary to help people
migrate to the newer prune and repack.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-01-06 11:16:19 +01:00
|
|
|
git add C &&
|
|
|
|
test_tick && git commit -m dragon &&
|
|
|
|
L=`git rev-parse --verify HEAD` &&
|
|
|
|
check_fsck &&
|
|
|
|
|
|
|
|
rm -f C A/B/E &&
|
|
|
|
echo snake >F &&
|
|
|
|
echo horse >A/G &&
|
|
|
|
git add F A/G &&
|
|
|
|
test_tick && git commit -a -m sheep &&
|
|
|
|
F=`git rev-parse --verify HEAD:F` &&
|
|
|
|
G=`git rev-parse --verify HEAD:A/G` &&
|
|
|
|
I=`git rev-parse --verify HEAD:A` &&
|
|
|
|
J=`git rev-parse --verify HEAD` &&
|
|
|
|
check_fsck &&
|
|
|
|
|
|
|
|
rm -f A/G &&
|
|
|
|
test_tick && git commit -a -m monkey &&
|
|
|
|
K=`git rev-parse --verify HEAD` &&
|
|
|
|
check_fsck &&
|
|
|
|
|
|
|
|
check_have A B C D E F G H I J K L &&
|
|
|
|
|
2007-01-22 06:29:44 +01:00
|
|
|
git prune &&
|
reflog expire --fix-stale
The logic in an earlier round to detect reflog entries that
point at a broken commit was not sufficient. Just like we do
not trust presense of a commit during pack transfer (we trust
only our refs), we should not trust a commit's presense, even if
the tree of that commit is complete.
A repository that had reflog enabled on some of the refs that
was rewound and then run git-repack or git-prune from older
versions of git can have reflog entries that point at a commit
that still exist but lack commits (or trees and blobs needed for
that commit) between it and some commit that is reachable from
one of the refs.
This revamps the logic -- the definition of "broken commit"
becomes: a commit that is not reachable from any of the refs and
there is a missing object among the commit, tree, or blob
objects reachable from it that is not reachable from any of the
refs. Entries in the reflog that refer to such a commit are
expired.
Since this computation involves traversing all the reachable
objects, i.e. it has the same cost as 'git prune', it is enabled
only when a new option --fix-stale. Fortunately, once this is
run, we should not have to ever worry about missing objects,
because the current prune and pack-objects know about reflogs
and protect objects referred by them.
Unfortunately, this will be absolutely necessary to help people
migrate to the newer prune and repack.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-01-06 11:16:19 +01:00
|
|
|
|
|
|
|
check_have A B C D E F G H I J K L &&
|
|
|
|
|
|
|
|
check_fsck &&
|
|
|
|
|
|
|
|
loglen=$(wc -l <.git/logs/refs/heads/master) &&
|
|
|
|
test $loglen = 4
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success rewind '
|
|
|
|
test_tick && git reset --hard HEAD~2 &&
|
|
|
|
test -f C &&
|
|
|
|
test -f A/B/E &&
|
|
|
|
! test -f F &&
|
|
|
|
! test -f A/G &&
|
|
|
|
|
|
|
|
check_have A B C D E F G H I J K L &&
|
|
|
|
|
2007-01-22 06:29:44 +01:00
|
|
|
git prune &&
|
reflog expire --fix-stale
The logic in an earlier round to detect reflog entries that
point at a broken commit was not sufficient. Just like we do
not trust presense of a commit during pack transfer (we trust
only our refs), we should not trust a commit's presense, even if
the tree of that commit is complete.
A repository that had reflog enabled on some of the refs that
was rewound and then run git-repack or git-prune from older
versions of git can have reflog entries that point at a commit
that still exist but lack commits (or trees and blobs needed for
that commit) between it and some commit that is reachable from
one of the refs.
This revamps the logic -- the definition of "broken commit"
becomes: a commit that is not reachable from any of the refs and
there is a missing object among the commit, tree, or blob
objects reachable from it that is not reachable from any of the
refs. Entries in the reflog that refer to such a commit are
expired.
Since this computation involves traversing all the reachable
objects, i.e. it has the same cost as 'git prune', it is enabled
only when a new option --fix-stale. Fortunately, once this is
run, we should not have to ever worry about missing objects,
because the current prune and pack-objects know about reflogs
and protect objects referred by them.
Unfortunately, this will be absolutely necessary to help people
migrate to the newer prune and repack.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-01-06 11:16:19 +01:00
|
|
|
|
|
|
|
check_have A B C D E F G H I J K L &&
|
|
|
|
|
|
|
|
loglen=$(wc -l <.git/logs/refs/heads/master) &&
|
|
|
|
test $loglen = 5
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'corrupt and check' '
|
|
|
|
|
|
|
|
corrupt $F &&
|
|
|
|
check_fsck "missing blob $F"
|
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'reflog expire --dry-run should not touch reflog' '
|
|
|
|
|
|
|
|
git reflog expire --dry-run \
|
|
|
|
--expire=$(($test_tick - 10000)) \
|
|
|
|
--expire-unreachable=$(($test_tick - 10000)) \
|
|
|
|
--stale-fix \
|
|
|
|
--all &&
|
|
|
|
|
|
|
|
loglen=$(wc -l <.git/logs/refs/heads/master) &&
|
|
|
|
test $loglen = 5 &&
|
|
|
|
|
|
|
|
check_fsck "missing blob $F"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'reflog expire' '
|
|
|
|
|
|
|
|
git reflog expire --verbose \
|
|
|
|
--expire=$(($test_tick - 10000)) \
|
|
|
|
--expire-unreachable=$(($test_tick - 10000)) \
|
|
|
|
--stale-fix \
|
|
|
|
--all &&
|
|
|
|
|
|
|
|
loglen=$(wc -l <.git/logs/refs/heads/master) &&
|
|
|
|
test $loglen = 2 &&
|
|
|
|
|
|
|
|
check_fsck "dangling commit $K"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prune and fsck' '
|
|
|
|
|
2007-01-22 06:29:44 +01:00
|
|
|
git prune &&
|
reflog expire --fix-stale
The logic in an earlier round to detect reflog entries that
point at a broken commit was not sufficient. Just like we do
not trust presense of a commit during pack transfer (we trust
only our refs), we should not trust a commit's presense, even if
the tree of that commit is complete.
A repository that had reflog enabled on some of the refs that
was rewound and then run git-repack or git-prune from older
versions of git can have reflog entries that point at a commit
that still exist but lack commits (or trees and blobs needed for
that commit) between it and some commit that is reachable from
one of the refs.
This revamps the logic -- the definition of "broken commit"
becomes: a commit that is not reachable from any of the refs and
there is a missing object among the commit, tree, or blob
objects reachable from it that is not reachable from any of the
refs. Entries in the reflog that refer to such a commit are
expired.
Since this computation involves traversing all the reachable
objects, i.e. it has the same cost as 'git prune', it is enabled
only when a new option --fix-stale. Fortunately, once this is
run, we should not have to ever worry about missing objects,
because the current prune and pack-objects know about reflogs
and protect objects referred by them.
Unfortunately, this will be absolutely necessary to help people
migrate to the newer prune and repack.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-01-06 11:16:19 +01:00
|
|
|
check_fsck &&
|
|
|
|
|
|
|
|
check_have A B C D E H L &&
|
|
|
|
check_dont_have F G I J K
|
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'recover and check' '
|
|
|
|
|
|
|
|
recover $F &&
|
|
|
|
check_fsck "dangling blob $F"
|
|
|
|
|
|
|
|
'
|
|
|
|
|
2008-08-11 08:21:25 +02:00
|
|
|
test_expect_success 'delete' '
|
2007-10-17 03:50:45 +02:00
|
|
|
echo 1 > C &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m rat C &&
|
|
|
|
|
|
|
|
echo 2 > C &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m ox C &&
|
|
|
|
|
|
|
|
echo 3 > C &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m tiger C &&
|
|
|
|
|
2008-08-10 01:33:29 +02:00
|
|
|
HEAD_entry_count=$(git reflog | wc -l)
|
|
|
|
master_entry_count=$(git reflog show master | wc -l)
|
|
|
|
|
|
|
|
test $HEAD_entry_count = 5 &&
|
|
|
|
test $master_entry_count = 5 &&
|
|
|
|
|
2007-10-17 03:50:45 +02:00
|
|
|
|
|
|
|
git reflog delete master@{1} &&
|
|
|
|
git reflog show master > output &&
|
2008-08-10 01:33:29 +02:00
|
|
|
test $(($master_entry_count - 1)) = $(wc -l < output) &&
|
|
|
|
test $HEAD_entry_count = $(git reflog | wc -l) &&
|
2007-10-17 03:50:45 +02:00
|
|
|
! grep ox < output &&
|
|
|
|
|
2008-08-10 01:33:29 +02:00
|
|
|
master_entry_count=$(wc -l < output)
|
|
|
|
|
|
|
|
git reflog delete HEAD@{1} &&
|
|
|
|
test $(($HEAD_entry_count -1)) = $(git reflog | wc -l) &&
|
|
|
|
test $master_entry_count = $(git reflog show master | wc -l) &&
|
|
|
|
|
|
|
|
HEAD_entry_count=$(git reflog | wc -l)
|
|
|
|
|
2007-10-17 03:50:45 +02:00
|
|
|
git reflog delete master@{07.04.2005.15:15:00.-0700} &&
|
|
|
|
git reflog show master > output &&
|
2008-08-10 01:33:29 +02:00
|
|
|
test $(($master_entry_count - 1)) = $(wc -l < output) &&
|
2007-10-17 03:50:45 +02:00
|
|
|
! grep dragon < output
|
2008-02-23 07:54:37 +01:00
|
|
|
|
|
|
|
'
|
|
|
|
|
reflog expire --fix-stale
The logic in an earlier round to detect reflog entries that
point at a broken commit was not sufficient. Just like we do
not trust presense of a commit during pack transfer (we trust
only our refs), we should not trust a commit's presense, even if
the tree of that commit is complete.
A repository that had reflog enabled on some of the refs that
was rewound and then run git-repack or git-prune from older
versions of git can have reflog entries that point at a commit
that still exist but lack commits (or trees and blobs needed for
that commit) between it and some commit that is reachable from
one of the refs.
This revamps the logic -- the definition of "broken commit"
becomes: a commit that is not reachable from any of the refs and
there is a missing object among the commit, tree, or blob
objects reachable from it that is not reachable from any of the
refs. Entries in the reflog that refer to such a commit are
expired.
Since this computation involves traversing all the reachable
objects, i.e. it has the same cost as 'git prune', it is enabled
only when a new option --fix-stale. Fortunately, once this is
run, we should not have to ever worry about missing objects,
because the current prune and pack-objects know about reflogs
and protect objects referred by them.
Unfortunately, this will be absolutely necessary to help people
migrate to the newer prune and repack.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-01-06 11:16:19 +01:00
|
|
|
test_done
|