# [PATCH 1/2] git-sh-setup: make require_clean_work_tree part of the interface

10 messages from 2011-12-20 to 2011-12-20. Participants: Thomas Rast, Junio C Hamano, Ævar Arnfjörð Bjarmason.
Thread: https://gitlist.dev/t/29211

## Thomas Rast, 2011-12-20 11:09

Subject: [PATCH 1/2] git-sh-setup: make require_clean_work_tree part of the interface
Message-ID: <c53feb0de8006c205fd26c2c07dcd78bd86b6c24.1324378986.git.trast@student.ethz.ch>
URL: https://gitlist.dev/e/c53feb0de8006c205fd26c2c07dcd78bd86b6c24.1324378986.git.trast%40student.ethz.ch

```
92c62a3 (Porcelain scripts: Rewrite cryptic "needs update" error
message, 2010-10-19) refactored git's own checking to a function in
git-sh-setup.  This is a very useful thing for script writers, so
document it.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---

Noticed while helping ribasushi on IRC.

 Documentation/git-sh-setup.txt |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/Documentation/git-sh-setup.txt b/Documentation/git-sh-setup.txt
index a2f346c..bbfefca 100644
--- a/Documentation/git-sh-setup.txt
+++ b/Documentation/git-sh-setup.txt
@@ -68,6 +68,15 @@ require_work_tree_exists::
 	cd_to_toplevel, which is impossible to do if there is no
 	working tree.
 
+require_clean_work_tree <action> [<hint>]::
+	checks if the working tree associated with the repository is
+	clean.  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."
+----------------
+
 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.
-- 
1.7.8.484.gdad4270

```

## Thomas Rast, 2011-12-20 11:09

Subject: [PATCH 2/2] Documentation: make git-sh-setup docs less scary
Message-ID: <c8867738c264a76f9662080b64e00615ec1aa28f.1324378986.git.trast@student.ethz.ch>
URL: https://gitlist.dev/e/c8867738c264a76f9662080b64e00615ec1aa28f.1324378986.git.trast%40student.ethz.ch
In-Reply-To: <c53feb0de8006c205fd26c2c07dcd78bd86b6c24.1324378986.git.trast@student.ethz.ch>

```
At least one IRC user was scared away by the introductory "This is not
a command the end user would want to run.  Ever." to the point of not
reading on.

Reword it in a more matter-of-fact way that does not intentionally try
to scare the user away.  Since 46bac90 (Do not install shell libraries
executable, 2010-01-31) it is not executable anyway, so the end user
would get

  $ git sh-setup
  fatal: cannot exec 'git-sh-setup': Permission denied

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
 Documentation/git-sh-setup.txt |   11 ++++-------
 1 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/Documentation/git-sh-setup.txt b/Documentation/git-sh-setup.txt
index bbfefca..612fb50 100644
--- a/Documentation/git-sh-setup.txt
+++ b/Documentation/git-sh-setup.txt
@@ -13,13 +13,10 @@ SYNOPSIS
 DESCRIPTION
 -----------
 
-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.
-
-The 'git sh-setup' scriptlet is designed to be sourced (using
-`.`) by other shell scripts to set up some variables pointing at
-the normal git directories and a few helper shell functions.
+This command cannot be run by the end user.  Shell scripts can
+source it (using `.` as indicated above) to set up some variables
+pointing at the normal git directories and a few helper shell
+functions.
 
 Before sourcing it, your script should set up a few variables;
 `USAGE` (and `LONG_USAGE`, if any) is used to define message
-- 
1.7.8.484.gdad4270

```

## Junio C Hamano, 2011-12-20 19:20

Subject: Re: [PATCH 2/2] Documentation: make git-sh-setup docs less scary
Message-ID: <7v1urzkq2i.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v1urzkq2i.fsf%40alter.siamese.dyndns.org
In-Reply-To: <c8867738c264a76f9662080b64e00615ec1aa28f.1324378986.git.trast@student.ethz.ch>

