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

Re: [PATCH] rev-parse --show-prefix: add in trailing newline

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 9, 2012, 19:07 UTC
Message-ID
<7v1unwwwov.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1333978076-29968-1-git-send-email-rosslagerwall@gmail.com>
Ross Lagerwall <rosslagerwall@gmail.com> writes:
Show 13 quoted lines
> diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh
> index e661147..8f36aa9 100755
> --- a/t/t1501-worktree.sh
> +++ b/t/t1501-worktree.sh
> @@ -68,7 +68,7 @@ test_expect_success 'inside work tree' '
>  	)
>  '
>  
> -test_expect_failure 'empty prefix is actually written out' '
> +test_expect_success 'empty prefix is actually written out' '
>  	echo >expected &&
>  	(
>  		cd work &&

fc68875 (t1501 (rev-parse): clarify, 2010-07-24) says it is a "possible bug", but I do not think the expectation of the new test added by that commit is entirely correct.

Because the assignment will strip the trailing LF away adding an extra newline at the end would not matter in practice in many scripts, e.g.

	a=$(git rev-parse --show-prefix)
        if test -z "$a"
        then
		echo we are at toplevel
	fi
or
	pfx=$(git rev-parse --show-prefix)
	cd_to_toplevel
	for arg
        do
		case "$arg" in
                /*)
                       	user refers to "$arg" that is a full path ;;
		*)
			user refers to "$pfx$arg" ;;
		esac
	done
But it will break existing scripts if they expect the following to work:
	file="$(git rev-parse --show-prefix)/$1"
        cd_to_toplevel
        test -f "$file"
Previous: Ross LagerwallNext: Ross Lagerwall
Message 2 of 9 in “rev-parse --show-prefix: add in trailing newline”
  1. rev-parse --show-prefix: add in trailing newlineRoss Lagerwall, Apr 9, 2012
  2. Junio C HamanoApr 9, 2012
  3. Ross LagerwallApr 10, 2012
  4. Jonathan NiederApr 10, 2012
  5. Andreas SchwabApr 10, 2012
  6. Junio C HamanoApr 10, 2012
  7. Jonathan NiederApr 10, 2012
  8. Junio C HamanoApr 10, 2012
  9. Nguyen Thai Ngoc DuyApr 10, 2012

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.