Skip to content

Commit 6c2bec9

Browse files
committed
Merge branch 'jc/reflog-doc'
Document rules to use GIT_REFLOG_ACTION variable in the scripted Porcelain. git-rebase--interactive locally violates them, but it is a leaf user that does not call out to or dot-source other scripts, so it does not urgently need to be fixed. * jc/reflog-doc: setup_reflog_action: document the rules for using GIT_REFLOG_ACTION
2 parents dec034a + c3e2d18 commit 6c2bec9

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

Documentation/git-sh-setup.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ usage::
4141
die with the usage message.
4242

4343
set_reflog_action::
44-
set the message that will be recorded to describe the
45-
end-user action in the reflog, when the script updates a
46-
ref.
44+
Set GIT_REFLOG_ACTION environment to a given string (typically
45+
the name of the program) unless it is already set. Whenever
46+
the script runs a `git` command that updates refs, a reflog
47+
entry is created using the value of this string to leave the
48+
record of what command updated the ref.
4749

4850
git_editor::
4951
runs an editor of user's choice (GIT_EDITOR, core.editor, VISUAL or

Documentation/git.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,16 @@ GIT_ICASE_PATHSPECS::
909909
Setting this variable to `1` will cause Git to treat all
910910
pathspecs as case-insensitive.
911911

912+
'GIT_REFLOG_ACTION'::
913+
When a ref is updated, reflog entries are created to keep
914+
track of the reason why the ref was updated (which is
915+
typically the name of the high-level command that updated
916+
the ref), in addition to the old and new values of the ref.
917+
A scripted Porcelain command can use set_reflog_action
918+
helper function in `git-sh-setup` to set its name to this
919+
variable when it is invoked as the top level command by the
920+
end user, to be recorded in the body of the reflog.
921+
912922

913923
Discussion[[Discussion]]
914924
------------------------

git-sh-setup.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,40 @@ $LONG_USAGE"
103103
esac
104104
fi
105105
106+
# Set the name of the end-user facing command in the reflog when the
107+
# script may update refs. When GIT_REFLOG_ACTION is already set, this
108+
# will not overwrite it, so that a scripted Porcelain (e.g. "git
109+
# rebase") can set it to its own name (e.g. "rebase") and then call
110+
# another scripted Porcelain (e.g. "git am") and a call to this
111+
# function in the latter will keep the name of the end-user facing
112+
# program (e.g. "rebase") in GIT_REFLOG_ACTION, ensuring whatever it
113+
# does will be record as actions done as part of the end-user facing
114+
# operation (e.g. "rebase").
115+
#
116+
# NOTE NOTE NOTE: consequently, after assigning a specific message to
117+
# GIT_REFLOG_ACTION when calling a "git" command to record a custom
118+
# reflog message, do not leave that custom value in GIT_REFLOG_ACTION,
119+
# after you are done. Other callers of "git" commands that rely on
120+
# writing the default "program name" in reflog expect the variable to
121+
# contain the value set by this function.
122+
#
123+
# To use a custom reflog message, do either one of these three:
124+
#
125+
# (a) use a single-shot export form:
126+
# GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: preparing frotz" \
127+
# git command-that-updates-a-ref
128+
#
129+
# (b) save the original away and restore:
130+
# SAVED_ACTION=$GIT_REFLOG_ACTION
131+
# GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: preparing frotz"
132+
# git command-that-updates-a-ref
133+
# GIT_REFLOG_ACITON=$SAVED_ACTION
134+
#
135+
# (c) assign the variable in a subshell:
136+
# (
137+
# GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: preparing frotz"
138+
# git command-that-updates-a-ref
139+
# )
106140
set_reflog_action() {
107141
if [ -z "${GIT_REFLOG_ACTION:+set}" ]
108142
then

0 commit comments

Comments
 (0)