```
Thomas Rast <trast@student.ethz.ch> writes:

> At least one IRC user was scared away by the introductory "This is not
> a command the end user would want to run.  Ever." to the point of not
> reading on.

You would need to say what that IRC user needed to find out. Depending on
that, letting the user know that there is no point reading on early and
not waste his or her time may be a good thing. That was what the paragraph
was designed for. IOW, it is not to "scare" away, but to allow the users
to decide if they are intended audiences.

The reworded version does avoid sounding scary, but loses the "this
document is for people who want to write new or understand existing
Porcelain scripts", which is a documentation regression.

> Reword it in a more matter-of-fact way that does not intentionally try
> to scare the user away.  Since 46bac90 (Do not install shell libraries
> executable, 2010-01-31) it is not executable anyway, so the end user
> would get
>
>   $ git sh-setup
>   fatal: cannot exec 'git-sh-setup': Permission denied
>
> Signed-off-by: Thomas Rast <trast@student.ethz.ch>
> ---
>  Documentation/git-sh-setup.txt |   11 ++++-------
>  1 files changed, 4 insertions(+), 7 deletions(-)
>
> diff --git a/Documentation/git-sh-setup.txt b/Documentation/git-sh-setup.txt
> index bbfefca..612fb50 100644
> --- a/Documentation/git-sh-setup.txt
> +++ b/Documentation/git-sh-setup.txt
> @@ -13,13 +13,10 @@ SYNOPSIS
>  DESCRIPTION
>  -----------
>  
> -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.
> -
> -The 'git sh-setup' scriptlet is designed to be sourced (using
> -`.`) by other shell scripts to set up some variables pointing at
> -the normal git directories and a few helper shell functions.
> +This command cannot be run by the end user.  Shell scripts can
> +source it (using `.` as indicated above) to set up some variables
> +pointing at the normal git directories and a few helper shell
> +functions.
>  
>  Before sourcing it, your script should set up a few variables;
>  `USAGE` (and `LONG_USAGE`, if any) is used to define message

```

## Junio C Hamano, 2011-12-20 19:25

Subject: Re: [PATCH 1/2] git-sh-setup: make require_clean_work_tree part of the interface
Message-ID: <7vwr9rjbaq.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vwr9rjbaq.fsf%40alter.siamese.dyndns.org
In-Reply-To: <c53feb0de8006c205fd26c2c07dcd78bd86b6c24.1324378986.git.trast@student.ethz.ch>

```
Thomas Rast <trast@student.ethz.ch> writes:

> 92c62a3 (Porcelain scripts: Rewrite cryptic "needs update" error
> message, 2010-10-19) refactored git's own checking to a function in
> git-sh-setup.  This is a very useful thing for script writers, so
> document it.

Can we avoid explaining "clean" with the same word "clean", which adds no
new information? IOW, what does "clean" mean in the context of this helper
shell function? No untracked cruft? No un-added changes? What are the kind
of dirtiness being checked?

> +require_clean_work_tree <action> [<hint>]::
> +	checks if the working tree associated with the repository is
> +	clean.  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."
> +----------------
> +
>  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.

```

## Ævar Arnfjörð Bjarmason, 2011-12-20 19:45

Subject: Re: [PATCH 2/2] Documentation: make git-sh-setup docs less scary
Message-ID: <CACBZZX5BSfh8S9Kf1Wbi+NPEKpxJNXU8TD8-hkC2o1Mi91Or6A@mail.gmail.com>
URL: https://gitlist.dev/e/CACBZZX5BSfh8S9Kf1Wbi%2BNPEKpxJNXU8TD8-hkC2o1Mi91Or6A%40mail.gmail.com
In-Reply-To: <c8867738c264a76f9662080b64e00615ec1aa28f.1324378986.git.trast@student.ethz.ch>

```
On Tue, Dec 20, 2011 at 12:09, Thomas Rast <trast@student.ethz.ch> wrote:
> At least one IRC user was scared away by the introductory "This is not
> a command the end user would want to run.  Ever." to the point of not
> reading on.

Arguably that's the point isn't it? To not have people who aren't
maintaining Git itself waste time on reading it.

Anyway I don't care how it's worded, but if you're going to patch it
you should probably do these too for consistency, since they
copy/paste this same blurb:

    $ git --no-pager grep -l 'This is not a command the end user would
want to run.  Ever.'
    Documentation/git-mergetool--lib.txt
    Documentation/git-sh-i18n--envsubst.txt
    Documentation/git-sh-i18n.txt
    Documentation/git-sh-setup.txt

And actually we might want to do all those with some asciidoc include
mechanism.

```

