all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alexander Kuleshov <kuleshovmail@gmail.com>
To: 24046@debbugs.gnu.org
Subject: bug#24046: [PATCH] vc-git: prevent execution of git stash in error cases
Date: Thu, 21 Jul 2016 18:46:18 +0600	[thread overview]
Message-ID: <CANCZXo7aRYjkqB19H9Qr8MWv6RAJQRfqU7UwX8Oy8DUYdQf1HA@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 173 bytes --]

Here is simple patch which adds two additional checks to the vc-git-stash-show
function to check that correct stash name is passed and actually repo
has stashes.

Thank you

[-- Attachment #2: 0001-vc-git-prevent-execution-of-git-stash-in-error-cases.patch --]
[-- Type: text/x-patch, Size: 1408 bytes --]

From f9fc64560dcf892826eddca535c0c869d2922041 Mon Sep 17 00:00:00 2001
From: Alexander Kuleshov <kuleshovmail@gmail.com>
Date: Thu, 21 Jul 2016 18:42:48 +0600
Subject: [PATCH] vc-git: prevent execution of git stash in error cases

* lisp/vc/vc-git.el (vc-git-stash-show): prevent execution if stash
name is empty or a repo hasn't stashes.
---
 lisp/vc/vc-git.el | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index e6fe019..940738d 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -1348,12 +1348,16 @@ vc-git-stash
 (defun vc-git-stash-show (name)
   "Show the contents of stash NAME."
   (interactive "sStash name: ")
-  (vc-setup-buffer "*vc-git-stash*")
-  (vc-git-command "*vc-git-stash*" 'async nil "stash" "show" "-p" name)
-  (set-buffer "*vc-git-stash*")
-  (diff-mode)
-  (setq buffer-read-only t)
-  (pop-to-buffer (current-buffer)))
+  (if (string= name "")
+      (error "stash name can't be empty string."))
+  (if (eq (vc-git-stash-list) nil)
+      (error "There are no stashes.")
+    (vc-setup-buffer "*vc-git-stash*")
+    (vc-git-command "*vc-git-stash*" 'async nil "stash" "show" "-p" name)
+    (set-buffer "*vc-git-stash*")
+    (diff-mode)
+    (setq buffer-read-only t)
+    (pop-to-buffer (current-buffer))))
 
 (defun vc-git-stash-apply (name)
   "Apply stash NAME."
-- 
2.8.0.rc3.1353.gea9bdc0


             reply	other threads:[~2016-07-21 12:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-21 12:46 Alexander Kuleshov [this message]
2017-06-04  3:00 ` bug#24046: [PATCH] vc-git: prevent execution of git stash in error cases npostavs
2019-06-25 12:03   ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CANCZXo7aRYjkqB19H9Qr8MWv6RAJQRfqU7UwX8Oy8DUYdQf1HA@mail.gmail.com \
    --to=kuleshovmail@gmail.com \
    --cc=24046@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.