branch: master
commit 2393f3a7d17eb3ebe674127821925c60547d1bcb
Author: Tino Calancha
Commit: Tino Calancha
Avoid side-effects in a couple of functions
Fixes a long-standing issue.
See Emacs Prince analysis of the Bug and John Wick's fix here:
https://youtu.be/nVLeQoBeNL8
* packages/gited/gited.el (gited--handle-new-or-delete-files)
(gited-add-patched-files):
Avoid unsafe `nconc' usage, i.e. quoted constant list as a non-last
argument.
* packages/gited/gited-tests.el (gited-test-add-patch-bug):
Add test. Clean previous tests by adding helper some functions/variables.
---
packages/gited/gited-tests.el | 216 +++---
packages/gited/gited.el | 10 +-
2 files changed, 146 insertions(+), 80 deletions(-)
diff --git a/packages/gited/gited-tests.el b/packages/gited/gited-tests.el
index 89c549c..e72e32e 100644
--- a/packages/gited/gited-tests.el
+++ b/packages/gited/gited-tests.el
@@ -1,6 +1,6 @@
;;; gited-tests.el --- Tests for gited.el -*- lexical-binding: t; -*-
-;; Copyright (C) 2017 Free Software Foundation, Inc.
+;; Copyright (C) 2017-2019 Free Software Foundation, Inc.
;; Author: Tino Calancha ,
;; Keywords:
@@ -30,77 +30,117 @@
(require 'gited)
(eval-when-compile (require 'cl-lib))
+;; Settings for a test repository.
+(defvar gited-user-name "John Doe")
+(defvar gited-user-email "john@example.com")
+(defvar gited-initial-commit-msg "Initialize repository.")
+(defvar gited-initial-filename "foo")
+(defvar gited-initial-file-content "Test file")
+
+(defvar gited-remote-repo "https://github.com/calancha/foo";)
+(defvar gited-remote-repo-branch "fail-say-foo-test")
+(defvar gited-remote-repo-file "do_not_delete.el")
+
+(defun gited-create-new-repo (dir)
+ "Create a new repository at DIR and return its gited buffer."
+ (let ((inhibit-message t))
+(write-region gited-initial-file-content
+ nil
+ (expand-file-name gited-initial-filename dir))
+(dired dir)
+(gited-git-command '("init"))
+(gited-git-command `("config" "user.email" ,gited-user-email))
+(gited-git-command `("config" "user.name" ,gited-user-name))
+(gited-git-command `("add" ,gited-initial-filename))
+(gited-git-command `("commit" "-m" ,gited-initial-commit-msg))
+(gited-list-branches "local")
+gited-buffer))
+
+(defmacro with-gited-repo (dir &rest body)
+ "Create a new Git repository at DIR and evaluate BODY.
+The repository consists of just one file with content
+`gited-initial-file-content'.
+The forms in BODY are evaluated with DIR as `default-directory'."
+ (declare (indent 1) (debug (form body)))
+ `(let* ((gited-expert t)
+ (inhibit-message t))
+ (unwind-protect
+ (progn
+ (gited-create-new-repo ,dir)
+ ,@body)
+ (delete-directory ,dir 'recursive
+
+(defmacro with-specified-completion-branch (branch &rest body)
+ "Fix branch completions to BRANCH and evaluate BODY.
+This macro uses `cl-letf' to temporary fix the completions.
+Return the last evaled BODY form."
+ (declare (indent 1) (debug (form body)))
+ `(cl-letf (((symbol-function 'completing-read)
+ (lambda (&rest _) ,branch)))
+ ,@body))
+
(ert-deftest gited-test1 ()
(skip-unless (executable-find vc-git-program))
- (let* ((dir (make-temp-file "gited" 'dir))
- (file (expand-file-name "foo" dir))
- (gited-expert t)
- (inhibit-message t)
- dired-buf)
-(unwind-protect
-(let ((str "Initialize repository."))
- (write-region "Test file" nil file)
- (setq dired-buf (dired dir))
- (gited-git-command '("init"))
- (gited-git-command '("config" "user.email"
"john@example.com"))
- (gited-git-command '("config" "user.name" "John Doe"))
- (gited-git-command '("add" "foo"))
- (gited-git-command `("commit" "-m" ,str))
- (gited-list-branches "local")
- (should (gited-dir-under-Git-control-p))
- (should (gited-buffer-p))
- (should (equal str (gited--last-commit-title)))
- (should (equal "master" (gited-current-branch)))
- (should-not (gited-branch-exists-p "foo"))
- (gited-copy-branch "master" "foo")
- (should (gited-branch-exists-p "foo"))
- (gited-toggle-marks)
- (should (= 2 (gited-number-marked)))
+ (let ((dir (make-temp-file "gited" 'dir)))
+(with-gited-repo dir
+ (progn
+(should (gited-dir-under-Git-control-p))
+(should (gited-buffer-p))
+(should (equal gited-initial-commit-msg (gited--last-commit-title)))
+(should (equal "master" (gited-current-branch)))
+;; Only master branch do exist
+(should-not (gited-branch-exists-p gited-initial-filename))
+;; Create a new branch (copy of master)
+(gited-copy-branch "master" gited-initial-filename)
+(should (gite