2005-09-08 04:26:23 +04:00
|
|
|
git-sh-setup(1)
|
|
|
|
===============
|
2005-08-23 12:49:47 +04:00
|
|
|
|
|
|
|
NAME
|
|
|
|
----
|
2013-01-21 23:17:53 +04:00
|
|
|
git-sh-setup - Common Git shell script setup code
|
2005-08-23 12:49:47 +04:00
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
--------
|
2011-07-02 06:38:26 +04:00
|
|
|
[verse]
|
2008-06-29 20:10:20 +04:00
|
|
|
'. "$(git --exec-path)/git-sh-setup"'
|
2005-08-23 12:49:47 +04:00
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
-----------
|
|
|
|
|
2007-01-17 12:13:05 +03:00
|
|
|
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.
|
|
|
|
|
2010-01-10 02:33:00 +03:00
|
|
|
The 'git sh-setup' scriptlet is designed to be sourced (using
|
2007-01-17 12:13:05 +03:00
|
|
|
`.`) by other shell scripts to set up some variables pointing at
|
2013-01-21 23:17:53 +04:00
|
|
|
the normal Git directories and a few helper shell functions.
|
2007-01-17 12:13:05 +03:00
|
|
|
|
|
|
|
Before sourcing it, your script should set up a few variables;
|
|
|
|
`USAGE` (and `LONG_USAGE`, if any) is used to define message
|
|
|
|
given by `usage()` shell function. `SUBDIRECTORY_OK` can be set
|
|
|
|
if the script can run from a subdirectory of the working tree
|
|
|
|
(some commands do not).
|
|
|
|
|
|
|
|
The scriptlet sets `GIT_DIR` and `GIT_OBJECT_DIRECTORY` shell
|
|
|
|
variables, but does *not* export them to the environment.
|
|
|
|
|
|
|
|
FUNCTIONS
|
|
|
|
---------
|
|
|
|
|
|
|
|
die::
|
|
|
|
exit after emitting the supplied error message to the
|
|
|
|
standard error stream.
|
|
|
|
|
|
|
|
usage::
|
|
|
|
die with the usage message.
|
|
|
|
|
|
|
|
set_reflog_action::
|
2016-06-08 01:35:07 +03:00
|
|
|
Set `GIT_REFLOG_ACTION` environment to a given string (typically
|
setup_reflog_action: document the rules for using GIT_REFLOG_ACTION
The set_reflog_action helper (in git-sh-setup) is designed to be
used once at the very top of a program, like this in "git am", for
example:
set_reflog_action am
The helper function sets the given string to GIT_REFLOG_ACTION only
when GIT_REFLOG_ACTION is not yet set. Thanks to this, "git am",
when run as the top-level program, will use "am" in GIT_REFLOG_ACTION
and the reflog entries made by whatever it does will record the
updates of refs done by "am".
Because of the conditional assignment, when "git am" is run as a
subprogram (i.e. an implementation detail) of "git rebase" that
already sets GIT_REFLOG_ACTION to its own name, the call in "git am"
to the helper function at the beginning will *not* have any effect.
So "git rebase" can do this:
set_reflog_action rebase
... do its own preparation, like checking out "onto" commit
... decide to do "format-patch" to "am" pipeline
git format-patch --stdout >mbox
git am mbox
and the reflog entries made inside "git am" invocation will say
"rebase", not "am".
Calls to "git" commands that update refs would use GIT_REFLOG_ACTION
to record who did that update. Most such calls in scripted Porcelains
do not define custom reflog message and rely on GIT_REFLOG_ACTION to
contain its (or its caller's, when it is called as a subprogram) name.
If a scripted Porcelain wants to record a custom reflog message for
a single invocation of "git" command (e.g. when "git rebase" uses
"git checkout" to detach HEAD at the commit a series is to be
replayed on), it needs to set GIT_REFLOG_ACTION to the custom
message and export it while calling the "git" command, but such an
assignment must be restricted to that single "git" invocation and
should not be left behind to affect later codepath.
Document the rules to avoid future confusion.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-06-19 21:54:00 +04:00
|
|
|
the name of the program) unless it is already set. Whenever
|
|
|
|
the script runs a `git` 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.
|
2007-01-17 12:13:05 +03:00
|
|
|
|
2007-12-29 01:25:39 +03:00
|
|
|
git_editor::
|
|
|
|
runs an editor of user's 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.
|
|
|
|
|
2007-01-17 12:13:05 +03:00
|
|
|
is_bare_repository::
|
|
|
|
outputs `true` or `false` to the standard output stream
|
|
|
|
to indicate if the repository is a bare repository
|
|
|
|
(i.e. without an associated working tree).
|
|
|
|
|
|
|
|
cd_to_toplevel::
|
|
|
|
runs chdir to the toplevel of the working tree.
|
|
|
|
|
|
|
|
require_work_tree::
|
require-work-tree wants more than what its name says
Somebody tried "git pull" from a random place completely outside the work
tree, while exporting GIT_DIR and GIT_WORK_TREE that are set to correct
places, e.g.
GIT_WORK_TREE=$HOME/git.git
GIT_DIR=$GIT_WORK_TREE/.git
export GIT_WORK_TREE GIT_DIR
cd /tmp
git pull
At the beginning of git-pull, we check "require-work-tree" and then
"cd-to-toplevel". I _think_ the original intention when I wrote the
command was "we MUST have a work tree, our $(cwd) might not be at the
top-level directory of it", and no stronger than that. That check is a
very sensible thing to do before doing cd-to-toplevel. We check that the
place we would want to go exists, and then go there.
But the implementation of require_work_tree we have today is quite
different. I don't have energy to dig the history, but currently it says:
test "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = true ||
die "fatal: $0 cannot be used without a working tree."
Which is completely bogus. Even though we may happen to be just outside
of it right now, we may have a working tree that we can cd_to_toplevel
back to.
Add a function "require_work_tree_exists" that implements the check
this function originally intended (this is so that third-party scripts
that rely on the current behaviour do not have to get broken).
For now, update _no_ in-tree scripts, not even "git pull", as nobody on
the list seems to really care about the above corner case workflow that
triggered this. Scripts can be updated after vetting that they do want the
"we want to make sure the place we are going to go actually exists"
semantics.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-05-05 06:11:18 +04:00
|
|
|
checks if the current directory is within the working tree
|
|
|
|
of the repository, and otherwise dies.
|
|
|
|
|
|
|
|
require_work_tree_exists::
|
|
|
|
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.
|
2007-01-17 12:13:05 +03:00
|
|
|
|
2011-12-21 01:42:39 +04:00
|
|
|
require_clean_work_tree <action> [<hint>]::
|
|
|
|
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 `Cannot
|
|
|
|
<action>: <reason>. <hint>`, and dies. Example:
|
|
|
|
+
|
|
|
|
----------------
|
|
|
|
require_clean_work_tree rebase "Please commit or stash them."
|
|
|
|
----------------
|
|
|
|
|
2007-12-29 01:25:39 +03:00
|
|
|
get_author_ident_from_commit::
|
|
|
|
outputs code for use with eval to set the GIT_AUTHOR_NAME,
|
|
|
|
GIT_AUTHOR_EMAIL and GIT_AUTHOR_DATE variables for a given commit.
|
|
|
|
|
mergetools/p4merge: create a base if none available
Originally, with no base, Git gave P4Merge $LOCAL as a dummy base:
p4merge "$LOCAL" "$LOCAL" "$REMOTE" "$MERGED"
Commit 0a0ec7bd changed this to:
p4merge "empty file" "$LOCAL" "$REMOTE" "$MERGED"
to avoid the problem of being unable to save in some circumstances with
similar inputs.
Unfortunately this approach produces much worse results on differing
inputs. P4Merge really regards the blank file as the base, and once you
have just a couple of differences between the two branches you end up
with one a massive full-file conflict. The 3-way diff is not readable,
and you have to invoke "difftool MERGE_HEAD HEAD" manually to get a
useful view.
The original approach appears to have invoked special 2-way merge
behaviour in P4Merge that occurs only if the base filename is "" or
equal to the left input. You get a good visual comparison, and it does
not auto-resolve differences. (Normally if one branch matched the base,
it would autoresolve to the other branch).
But there appears to be no way of getting this 2-way behaviour and being
able to reliably save. Having base==left appears to be triggering other
assumptions. There are tricks the user can use to force the save icon
on, but it's not intuitive.
So we now follow a suggestion given in the original patch's discussion:
generate a virtual base, consisting of the lines common to the two
branches. This is the same as the technique used in resolve and octopus
merges, so we relocate that code to a shared function.
Note that if there are no differences at the same location, this
technique can lead to automatic resolution without conflict, combining
everything from the 2 files. As with the other merges using this
technique, we assume the user will inspect the result before saving.
Signed-off-by: Kevin Bracey <kevin@bracey.fi>
Reviewed-by: David Aguilar <davvid@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-03-13 05:12:21 +04:00
|
|
|
create_virtual_base::
|
|
|
|
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.
|
|
|
|
|
2005-08-23 12:49:47 +04:00
|
|
|
GIT
|
|
|
|
---
|
2008-06-06 11:07:32 +04:00
|
|
|
Part of the linkgit:git[1] suite
|