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 &&
|
2015-12-22 16:05:48 +01:00
|
|
|
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) &&
|
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 &&
|
|
|
|
|
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 &&
|
2015-12-22 16:05:48 +01:00
|
|
|
L=$(git rev-parse --verify HEAD) &&
|
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 &&
|
|
|
|
|
|
|
|
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 &&
|
2015-12-22 16:05:48 +01:00
|
|
|
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) &&
|
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 &&
|
|
|
|
|
|
|
|
rm -f A/G &&
|
|
|
|
test_tick && git commit -a -m monkey &&
|
2015-12-22 16:05:48 +01:00
|
|
|
K=$(git rev-parse --verify HEAD) &&
|
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 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 &&
|
|
|
|
|
2015-07-28 00:57:08 +02:00
|
|
|
git reflog refs/heads/master >output &&
|
|
|
|
test_line_count = 4 output
|
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_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 &&
|
|
|
|
|
2015-07-28 00:57:08 +02:00
|
|
|
git reflog refs/heads/master >output &&
|
|
|
|
test_line_count = 5 output
|
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_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 &&
|
|
|
|
|
2015-07-28 00:57:08 +02:00
|
|
|
git reflog refs/heads/master >output &&
|
|
|
|
test_line_count = 5 output &&
|
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 "missing blob $F"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'reflog expire' '
|
|
|
|
|
|
|
|
git reflog expire --verbose \
|
|
|
|
--expire=$(($test_tick - 10000)) \
|
|
|
|
--expire-unreachable=$(($test_tick - 10000)) \
|
|
|
|
--stale-fix \
|
|
|
|
--all &&
|
|
|
|
|
2015-07-28 00:57:08 +02:00
|
|
|
git reflog refs/heads/master >output &&
|
|
|
|
test_line_count = 2 output &&
|
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 "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 &&
|
|
|
|
|
2010-10-31 02:46:54 +01:00
|
|
|
HEAD_entry_count=$(git reflog | wc -l) &&
|
|
|
|
master_entry_count=$(git reflog show master | wc -l) &&
|
2008-08-10 01:33:29 +02:00
|
|
|
|
|
|
|
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 &&
|
|
|
|
|
2010-10-31 02:46:54 +01:00
|
|
|
master_entry_count=$(wc -l < output) &&
|
2008-08-10 01:33:29 +02:00
|
|
|
|
|
|
|
git reflog delete HEAD@{1} &&
|
|
|
|
test $(($HEAD_entry_count -1)) = $(git reflog | wc -l) &&
|
|
|
|
test $master_entry_count = $(git reflog show master | wc -l) &&
|
|
|
|
|
2010-10-31 02:46:54 +01:00
|
|
|
HEAD_entry_count=$(git reflog | wc -l) &&
|
2008-08-10 01:33:29 +02:00
|
|
|
|
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
|
|
|
|
|
|
|
'
|
|
|
|
|
2010-02-27 04:50:03 +01:00
|
|
|
test_expect_success 'rewind2' '
|
|
|
|
|
|
|
|
test_tick && git reset --hard HEAD~2 &&
|
2015-07-28 00:57:08 +02:00
|
|
|
git reflog refs/heads/master >output &&
|
|
|
|
test_line_count = 4 output
|
2010-02-27 04:50:03 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '--expire=never' '
|
|
|
|
|
|
|
|
git reflog expire --verbose \
|
|
|
|
--expire=never \
|
|
|
|
--expire-unreachable=never \
|
|
|
|
--all &&
|
2015-07-28 00:57:08 +02:00
|
|
|
git reflog refs/heads/master >output &&
|
|
|
|
test_line_count = 4 output
|
2010-02-27 04:50:03 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'gc.reflogexpire=never' '
|
|
|
|
|
|
|
|
git config gc.reflogexpire never &&
|
|
|
|
git config gc.reflogexpireunreachable never &&
|
|
|
|
git reflog expire --verbose --all &&
|
2015-07-28 00:57:08 +02:00
|
|
|
git reflog refs/heads/master >output &&
|
|
|
|
test_line_count = 4 output
|
2010-02-27 04:50:03 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'gc.reflogexpire=false' '
|
|
|
|
|
|
|
|
git config gc.reflogexpire false &&
|
|
|
|
git config gc.reflogexpireunreachable false &&
|
|
|
|
git reflog expire --verbose --all &&
|
2015-07-28 00:57:08 +02:00
|
|
|
git reflog refs/heads/master >output &&
|
|
|
|
test_line_count = 4 output &&
|
2010-02-27 04:50:03 +01:00
|
|
|
|
|
|
|
git config --unset gc.reflogexpire &&
|
|
|
|
git config --unset gc.reflogexpireunreachable
|
|
|
|
|
|
|
|
'
|
|
|
|
|
2014-05-07 00:45:53 +02:00
|
|
|
test_expect_success 'checkout should not delete log for packed ref' '
|
|
|
|
test $(git reflog master | wc -l) = 4 &&
|
|
|
|
git branch foo &&
|
|
|
|
git pack-refs --all &&
|
|
|
|
git checkout foo &&
|
|
|
|
test $(git reflog master | wc -l) = 4
|
|
|
|
'
|
|
|
|
|
ignore stale directories when checking reflog existence
When we update a ref, we have two rules for whether or not
we actually update the reflog:
1. If the reflog already exists, we will always append to
it.
2. If log_all_ref_updates is set, we will create a new
reflog file if necessary.
We do the existence check by trying to open the reflog file,
either with or without O_CREAT (depending on log_all_ref_updates).
If it fails, then we check errno to see what happened.
If we were not using O_CREAT and we got ENOENT, the file
doesn't exist, and we return success (there isn't a reflog
already, and we were not told to make a new one).
If we get EISDIR, then there is likely a stale directory
that needs to be removed (e.g., there used to be "foo/bar",
it was deleted, and the directory "foo" was left. Now we
want to create the ref "foo"). If O_CREAT is set, then we
catch this case, try to remove the directory, and retry our
open. So far so good.
But if we get EISDIR and O_CREAT is not set, then we treat
this as any other error, which is not right. Like ENOENT,
EISDIR is an indication that we do not have a reflog, and we
should silently return success (we were not told to create
it). Instead, the current code reports this as an error, and
we fail to update the ref at all.
Note that this is relatively unlikely to happen, as you
would have to have had reflogs turned on, and then later
turned them off (it could also happen due to a bug in fetch,
but that was fixed in the previous commit). However, it's
quite easy to fix: we just need to treat EISDIR like ENOENT
for the non-O_CREAT case, and silently return (note that
this early return means we can also simplify the O_CREAT
case).
Our new tests cover both cases (O_CREAT and non-O_CREAT).
The first one already worked, of course.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-11-04 14:24:53 +01:00
|
|
|
test_expect_success 'stale dirs do not cause d/f conflicts (reflogs on)' '
|
2014-11-09 02:59:18 +01:00
|
|
|
test_when_finished "git branch -d one || git branch -d one/two" &&
|
ignore stale directories when checking reflog existence
When we update a ref, we have two rules for whether or not
we actually update the reflog:
1. If the reflog already exists, we will always append to
it.
2. If log_all_ref_updates is set, we will create a new
reflog file if necessary.
We do the existence check by trying to open the reflog file,
either with or without O_CREAT (depending on log_all_ref_updates).
If it fails, then we check errno to see what happened.
If we were not using O_CREAT and we got ENOENT, the file
doesn't exist, and we return success (there isn't a reflog
already, and we were not told to make a new one).
If we get EISDIR, then there is likely a stale directory
that needs to be removed (e.g., there used to be "foo/bar",
it was deleted, and the directory "foo" was left. Now we
want to create the ref "foo"). If O_CREAT is set, then we
catch this case, try to remove the directory, and retry our
open. So far so good.
But if we get EISDIR and O_CREAT is not set, then we treat
this as any other error, which is not right. Like ENOENT,
EISDIR is an indication that we do not have a reflog, and we
should silently return success (we were not told to create
it). Instead, the current code reports this as an error, and
we fail to update the ref at all.
Note that this is relatively unlikely to happen, as you
would have to have had reflogs turned on, and then later
turned them off (it could also happen due to a bug in fetch,
but that was fixed in the previous commit). However, it's
quite easy to fix: we just need to treat EISDIR like ENOENT
for the non-O_CREAT case, and silently return (note that
this early return means we can also simplify the O_CREAT
case).
Our new tests cover both cases (O_CREAT and non-O_CREAT).
The first one already worked, of course.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-11-04 14:24:53 +01:00
|
|
|
|
2014-11-09 02:59:18 +01:00
|
|
|
git branch one/two master &&
|
|
|
|
echo "one/two@{0} branch: Created from master" >expect &&
|
|
|
|
git log -g --format="%gd %gs" one/two >actual &&
|
ignore stale directories when checking reflog existence
When we update a ref, we have two rules for whether or not
we actually update the reflog:
1. If the reflog already exists, we will always append to
it.
2. If log_all_ref_updates is set, we will create a new
reflog file if necessary.
We do the existence check by trying to open the reflog file,
either with or without O_CREAT (depending on log_all_ref_updates).
If it fails, then we check errno to see what happened.
If we were not using O_CREAT and we got ENOENT, the file
doesn't exist, and we return success (there isn't a reflog
already, and we were not told to make a new one).
If we get EISDIR, then there is likely a stale directory
that needs to be removed (e.g., there used to be "foo/bar",
it was deleted, and the directory "foo" was left. Now we
want to create the ref "foo"). If O_CREAT is set, then we
catch this case, try to remove the directory, and retry our
open. So far so good.
But if we get EISDIR and O_CREAT is not set, then we treat
this as any other error, which is not right. Like ENOENT,
EISDIR is an indication that we do not have a reflog, and we
should silently return success (we were not told to create
it). Instead, the current code reports this as an error, and
we fail to update the ref at all.
Note that this is relatively unlikely to happen, as you
would have to have had reflogs turned on, and then later
turned them off (it could also happen due to a bug in fetch,
but that was fixed in the previous commit). However, it's
quite easy to fix: we just need to treat EISDIR like ENOENT
for the non-O_CREAT case, and silently return (note that
this early return means we can also simplify the O_CREAT
case).
Our new tests cover both cases (O_CREAT and non-O_CREAT).
The first one already worked, of course.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-11-04 14:24:53 +01:00
|
|
|
test_cmp expect actual &&
|
2014-11-09 02:59:18 +01:00
|
|
|
git branch -d one/two &&
|
ignore stale directories when checking reflog existence
When we update a ref, we have two rules for whether or not
we actually update the reflog:
1. If the reflog already exists, we will always append to
it.
2. If log_all_ref_updates is set, we will create a new
reflog file if necessary.
We do the existence check by trying to open the reflog file,
either with or without O_CREAT (depending on log_all_ref_updates).
If it fails, then we check errno to see what happened.
If we were not using O_CREAT and we got ENOENT, the file
doesn't exist, and we return success (there isn't a reflog
already, and we were not told to make a new one).
If we get EISDIR, then there is likely a stale directory
that needs to be removed (e.g., there used to be "foo/bar",
it was deleted, and the directory "foo" was left. Now we
want to create the ref "foo"). If O_CREAT is set, then we
catch this case, try to remove the directory, and retry our
open. So far so good.
But if we get EISDIR and O_CREAT is not set, then we treat
this as any other error, which is not right. Like ENOENT,
EISDIR is an indication that we do not have a reflog, and we
should silently return success (we were not told to create
it). Instead, the current code reports this as an error, and
we fail to update the ref at all.
Note that this is relatively unlikely to happen, as you
would have to have had reflogs turned on, and then later
turned them off (it could also happen due to a bug in fetch,
but that was fixed in the previous commit). However, it's
quite easy to fix: we just need to treat EISDIR like ENOENT
for the non-O_CREAT case, and silently return (note that
this early return means we can also simplify the O_CREAT
case).
Our new tests cover both cases (O_CREAT and non-O_CREAT).
The first one already worked, of course.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-11-04 14:24:53 +01:00
|
|
|
|
2014-11-09 02:59:18 +01:00
|
|
|
# now logs/refs/heads/one is a stale directory, but
|
|
|
|
# we should move it out of the way to create "one" reflog
|
|
|
|
git branch one master &&
|
|
|
|
echo "one@{0} branch: Created from master" >expect &&
|
|
|
|
git log -g --format="%gd %gs" one >actual &&
|
ignore stale directories when checking reflog existence
When we update a ref, we have two rules for whether or not
we actually update the reflog:
1. If the reflog already exists, we will always append to
it.
2. If log_all_ref_updates is set, we will create a new
reflog file if necessary.
We do the existence check by trying to open the reflog file,
either with or without O_CREAT (depending on log_all_ref_updates).
If it fails, then we check errno to see what happened.
If we were not using O_CREAT and we got ENOENT, the file
doesn't exist, and we return success (there isn't a reflog
already, and we were not told to make a new one).
If we get EISDIR, then there is likely a stale directory
that needs to be removed (e.g., there used to be "foo/bar",
it was deleted, and the directory "foo" was left. Now we
want to create the ref "foo"). If O_CREAT is set, then we
catch this case, try to remove the directory, and retry our
open. So far so good.
But if we get EISDIR and O_CREAT is not set, then we treat
this as any other error, which is not right. Like ENOENT,
EISDIR is an indication that we do not have a reflog, and we
should silently return success (we were not told to create
it). Instead, the current code reports this as an error, and
we fail to update the ref at all.
Note that this is relatively unlikely to happen, as you
would have to have had reflogs turned on, and then later
turned them off (it could also happen due to a bug in fetch,
but that was fixed in the previous commit). However, it's
quite easy to fix: we just need to treat EISDIR like ENOENT
for the non-O_CREAT case, and silently return (note that
this early return means we can also simplify the O_CREAT
case).
Our new tests cover both cases (O_CREAT and non-O_CREAT).
The first one already worked, of course.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-11-04 14:24:53 +01:00
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'stale dirs do not cause d/f conflicts (reflogs off)' '
|
2014-11-09 02:59:18 +01:00
|
|
|
test_when_finished "git branch -d one || git branch -d one/two" &&
|
ignore stale directories when checking reflog existence
When we update a ref, we have two rules for whether or not
we actually update the reflog:
1. If the reflog already exists, we will always append to
it.
2. If log_all_ref_updates is set, we will create a new
reflog file if necessary.
We do the existence check by trying to open the reflog file,
either with or without O_CREAT (depending on log_all_ref_updates).
If it fails, then we check errno to see what happened.
If we were not using O_CREAT and we got ENOENT, the file
doesn't exist, and we return success (there isn't a reflog
already, and we were not told to make a new one).
If we get EISDIR, then there is likely a stale directory
that needs to be removed (e.g., there used to be "foo/bar",
it was deleted, and the directory "foo" was left. Now we
want to create the ref "foo"). If O_CREAT is set, then we
catch this case, try to remove the directory, and retry our
open. So far so good.
But if we get EISDIR and O_CREAT is not set, then we treat
this as any other error, which is not right. Like ENOENT,
EISDIR is an indication that we do not have a reflog, and we
should silently return success (we were not told to create
it). Instead, the current code reports this as an error, and
we fail to update the ref at all.
Note that this is relatively unlikely to happen, as you
would have to have had reflogs turned on, and then later
turned them off (it could also happen due to a bug in fetch,
but that was fixed in the previous commit). However, it's
quite easy to fix: we just need to treat EISDIR like ENOENT
for the non-O_CREAT case, and silently return (note that
this early return means we can also simplify the O_CREAT
case).
Our new tests cover both cases (O_CREAT and non-O_CREAT).
The first one already worked, of course.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-11-04 14:24:53 +01:00
|
|
|
|
2014-11-09 02:59:18 +01:00
|
|
|
git branch one/two master &&
|
|
|
|
echo "one/two@{0} branch: Created from master" >expect &&
|
|
|
|
git log -g --format="%gd %gs" one/two >actual &&
|
ignore stale directories when checking reflog existence
When we update a ref, we have two rules for whether or not
we actually update the reflog:
1. If the reflog already exists, we will always append to
it.
2. If log_all_ref_updates is set, we will create a new
reflog file if necessary.
We do the existence check by trying to open the reflog file,
either with or without O_CREAT (depending on log_all_ref_updates).
If it fails, then we check errno to see what happened.
If we were not using O_CREAT and we got ENOENT, the file
doesn't exist, and we return success (there isn't a reflog
already, and we were not told to make a new one).
If we get EISDIR, then there is likely a stale directory
that needs to be removed (e.g., there used to be "foo/bar",
it was deleted, and the directory "foo" was left. Now we
want to create the ref "foo"). If O_CREAT is set, then we
catch this case, try to remove the directory, and retry our
open. So far so good.
But if we get EISDIR and O_CREAT is not set, then we treat
this as any other error, which is not right. Like ENOENT,
EISDIR is an indication that we do not have a reflog, and we
should silently return success (we were not told to create
it). Instead, the current code reports this as an error, and
we fail to update the ref at all.
Note that this is relatively unlikely to happen, as you
would have to have had reflogs turned on, and then later
turned them off (it could also happen due to a bug in fetch,
but that was fixed in the previous commit). However, it's
quite easy to fix: we just need to treat EISDIR like ENOENT
for the non-O_CREAT case, and silently return (note that
this early return means we can also simplify the O_CREAT
case).
Our new tests cover both cases (O_CREAT and non-O_CREAT).
The first one already worked, of course.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-11-04 14:24:53 +01:00
|
|
|
test_cmp expect actual &&
|
2014-11-09 02:59:18 +01:00
|
|
|
git branch -d one/two &&
|
ignore stale directories when checking reflog existence
When we update a ref, we have two rules for whether or not
we actually update the reflog:
1. If the reflog already exists, we will always append to
it.
2. If log_all_ref_updates is set, we will create a new
reflog file if necessary.
We do the existence check by trying to open the reflog file,
either with or without O_CREAT (depending on log_all_ref_updates).
If it fails, then we check errno to see what happened.
If we were not using O_CREAT and we got ENOENT, the file
doesn't exist, and we return success (there isn't a reflog
already, and we were not told to make a new one).
If we get EISDIR, then there is likely a stale directory
that needs to be removed (e.g., there used to be "foo/bar",
it was deleted, and the directory "foo" was left. Now we
want to create the ref "foo"). If O_CREAT is set, then we
catch this case, try to remove the directory, and retry our
open. So far so good.
But if we get EISDIR and O_CREAT is not set, then we treat
this as any other error, which is not right. Like ENOENT,
EISDIR is an indication that we do not have a reflog, and we
should silently return success (we were not told to create
it). Instead, the current code reports this as an error, and
we fail to update the ref at all.
Note that this is relatively unlikely to happen, as you
would have to have had reflogs turned on, and then later
turned them off (it could also happen due to a bug in fetch,
but that was fixed in the previous commit). However, it's
quite easy to fix: we just need to treat EISDIR like ENOENT
for the non-O_CREAT case, and silently return (note that
this early return means we can also simplify the O_CREAT
case).
Our new tests cover both cases (O_CREAT and non-O_CREAT).
The first one already worked, of course.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-11-04 14:24:53 +01:00
|
|
|
|
2014-11-09 02:59:18 +01:00
|
|
|
# same as before, but we only create a reflog for "one" if
|
ignore stale directories when checking reflog existence
When we update a ref, we have two rules for whether or not
we actually update the reflog:
1. If the reflog already exists, we will always append to
it.
2. If log_all_ref_updates is set, we will create a new
reflog file if necessary.
We do the existence check by trying to open the reflog file,
either with or without O_CREAT (depending on log_all_ref_updates).
If it fails, then we check errno to see what happened.
If we were not using O_CREAT and we got ENOENT, the file
doesn't exist, and we return success (there isn't a reflog
already, and we were not told to make a new one).
If we get EISDIR, then there is likely a stale directory
that needs to be removed (e.g., there used to be "foo/bar",
it was deleted, and the directory "foo" was left. Now we
want to create the ref "foo"). If O_CREAT is set, then we
catch this case, try to remove the directory, and retry our
open. So far so good.
But if we get EISDIR and O_CREAT is not set, then we treat
this as any other error, which is not right. Like ENOENT,
EISDIR is an indication that we do not have a reflog, and we
should silently return success (we were not told to create
it). Instead, the current code reports this as an error, and
we fail to update the ref at all.
Note that this is relatively unlikely to happen, as you
would have to have had reflogs turned on, and then later
turned them off (it could also happen due to a bug in fetch,
but that was fixed in the previous commit). However, it's
quite easy to fix: we just need to treat EISDIR like ENOENT
for the non-O_CREAT case, and silently return (note that
this early return means we can also simplify the O_CREAT
case).
Our new tests cover both cases (O_CREAT and non-O_CREAT).
The first one already worked, of course.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-11-04 14:24:53 +01:00
|
|
|
# it already exists, which it does not
|
2014-11-09 02:59:18 +01:00
|
|
|
git -c core.logallrefupdates=false branch one master &&
|
ignore stale directories when checking reflog existence
When we update a ref, we have two rules for whether or not
we actually update the reflog:
1. If the reflog already exists, we will always append to
it.
2. If log_all_ref_updates is set, we will create a new
reflog file if necessary.
We do the existence check by trying to open the reflog file,
either with or without O_CREAT (depending on log_all_ref_updates).
If it fails, then we check errno to see what happened.
If we were not using O_CREAT and we got ENOENT, the file
doesn't exist, and we return success (there isn't a reflog
already, and we were not told to make a new one).
If we get EISDIR, then there is likely a stale directory
that needs to be removed (e.g., there used to be "foo/bar",
it was deleted, and the directory "foo" was left. Now we
want to create the ref "foo"). If O_CREAT is set, then we
catch this case, try to remove the directory, and retry our
open. So far so good.
But if we get EISDIR and O_CREAT is not set, then we treat
this as any other error, which is not right. Like ENOENT,
EISDIR is an indication that we do not have a reflog, and we
should silently return success (we were not told to create
it). Instead, the current code reports this as an error, and
we fail to update the ref at all.
Note that this is relatively unlikely to happen, as you
would have to have had reflogs turned on, and then later
turned them off (it could also happen due to a bug in fetch,
but that was fixed in the previous commit). However, it's
quite easy to fix: we just need to treat EISDIR like ENOENT
for the non-O_CREAT case, and silently return (note that
this early return means we can also simplify the O_CREAT
case).
Our new tests cover both cases (O_CREAT and non-O_CREAT).
The first one already worked, of course.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-11-04 14:24:53 +01:00
|
|
|
: >expect &&
|
2014-11-09 02:59:18 +01:00
|
|
|
git log -g --format="%gd %gs" one >actual &&
|
ignore stale directories when checking reflog existence
When we update a ref, we have two rules for whether or not
we actually update the reflog:
1. If the reflog already exists, we will always append to
it.
2. If log_all_ref_updates is set, we will create a new
reflog file if necessary.
We do the existence check by trying to open the reflog file,
either with or without O_CREAT (depending on log_all_ref_updates).
If it fails, then we check errno to see what happened.
If we were not using O_CREAT and we got ENOENT, the file
doesn't exist, and we return success (there isn't a reflog
already, and we were not told to make a new one).
If we get EISDIR, then there is likely a stale directory
that needs to be removed (e.g., there used to be "foo/bar",
it was deleted, and the directory "foo" was left. Now we
want to create the ref "foo"). If O_CREAT is set, then we
catch this case, try to remove the directory, and retry our
open. So far so good.
But if we get EISDIR and O_CREAT is not set, then we treat
this as any other error, which is not right. Like ENOENT,
EISDIR is an indication that we do not have a reflog, and we
should silently return success (we were not told to create
it). Instead, the current code reports this as an error, and
we fail to update the ref at all.
Note that this is relatively unlikely to happen, as you
would have to have had reflogs turned on, and then later
turned them off (it could also happen due to a bug in fetch,
but that was fixed in the previous commit). However, it's
quite easy to fix: we just need to treat EISDIR like ENOENT
for the non-O_CREAT case, and silently return (note that
this early return means we can also simplify the O_CREAT
case).
Our new tests cover both cases (O_CREAT and non-O_CREAT).
The first one already worked, of course.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-11-04 14:24:53 +01:00
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
for_each_reflog_ent_reverse: fix newlines on block boundaries
When we read a reflog file in reverse, we read whole chunks
of BUFSIZ bytes, then loop over the buffer, parsing any
lines we find. We find the beginning of each line by looking
for the newline from the previous line. If we don't find
one, we know that we are either at the beginning of
the file, or that we have to read another block.
In the latter case, we stuff away what we have into a
strbuf, read another block, and continue our parse. But we
missed one case here. If we did find a newline, and it is at
the beginning of the block, we must also stuff that newline
into the strbuf, as it belongs to the block we are about to
read.
The minimal fix here would be to add this special case to
the conditional that checks whether we found a newline.
But we can make the flow a little clearer by rearranging a
bit: we first handle lines that we are going to show, and
then at the end of each loop, stuff away any leftovers if
necessary. That lets us fold this special-case in with the
more common "we ended in the middle of a line" case.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-12-05 02:28:54 +01:00
|
|
|
# Triggering the bug detected by this test requires a newline to fall
|
|
|
|
# exactly BUFSIZ-1 bytes from the end of the file. We don't know
|
|
|
|
# what that value is, since it's platform dependent. However, if
|
|
|
|
# we choose some value N, we also catch any D which divides N evenly
|
|
|
|
# (since we will read backwards in chunks of D). So we choose 8K,
|
|
|
|
# which catches glibc (with an 8K BUFSIZ) and *BSD (1K).
|
|
|
|
#
|
|
|
|
# Each line is 114 characters, so we need 75 to still have a few before the
|
|
|
|
# last 8K. The 89-character padding on the final entry lines up our
|
|
|
|
# newline exactly.
|
|
|
|
test_expect_success 'parsing reverse reflogs at BUFSIZ boundaries' '
|
|
|
|
git checkout -b reflogskip &&
|
|
|
|
z38=00000000000000000000000000000000000000 &&
|
|
|
|
ident="abc <xyz> 0000000001 +0000" &&
|
|
|
|
for i in $(test_seq 1 75); do
|
|
|
|
printf "$z38%02d $z38%02d %s\t" $i $(($i+1)) "$ident" &&
|
|
|
|
if test $i = 75; then
|
|
|
|
for j in $(test_seq 1 89); do
|
|
|
|
printf X
|
|
|
|
done
|
|
|
|
else
|
|
|
|
printf X
|
|
|
|
fi &&
|
|
|
|
printf "\n"
|
|
|
|
done >.git/logs/refs/heads/reflogskip &&
|
|
|
|
git rev-parse reflogskip@{73} >actual &&
|
|
|
|
echo ${z38}03 >expect &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2016-01-05 22:12:10 +01:00
|
|
|
test_expect_success 'no segfaults for reflog containing non-commit sha1s' '
|
|
|
|
git update-ref --create-reflog -m "Creating ref" \
|
|
|
|
refs/tests/tree-in-reflog HEAD &&
|
|
|
|
git update-ref -m "Forcing tree" refs/tests/tree-in-reflog HEAD^{tree} &&
|
|
|
|
git update-ref -m "Restoring to commit" refs/tests/tree-in-reflog HEAD &&
|
|
|
|
git reflog refs/tests/tree-in-reflog
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_failure 'reflog with non-commit entries displays all entries' '
|
|
|
|
git reflog refs/tests/tree-in-reflog >actual &&
|
|
|
|
test_line_count = 3 actual
|
|
|
|
'
|
|
|
|
|
2016-04-07 21:03:11 +02:00
|
|
|
test_expect_success 'reflog expire operates on symref not referrent' '
|
|
|
|
git branch -l the_symref &&
|
|
|
|
git branch -l referrent &&
|
|
|
|
git update-ref referrent HEAD &&
|
|
|
|
git symbolic-ref refs/heads/the_symref refs/heads/referrent &&
|
|
|
|
test_when_finished "rm -f .git/refs/heads/referrent.lock" &&
|
|
|
|
touch .git/refs/heads/referrent.lock &&
|
|
|
|
git reflog expire --expire=all the_symref
|
|
|
|
'
|
|
|
|
|
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
|