Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 1 | git-sh-setup(1) |
| 2 | =============== |
| 3 | |
| 4 | NAME |
| 5 | ---- |
Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 6 | git-sh-setup - Common Git shell script setup code |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 7 | |
| 8 | SYNOPSIS |
| 9 | -------- |
Junio C Hamano | 15567bc | 2011-07-23 00:51:59 | [diff] [blame] | 10 | [verse] |
Junio C Hamano | bb8e996 | 2008-06-30 09:05:08 | [diff] [blame] | 11 | '. "$(git --exec-path)/git-sh-setup"' |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 12 | |
| 13 | DESCRIPTION |
| 14 | ----------- |
| 15 | |
Junio C Hamano | f9771f6 | 2007-01-17 17:42:30 | [diff] [blame] | 16 | This is not a command the end user would want to run. Ever. |
| 17 | This documentation is meant for people who are studying the |
| 18 | Porcelain-ish scripts and/or are writing new ones. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 19 | |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 20 | The 'git sh-setup' scriptlet is designed to be sourced (using |
Junio C Hamano | f9771f6 | 2007-01-17 17:42:30 | [diff] [blame] | 21 | `.`) by other shell scripts to set up some variables pointing at |
Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 22 | the normal Git directories and a few helper shell functions. |
Junio C Hamano | f9771f6 | 2007-01-17 17:42:30 | [diff] [blame] | 23 | |
| 24 | Before sourcing it, your script should set up a few variables; |
| 25 | `USAGE` (and `LONG_USAGE`, if any) is used to define message |
| 26 | given by `usage()` shell function. `SUBDIRECTORY_OK` can be set |
| 27 | if the script can run from a subdirectory of the working tree |
| 28 | (some commands do not). |
| 29 | |
| 30 | The scriptlet sets `GIT_DIR` and `GIT_OBJECT_DIRECTORY` shell |
| 31 | variables, but does *not* export them to the environment. |
| 32 | |
| 33 | FUNCTIONS |
| 34 | --------- |
| 35 | |
| 36 | die:: |
| 37 | exit after emitting the supplied error message to the |
| 38 | standard error stream. |
| 39 | |
| 40 | usage:: |
| 41 | die with the usage message. |
| 42 | |
| 43 | 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. |
| 47 | |
Junio C Hamano | 91baf10 | 2007-12-31 09:44:26 | [diff] [blame] | 48 | git_editor:: |
| 49 | runs an editor of user's choice (GIT_EDITOR, core.editor, VISUAL or |
| 50 | EDITOR) on a given file, but error out if no editor is specified |
| 51 | and the terminal is dumb. |
| 52 | |
Junio C Hamano | f9771f6 | 2007-01-17 17:42:30 | [diff] [blame] | 53 | is_bare_repository:: |
| 54 | outputs `true` or `false` to the standard output stream |
| 55 | to indicate if the repository is a bare repository |
| 56 | (i.e. without an associated working tree). |
| 57 | |
| 58 | cd_to_toplevel:: |
| 59 | runs chdir to the toplevel of the working tree. |
| 60 | |
| 61 | require_work_tree:: |
Junio C Hamano | 90b5653 | 2011-05-26 22:39:49 | [diff] [blame] | 62 | checks if the current directory is within the working tree |
| 63 | of the repository, and otherwise dies. |
| 64 | |
| 65 | require_work_tree_exists:: |
| 66 | checks if the working tree associated with the repository |
| 67 | exists, and otherwise dies. Often done before calling |
| 68 | cd_to_toplevel, which is impossible to do if there is no |
| 69 | working tree. |
Junio C Hamano | f9771f6 | 2007-01-17 17:42:30 | [diff] [blame] | 70 | |
Junio C Hamano | db472bc | 2012-01-04 00:22:37 | [diff] [blame] | 71 | require_clean_work_tree <action> [<hint>]:: |
| 72 | checks that the working tree and index associated with the |
| 73 | repository have no uncommitted changes to tracked files. |
| 74 | Otherwise it emits an error message of the form `Cannot |
| 75 | <action>: <reason>. <hint>`, and dies. Example: |
| 76 | + |
| 77 | ---------------- |
| 78 | require_clean_work_tree rebase "Please commit or stash them." |
| 79 | ---------------- |
| 80 | |
Junio C Hamano | 91baf10 | 2007-12-31 09:44:26 | [diff] [blame] | 81 | get_author_ident_from_commit:: |
| 82 | outputs code for use with eval to set the GIT_AUTHOR_NAME, |
| 83 | GIT_AUTHOR_EMAIL and GIT_AUTHOR_DATE variables for a given commit. |
| 84 | |
Junio C Hamano | 712be26 | 2013-03-26 22:45:56 | [diff] [blame^] | 85 | create_virtual_base:: |
| 86 | modifies the first file so only lines in common with the |
| 87 | second file remain. If there is insufficient common material, |
| 88 | then the first file is left empty. The result is suitable |
| 89 | as a virtual base input for a 3-way merge. |
| 90 | |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 91 | GIT |
| 92 | --- |
Junio C Hamano | f7c042d | 2008-06-06 22:50:53 | [diff] [blame] | 93 | Part of the linkgit:git[1] suite |