1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
'\" t
.\" Title: git-sh-setup
.\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
.\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
.\" Date: 04/17/2023
.\" Manual: Git Manual
.\" Source: Git 2.40.0.352.g667fcf4e15
.\" Language: English
.\"
.TH "GIT\-SH\-SETUP" "1" "04/17/2023" "Git 2\&.40\&.0\&.352\&.g667fcf" "Git Manual"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
git-sh-setup \- Common Git shell script setup code
.SH "SYNOPSIS"
.sp
.nf
\fI\&. "$(git \-\-exec\-path)/git\-sh\-setup"\fR
.fi
.sp
.SH "DESCRIPTION"
.sp
This is not a command the end user would want to run\&. Ever\&. This documentation is meant for people who are studying the Porcelain\-ish scripts and/or are writing new ones\&.
.sp
The \fIgit sh\-setup\fR scriptlet is designed to be sourced (using \fB\&.\fR) by other shell scripts to set up some variables pointing at the normal Git directories and a few helper shell functions\&.
.sp
Before sourcing it, your script should set up a few variables; \fBUSAGE\fR (and \fBLONG_USAGE\fR, if any) is used to define message given by \fBusage()\fR shell function\&. \fBSUBDIRECTORY_OK\fR can be set if the script can run from a subdirectory of the working tree (some commands do not)\&.
.sp
The scriptlet sets \fBGIT_DIR\fR and \fBGIT_OBJECT_DIRECTORY\fR shell variables, but does \fBnot\fR export them to the environment\&.
.SH "FUNCTIONS"
.PP
die
.RS 4
exit after emitting the supplied error message to the standard error stream\&.
.RE
.PP
usage
.RS 4
die with the usage message\&.
.RE
.PP
set_reflog_action
.RS 4
Set
\fBGIT_REFLOG_ACTION\fR
environment to a given string (typically the name of the program) unless it is already set\&. Whenever the script runs a
\fBgit\fR
command that updates refs, a reflog entry is created using the value of this string to leave the record of what command updated the ref\&.
.RE
.PP
git_editor
.RS 4
runs an editor of user\(cqs choice (GIT_EDITOR, core\&.editor, VISUAL or EDITOR) on a given file, but error out if no editor is specified and the terminal is dumb\&.
.RE
.PP
is_bare_repository
.RS 4
outputs
\fBtrue\fR
or
\fBfalse\fR
to the standard output stream to indicate if the repository is a bare repository (i\&.e\&. without an associated working tree)\&.
.RE
.PP
cd_to_toplevel
.RS 4
runs chdir to the toplevel of the working tree\&.
.RE
.PP
require_work_tree
.RS 4
checks if the current directory is within the working tree of the repository, and otherwise dies\&.
.RE
.PP
require_work_tree_exists
.RS 4
checks if the working tree associated with the repository exists, and otherwise dies\&. Often done before calling cd_to_toplevel, which is impossible to do if there is no working tree\&.
.RE
.PP
require_clean_work_tree <action> [<hint>]
.RS 4
checks that the working tree and index associated with the repository have no uncommitted changes to tracked files\&. Otherwise it emits an error message of the form
\fBCannot <action>: <reason>\&. <hint>\fR, and dies\&. Example:
.sp
.if n \{\
.RS 4
.\}
.nf
require_clean_work_tree rebase "Please commit or stash them\&."
.fi
.if n \{\
.RE
.\}
.sp
.RE
.PP
get_author_ident_from_commit
.RS 4
outputs code for use with eval to set the GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL and GIT_AUTHOR_DATE variables for a given commit\&.
.RE
.PP
create_virtual_base
.RS 4
modifies the first file so only lines in common with the second file remain\&. If there is insufficient common material, then the first file is left empty\&. The result is suitable as a virtual base input for a 3\-way merge\&.
.RE
.SH "GIT"
.sp
Part of the \fBgit\fR(1) suite
|