]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/git-sh-setup.txt
Merge branch 'js/t3404-typofix' into maint
[thirdparty/git.git] / Documentation / git-sh-setup.txt
CommitLineData
215a7ad1
JH
1git-sh-setup(1)
2===============
7fc9d69f
JH
3
4NAME
5----
2de9b711 6git-sh-setup - Common Git shell script setup code
7fc9d69f
JH
7
8SYNOPSIS
9--------
7791a1d9 10[verse]
bd870878 11'. "$(git --exec-path)/git-sh-setup"'
7fc9d69f
JH
12
13DESCRIPTION
14-----------
7fc9d69f 15
850844e2
JH
16This is not a command the end user would want to run. Ever.
17This documentation is meant for people who are studying the
18Porcelain-ish scripts and/or are writing new ones.
19
0b444cdb 20The 'git sh-setup' scriptlet is designed to be sourced (using
850844e2 21`.`) by other shell scripts to set up some variables pointing at
2de9b711 22the normal Git directories and a few helper shell functions.
850844e2
JH
23
24Before sourcing it, your script should set up a few variables;
25`USAGE` (and `LONG_USAGE`, if any) is used to define message
26given by `usage()` shell function. `SUBDIRECTORY_OK` can be set
27if the script can run from a subdirectory of the working tree
28(some commands do not).
29
30The scriptlet sets `GIT_DIR` and `GIT_OBJECT_DIRECTORY` shell
31variables, but does *not* export them to the environment.
32
33FUNCTIONS
34---------
35
36die::
37 exit after emitting the supplied error message to the
38 standard error stream.
39
40usage::
41 die with the usage message.
42
43set_reflog_action::
47d81b5c 44 Set `GIT_REFLOG_ACTION` environment to a given string (typically
c3e2d189
JH
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.
850844e2 49
3f4bc3e0
MV
50git_editor::
51 runs an editor of user's choice (GIT_EDITOR, core.editor, VISUAL or
52 EDITOR) on a given file, but error out if no editor is specified
53 and the terminal is dumb.
54
850844e2
JH
55is_bare_repository::
56 outputs `true` or `false` to the standard output stream
57 to indicate if the repository is a bare repository
58 (i.e. without an associated working tree).
59
60cd_to_toplevel::
61 runs chdir to the toplevel of the working tree.
62
63require_work_tree::
e2eb5273
JH
64 checks if the current directory is within the working tree
65 of the repository, and otherwise dies.
66
67require_work_tree_exists::
68 checks if the working tree associated with the repository
69 exists, and otherwise dies. Often done before calling
70 cd_to_toplevel, which is impossible to do if there is no
71 working tree.
850844e2 72
d577cd21
TR
73require_clean_work_tree <action> [<hint>]::
74 checks that the working tree and index associated with the
75 repository have no uncommitted changes to tracked files.
76 Otherwise it emits an error message of the form `Cannot
77 <action>: <reason>. <hint>`, and dies. Example:
78+
79----------------
80require_clean_work_tree rebase "Please commit or stash them."
81----------------
82
3f4bc3e0
MV
83get_author_ident_from_commit::
84 outputs code for use with eval to set the GIT_AUTHOR_NAME,
85 GIT_AUTHOR_EMAIL and GIT_AUTHOR_DATE variables for a given commit.
86
4549162e
KB
87create_virtual_base::
88 modifies the first file so only lines in common with the
89 second file remain. If there is insufficient common material,
90 then the first file is left empty. The result is suitable
91 as a virtual base input for a 3-way merge.
92
7fc9d69f
JH
93GIT
94---
9e1f0a85 95Part of the linkgit:git[1] suite