threads / patch / 29211

patch, 2 partsgit-sh-setup: make require_clean_work_tree part of the interface

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

## tl;dr

10 messages between Dec 20, 2011 and Dec 20, 2011. Diffs are folded; open one to read it.

replies: 9people: 3as markdown or json

Thomas Rast· Dec 20, 2011, 11:09 UTC · lore

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(-)
Show changes to Documentation/git-sh-setup.txt +9 −0
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· Dec 20, 2011, 11:09 UTC · re: Thomas Rast · lore

[PATCH 2/2] Documentation: make git-sh-setup docs less scary

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(-)
Show changes to Documentation/git-sh-setup.txt +4 −7
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· Dec 20, 2011, 19:20 UTC · re: Thomas Rast · lore

Re: [PATCH 2/2] Documentation: make git-sh-setup docs less scary

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.

Show 35 quoted lines
> 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
Ævar Arnfjörð Bjarmason· Dec 20, 2011, 19:45 UTC · re: Thomas Rast · lore

Re: [PATCH 2/2] Documentation: make git-sh-setup docs less scary

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· Dec 20, 2011, 20:27 UTC · re: Ævar Arnfjörð Bjarmason · lore

Re: [PATCH 2/2] Documentation: make git-sh-setup docs less scary

Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
Show 7 quoted lines
> 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:
Show 5 quoted lines
> 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
Junio C Hamano· Dec 20, 2011, 19:25 UTC · re: Thomas Rast · lore

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

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?

Show 12 quoted lines
> +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.
Thomas Rast· Dec 20, 2011, 20:29 UTC · re: Junio C Hamano · lore

[PATCH v2] git-sh-setup: make require_clean_work_tree part of the interface

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(-)
Show changes to Documentation/git-sh-setup.txt +10 −0
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· Dec 20, 2011, 20:52 UTC · re: Thomas Rast · lore

Re: [PATCH v2] git-sh-setup: make require_clean_work_tree part of the interface

Thomas Rast <trast@student.ethz.ch> writes:
Show 23 quoted lines
> 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?
Show 8 quoted lines
> ++
> +----------------
> +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· Dec 20, 2011, 21:42 UTC · re: Junio C Hamano · lore

[PATCH v3] git-sh-setup: make require_clean_work_tree part of the interface

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:
Show 9 quoted lines
> 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(-)
Show changes to Documentation/git-sh-setup.txt +10 −0
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

← back to recent threads