git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git stash: status from current dir not top dir?

From
Jeff King <peff@peff.net>
Date
Mar 11, 2011, 22:32 UTC
Message-ID
<20110311223232.GA21410@sigill.intra.peff.net>
In-Reply-To
<4D7A8AC9.1030506@gmail.com>
On Fri, Mar 11, 2011 at 09:49:13PM +0100, Piotr Krukowiecki wrote:
> But "git stash apply" shows status from root of git repository.
> This is misleading because you can't copy and paste the paths.

Yeah, I am inclined to call it a bug. git-status will show the status of the whole tree from wherever you are, and people who want full paths will have status.relativePaths turned off, anyway. So I think your proposed semantics are more natural.

> This patch tries to fix git-stash.sh to show status relative to 
> current directory. I can resend the patch with better commit message.

Yes, please. There is lots of nice discussion in your email but none of it in the commit message. :)

Show 21 quoted lines
> diff --git a/git-stash.sh b/git-stash.sh
> index 7561b37..586c12f 100755
> --- a/git-stash.sh
> +++ b/git-stash.sh
> @@ -12,6 +12,7 @@ USAGE="list [<options>]
>  
>  SUBDIRECTORY_OK=Yes
>  OPTIONS_SPEC=
> +START_DIR=`pwd`
>  . git-sh-setup
>  require_work_tree
>  cd_to_toplevel
> @@ -394,7 +395,7 @@ apply_stash () {
>  		then
>  			squelch='>/dev/null 2>&1'
>  		fi
> -		eval "git status $squelch" || :
> +		(cd "$START_DIR" && eval "git status $squelch") || :
>  	else
>  		# Merge conflict; keep the exit status from merge-recursive
>  		status=$?

This fix looks reasonable to me. The other option would be to avoid cd_to_toplevel at the beginning (which I am not sure why we really need in the first place, but presumably some code paths rely on it), but it's probably not worth the risk of introducing new confusing bugs.

-Peff
Previous: Piotr KrukowieckiNext: Piotr Krukowiecki
Message 2 of 8 in “git stash: status from current dir not top dir?”
  1. Piotr KrukowieckiMar 11, 2011
  2. Jeff KingMar 11, 2011
  3. Piotr KrukowieckiMar 12, 2011
  4. Junio C HamanoMar 14, 2011
  5. Piotr KrukowieckiMar 14, 2011
  6. Piotr KrukowieckiMar 17, 2011
  7. Junio C HamanoMar 17, 2011
  8. Piotr KrukowieckiMar 19, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.