## Thomas Rast, 2011-12-20 20:27

Subject: Re: [PATCH 2/2] Documentation: make git-sh-setup docs less scary
Message-ID: <87bor3ounz.fsf@thomas.inf.ethz.ch>
URL: https://gitlist.dev/e/87bor3ounz.fsf%40thomas.inf.ethz.ch
In-Reply-To: <CACBZZX5BSfh8S9Kf1Wbi+NPEKpxJNXU8TD8-hkC2o1Mi91Or6A@mail.gmail.com>

```
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
> On Tue, Dec 20, 2011 at 12:09, Thomas Rast <trast@student.ethz.ch> wrote:
>> At least one IRC user was scared away by the introductory "This is not
>> a command the end user would want to run.  Ever." to the point of not
>> reading on.
>
> Arguably that's the point isn't it? To not have people who aren't
> maintaining Git itself waste time on reading it.

Junio C Hamano writes:
> You would need to say what that IRC user needed to find out. Depending on
> that, letting the user know that there is no point reading on early and
> not waste his or her time may be a good thing. That was what the paragraph
> was designed for. IOW, it is not to "scare" away, but to allow the users
> to decide if they are intended audiences.

Well, the original question was [*]

  <ribasushi> how do I write a batch-test (goes in a script, exit value matters only) to test if the current workdir is clean?
  <ribasushi> i.e. nothing staged/unstaged to commit
  <shruggar> last I looked, there was no "all in one" method :/
  <shruggar> git diff -q && git diff —cached -q, perhaps
  <charon> ribasushi: . "$(git --exec-path)/git-sh-setup" ; require_clean_worktree
  <shruggar> but I think that's ignoring something
  <ribasushi> lack of output of `git status -s` seems to be what I want
  <ribasushi> hmmm
  <ribasushi> charon: git-gh-setup's manpage does not seem to list what you gave me
  <ribasushi> and the manpage says that I should not be touching it...

Leaving aside my worktree vs. work_tree mistake, he concluded that he
should not be using it even though he is a script writer.

Regardless, I don't really care enough about this one; let's just do the
first patch (v2 upcoming) so that we have documentation to point people
at.


[*] http://colabti.org/irclogger/irclogger_log/git?date=2011-12-20#l1284

-- 
Thomas Rast
trast@{inf,student}.ethz.ch

```

## Thomas Rast, 2011-12-20 20:29

Subject: [PATCH v2] git-sh-setup: make require_clean_work_tree part of the interface
Message-ID: <23d761193dcf25f36206adc3d392e8578c566cd7.1324412815.git.trast@student.ethz.ch>
URL: https://gitlist.dev/e/23d761193dcf25f36206adc3d392e8578c566cd7.1324412815.git.trast%40student.ethz.ch
In-Reply-To: <7vwr9rjbaq.fsf@alter.siamese.dyndns.org>

```
92c62a3 (Porcelain scripts: Rewrite cryptic "needs update" error
message, 2010-10-19) refactored git's own checking to a function in
git-sh-setup.  This is a very useful thing for script writers, so
document it.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
 Documentation/git-sh-setup.txt |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/Documentation/git-sh-setup.txt b/Documentation/git-sh-setup.txt
index a2f346c..9a0e574 100644
--- a/Documentation/git-sh-setup.txt
+++ b/Documentation/git-sh-setup.txt
@@ -68,6 +68,16 @@ require_work_tree_exists::
 	cd_to_toplevel, which is impossible to do if there is no
 	working tree.
 
+require_clean_work_tree <action> [<hint>]::
+	checks that the working tree associated with the repository
+	has 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."
+----------------
+
 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.
-- 
1.7.8.484.gdad4270

```

