blob: 8632612c31d07818659ff4f68ee567c789e5cd48 [file] [log] [blame]
Junio C Hamano1a4e8412005-12-27 08:17:231git-sh-setup(1)
2===============
3
4NAME
5----
Junio C Hamano076ffcc2013-02-06 05:13:216git-sh-setup - Common Git shell script setup code
Junio C Hamano1a4e8412005-12-27 08:17:237
8SYNOPSIS
9--------
Junio C Hamano15567bc2011-07-23 00:51:5910[verse]
Junio C Hamanobb8e9962008-06-30 09:05:0811'. "$(git --exec-path)/git-sh-setup"'
Junio C Hamano1a4e8412005-12-27 08:17:2312
13DESCRIPTION
14-----------
15
Junio C Hamanof9771f62007-01-17 17:42:3016This 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.
Junio C Hamano1a4e8412005-12-27 08:17:2319
Junio C Hamano1aa40d22010-01-21 17:46:4320The 'git sh-setup' scriptlet is designed to be sourced (using
Junio C Hamanof9771f62007-01-17 17:42:3021`.`) by other shell scripts to set up some variables pointing at
Junio C Hamano076ffcc2013-02-06 05:13:2122the normal Git directories and a few helper shell functions.
Junio C Hamanof9771f62007-01-17 17:42:3023
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::
37exit after emitting the supplied error message to the
38standard error stream.
39
40usage::
41die with the usage message.
42
43set_reflog_action::
Junio C Hamano042f2142016-06-27 18:05:0544Set `GIT_REFLOG_ACTION` environment to a given string (typically
Junio C Hamanoaef76442013-10-18 22:11:2745the name of the program) unless it is already set. Whenever
46the script runs a `git` command that updates refs, a reflog
47entry is created using the value of this string to leave the
48record of what command updated the ref.
Junio C Hamanof9771f62007-01-17 17:42:3049
Junio C Hamano91baf102007-12-31 09:44:2650git_editor::
51runs an editor of user's choice (GIT_EDITOR, core.editor, VISUAL or
52EDITOR) on a given file, but error out if no editor is specified
53and the terminal is dumb.
54
Junio C Hamanof9771f62007-01-17 17:42:3055is_bare_repository::
56outputs `true` or `false` to the standard output stream
57to indicate if the repository is a bare repository
58(i.e. without an associated working tree).
59
60cd_to_toplevel::
61runs chdir to the toplevel of the working tree.
62
63require_work_tree::
Junio C Hamano90b56532011-05-26 22:39:4964checks if the current directory is within the working tree
65of the repository, and otherwise dies.
66
67require_work_tree_exists::
68checks if the working tree associated with the repository
69exists, and otherwise dies. Often done before calling
70cd_to_toplevel, which is impossible to do if there is no
71working tree.
Junio C Hamanof9771f62007-01-17 17:42:3072
Junio C Hamanodb472bc2012-01-04 00:22:3773require_clean_work_tree <action> [<hint>]::
74checks that the working tree and index associated with the
75repository have no uncommitted changes to tracked files.
76Otherwise 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
Junio C Hamano91baf102007-12-31 09:44:2683get_author_ident_from_commit::
84outputs code for use with eval to set the GIT_AUTHOR_NAME,
85GIT_AUTHOR_EMAIL and GIT_AUTHOR_DATE variables for a given commit.
86
Junio C Hamano712be262013-03-26 22:45:5687create_virtual_base::
88modifies the first file so only lines in common with the
89second file remain. If there is insufficient common material,
90then the first file is left empty. The result is suitable
91as a virtual base input for a 3-way merge.
92
Junio C Hamano1a4e8412005-12-27 08:17:2393GIT
94---
Junio C Hamanof7c042d2008-06-06 22:50:5395Part of the linkgit:git[1] suite