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

Re: [PATCH 7/7] rebase: implement --[no-]autostash and rebase.autostash

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 23, 2013, 17:07 UTC
Message-ID
<7vr4i1i3a9.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1366725724-1016-8-git-send-email-artagnon@gmail.com>
Ramkumar Ramachandra <artagnon@gmail.com> writes:
Show 13 quoted lines
> +apply_autostash () {
> +	if test -f "$state_dir/autostash"
> +	then
> +		stash_sha1=$(cat "$state_dir/autostash")
> +		git stash apply $stash_sha1 2>&1 >/dev/null ||
> +		die "
> +$(eval_gettext 'Applying autostash resulted in conflicts.
> +Either fix the conflicts now, or run
> +	git reset --hard
> +and apply the stash on your desired branch:
> +	git stash apply $stash_sha1
> +at any time.')" &&
> +		echo "Applied autostash"

That && looks funny. What does it even mean for die to succeed and give control back to you for a chance to say "Applied"?

	stash apply || die
	echo applied
would be far more logical.
> +	fi
> +	git gc --auto &&
> +	rm -rf "$state_dir"
> +}

This is somewhat worrysome. After getting the "oops, we cannot apply" message, the "$stash_sha1" in the message on the terminal is the ONLY indication of where the (presumably precious) local change the user used to have can be recovered from.

You do not "rm -fr $state_dir" in such a case, so perhaps telling the user the location of that "autostash" file may help her somewhat.

For that matter, wouldn't it be a lot simpler to put the autostash ref somewhere in refs/ hierarchy, instead of storing an object name of the stash that keeps (presumably precious) local change of the user in a plain-text file that is not at all known by "gc"?

Show 50 quoted lines
> +
>  run_specific_rebase () {
>  	if [ "$interactive_rebase" = implied ]; then
>  		GIT_EDITOR=:
> @@ -153,8 +173,7 @@ run_specific_rebase () {
>  	ret=$?
>  	if test $ret = 0
>  	then
> -		git gc --auto &&
> -		rm -rf "$state_dir"
> +		apply_autostash
>  	fi
>  	exit $ret
>  }
> @@ -248,6 +267,9 @@ do
>  	--stat)
>  		diffstat=t
>  		;;
> +	--autostash)
> +		autostash=true
> +		;;
>  	-v)
>  		verbose=t
>  		diffstat=t
> @@ -348,7 +370,7 @@ abort)
>  		;;
>  	esac
>  	output git reset --hard $orig_head
> -	rm -r "$state_dir"
> +	apply_autostash
>  	exit
>  	;;
>  edit-todo)
> @@ -487,6 +509,16 @@ case "$#" in
>  	;;
>  esac
>  
> +if test "$autostash" = true && ! require_clean_work_tree --quiet
> +then
> +	stash_sha1=$(git stash create) || die "$(gettext "Cannot autostash")" &&
> +	mkdir -p "$state_dir" &&
> +	echo $stash_sha1 >"$state_dir/autostash" &&
> +	stash_abbrev=$(git rev-parse --short $stash_sha1) &&
> +	echo "$(gettext "Created autostash: $stash_abbrev")" &&
> +	git reset --hard
> +fi
> +
>  require_clean_work_tree "rebase" "$(gettext "Please commit or stash them.")"
>  
>  # Now we are rebasing commits $upstream..$orig_head (or with --root,
Previous: Ramkumar RamachandraNext: Junio C Hamano
Message 23 of 28 in “Introduce rebase.autostash”
  1. 0/7 Introduce rebase.autostashRamkumar Ramachandra, Apr 23, 2013
  2. 1/7 am: suppress error output from a conditionalRamkumar Ramachandra, Apr 23, 2013
  3. Martin von ZweigbergkApr 23, 2013
  4. Junio C HamanoApr 23, 2013
  5. Ramkumar RamachandraApr 23, 2013
  6. Junio C HamanoApr 23, 2013
  7. Ramkumar RamachandraApr 23, 2013
  8. 2/7 rebase -i: don't error out if $state_dir already existsRamkumar Ramachandra, Apr 23, 2013
  9. Martin von ZweigbergkApr 23, 2013
  10. Junio C HamanoApr 23, 2013
  11. Ramkumar RamachandraApr 23, 2013
  12. 3/7 am: tighten a conditional that checks for $dotestRamkumar Ramachandra, Apr 23, 2013
  13. Junio C HamanoApr 23, 2013
  14. 4/7 am: don't do housekeeping when rebasingRamkumar Ramachandra, Apr 23, 2013
  15. Junio C HamanoApr 23, 2013
  16. 5/7 rebase -i: return control to the caller, for housekeepingRamkumar Ramachandra, Apr 23, 2013
  17. Martin von ZweigbergkApr 23, 2013
  18. Ramkumar RamachandraApr 25, 2013
  19. Junio C HamanoApr 23, 2013
  20. 6/7 sh-setup: introduce require_clean_work_tree --quietRamkumar Ramachandra, Apr 23, 2013
  21. Junio C HamanoApr 23, 2013
  22. 7/7 rebase: implement --[no-]autostash and rebase.autostashRamkumar Ramachandra, Apr 23, 2013
  23. Junio C HamanoApr 23, 2013
  24. Junio C HamanoApr 23, 2013
  25. Ramkumar RamachandraApr 23, 2013
  26. Phil HordApr 23, 2013
  27. Ramkumar RamachandraApr 24, 2013
  28. Matthieu MoyApr 24, 2013

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.