## Junio C Hamano, 2011-12-20 20:52

Subject: Re: [PATCH v2] git-sh-setup: make require_clean_work_tree part of the interface
Message-ID: <7vd3bjj78h.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vd3bjj78h.fsf%40alter.siamese.dyndns.org
In-Reply-To: <23d761193dcf25f36206adc3d392e8578c566cd7.1324412815.git.trast@student.ethz.ch>

```
Thomas Rast <trast@student.ethz.ch> writes:

> 92c62a3 (Porcelain scripts: Rewrite cryptic "needs update" error
> message, 2010-10-19) refactored git's own checking to a function in
> git-sh-setup.  This is a very useful thing for script writers, so
> document it.
>
> Signed-off-by: Thomas Rast <trast@student.ethz.ch>
> ---
>  Documentation/git-sh-setup.txt |   10 ++++++++++
>  1 files changed, 10 insertions(+), 0 deletions(-)
>
> diff --git a/Documentation/git-sh-setup.txt b/Documentation/git-sh-setup.txt
> index a2f346c..9a0e574 100644
> --- a/Documentation/git-sh-setup.txt
> +++ b/Documentation/git-sh-setup.txt
> @@ -68,6 +68,16 @@ require_work_tree_exists::
>  	cd_to_toplevel, which is impossible to do if there is no
>  	working tree.
>  
> +require_clean_work_tree <action> [<hint>]::
> +	checks that the working tree associated with the repository
> +	has no uncommitted changes to tracked files.  Otherwise it
> +	emits an error message of the form `Cannot <action>:
> +	<reason>. <hint>`, and dies.  Example:

Doesn't it also enforce cleanliness on the index, not just the working tree?

> ++
> +----------------
> +require_clean_work_tree rebase "Please commit or stash them."
> +----------------
> +
>  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.

```

## Thomas Rast, 2011-12-20 21:42

Subject: [PATCH v3] git-sh-setup: make require_clean_work_tree part of the interface
Message-ID: <b121d918166dea3b578b075ac6b794967c4bdcbe.1324415678.git.trast@student.ethz.ch>
URL: https://gitlist.dev/e/b121d918166dea3b578b075ac6b794967c4bdcbe.1324415678.git.trast%40student.ethz.ch
In-Reply-To: <7vd3bjj78h.fsf@alter.siamese.dyndns.org>

```
92c62a3 (Porcelain scripts: Rewrite cryptic "needs update" error
message, 2010-10-19) refactored git's own checking to a function in
git-sh-setup.  This is a very useful thing for script writers, so
document it.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---

Junio C Hamano writes:

> Thomas Rast <trast@student.ethz.ch> writes:
> 
> > +require_clean_work_tree <action> [<hint>]::
> > +	checks that the working tree associated with the repository
> > +	has no uncommitted changes to tracked files.  Otherwise it
> > +	emits an error message of the form `Cannot <action>:
> > +	<reason>. <hint>`, and dies.  Example:
> 
> Doesn't it also enforce cleanliness on the index, not just the working tree?

Of course.  Here's the "and index" update.

BTW neither gitglossary(7) nor git-cherry-pick(1) get this right.


 Documentation/git-sh-setup.txt |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/Documentation/git-sh-setup.txt b/Documentation/git-sh-setup.txt
index a2f346c..eb08ba6 100644
--- a/Documentation/git-sh-setup.txt
+++ b/Documentation/git-sh-setup.txt
@@ -68,6 +68,16 @@ require_work_tree_exists::
 	cd_to_toplevel, which is impossible to do if there is no
 	working tree.
 
+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."
+----------------
+
 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.
-- 
1.7.8.484.gdad4270

```

## Junio C Hamano, 2011-12-20 22:05

Subject: Re: [PATCH v3] git-sh-setup: make require_clean_work_tree part of the interface
Message-ID: <7vzkemj3ul.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vzkemj3ul.fsf%40alter.siamese.dyndns.org
In-Reply-To: <b121d918166dea3b578b075ac6b794967c4bdcbe.1324415678.git.trast@student.ethz.ch>

```
Thanks, will queue.

```
