Skip to content

Commit 55b7835

Browse files
spearceJunio C Hamano
authored andcommitted
Log ref changes made by git-fetch and git-pull.
When git-fetch updates a reference record in the associated reflog what type of update took place and who caused it (git-fetch or git-pull, by invoking git-fetch). Signed-off-by: Shawn O. Pearce <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a3a733e commit 55b7835

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

git-fetch.sh

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ LF='
1111
'
1212
IFS="$LF"
1313

14+
rloga=fetch
1415
no_tags=
1516
tags=
1617
append=
@@ -51,6 +52,9 @@ do
5152
-k|--k|--ke|--kee|--keep)
5253
keep=--keep
5354
;;
55+
--reflog-action=*)
56+
rloga=`expr "z$1" : 'z-[^=]*=\(.*\)'`
57+
;;
5458
-*)
5559
usage
5660
;;
@@ -75,6 +79,9 @@ refs=
7579
rref=
7680
rsync_slurped_objects=
7781

82+
rloga="$rloga $remote_nick"
83+
test "$remote_nick" == "$remote" || rloga="$rloga $remote"
84+
7885
if test "" = "$append"
7986
then
8087
: >"$GIT_DIR/FETCH_HEAD"
@@ -149,11 +156,12 @@ fast_forward_local () {
149156
[ "$verbose" ] && echo >&2 "* $1: same as $3"
150157
else
151158
echo >&2 "* $1: updating with $3"
159+
git-update-ref -m "$rloga: updating tag" "$1" "$2"
152160
fi
153161
else
154162
echo >&2 "* $1: storing $3"
163+
git-update-ref -m "$rloga: storing tag" "$1" "$2"
155164
fi
156-
git-update-ref "$1" "$2"
157165
;;
158166

159167
refs/heads/* | refs/remotes/*)
@@ -174,7 +182,7 @@ fast_forward_local () {
174182
*,$local)
175183
echo >&2 "* $1: fast forward to $3"
176184
echo >&2 " from $local to $2"
177-
git-update-ref "$1" "$2" "$local"
185+
git-update-ref -m "$rloga: fast-forward" "$1" "$2" "$local"
178186
;;
179187
*)
180188
false
@@ -184,7 +192,7 @@ fast_forward_local () {
184192
case ",$force,$single_force," in
185193
*,t,*)
186194
echo >&2 " forcing update."
187-
git-update-ref "$1" "$2" "$local"
195+
git-update-ref -m "$rloga: forced-update" "$1" "$2" "$local"
188196
;;
189197
*)
190198
echo >&2 " not updating."
@@ -194,7 +202,7 @@ fast_forward_local () {
194202
}
195203
else
196204
echo >&2 "* $1: storing $3"
197-
git-update-ref "$1" "$2"
205+
git-update-ref -m "$rloga: storing head" "$1" "$2"
198206
fi
199207
;;
200208
esac
@@ -422,7 +430,9 @@ case ",$update_head_ok,$orig_head," in
422430
curr_head=$(git-rev-parse --verify HEAD 2>/dev/null)
423431
if test "$curr_head" != "$orig_head"
424432
then
425-
git-update-ref HEAD "$orig_head"
433+
git-update-ref \
434+
-m "$rloga: Undoing incorrectly fetched HEAD." \
435+
HEAD "$orig_head"
426436
die "Cannot fetch into the current branch."
427437
fi
428438
;;

git-pull.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ do
4545
done
4646

4747
orig_head=$(git-rev-parse --verify HEAD) || die "Pulling into a black hole?"
48-
git-fetch --update-head-ok "$@" || exit 1
48+
git-fetch --update-head-ok --reflog-action=pull "$@" || exit 1
4949

5050
curr_head=$(git-rev-parse --verify HEAD)
5151
if test "$curr_head" != "$orig_head"

0 commit comments

Comments
 (0)