Skip to content

Commit

Permalink
Fix statshing
Browse files Browse the repository at this point in the history
  • Loading branch information
storax committed May 15, 2016
1 parent 8dc76b3 commit 2af4a79
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test: export EMACI_TESTGITDIR2=$(shell mktemp -d)
test: elpa
echo created git temp dir $$EMACI_TESTGITDIR; \
./create_test_git_repo.sh
$(CASK) exec ert-runner; \
$(CASK) exec ert-runner --reporter ert; \
rm -rf $$EMACI_TESTGITDIR; \
rm -rf $$EMACI_TESTGITDIR2; \
rm -rf $$EMACI_SAVEDIR
Expand Down
2 changes: 0 additions & 2 deletions create_test_git_repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@ git add file3.txt
git commit -m "commit 2"
rm file3.txt
git stash save stash1
git stash list
git stash show 'stash@{0}'
git checkout master
10 changes: 5 additions & 5 deletions emaci.el
Original file line number Diff line number Diff line change
Expand Up @@ -263,20 +263,20 @@ Calls `emaci//job-finished'."

(defun emaci//switch-to-branch (branch dir)
"Switch to BRANCH of repo in DIR."
(let ((default-directory default-directory))
(let ((default-directory dir))
(when (vc-git-responsible-p default-directory)
(vc-git-checkout nil nil branch))))

(defun emaci//apply-stashes (stashes dir)
"Apply STASHES to repo in DIR."
(let ((default-directory default-directory))
(let ((default-directory dir))
(when (vc-git-responsible-p default-directory)
(dolist (stash stashes)
(vc-git-stash-apply stash)))))

(defun emaci//revert-stashes (stashes dir)
"Reverse apply stashes to repo in DIR."
(let ((default-directory default-directory))
(let ((default-directory dir))
(when (vc-git-responsible-p default-directory)
(dolist (stash (reverse stashes))
(shell-command (format "git stash show -p %s | git apply -R" stash))))))
Expand All @@ -286,8 +286,8 @@ Calls `emaci//job-finished'."
Checkout the branch it was one before the job got executed.
Revert all stashes that were applied by JOB."
(let ((dir (emaci-job-dir job)))
(emaci//switch-to-branch (emaci-job-oldref job) dir)
(emaci//revert-stashes (emaci-job-stashes job) dir)))
(emaci//revert-stashes (emaci-job-stashes job) dir)
(emaci//switch-to-branch (emaci-job-oldref job) dir)))

(defun emaci//git-apply (job)
"Switch to ref stored in JOB and apply the stashes."
Expand Down
12 changes: 6 additions & 6 deletions test/emaci-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ BODY is the actual test."
(should-not (emaci//branches emaci-test-empty-repo)))

(ert-deftest switch-branch ()
(emaci//switch-to-branch "branch1" emaci-test-repo)
(emaci//switch-to-branch "branch1" emaci-test-repo)
(let ((branch (car (emaci//branches emaci-test-repo))))
(emaci//switch-to-branch "master" emaci-test-repo)
(should (equal branch "branch1"))))
Expand Down Expand Up @@ -787,17 +787,17 @@ BODY is the actual test."
(should (equal (emaci//current-commit emaci-test-repo) "branch1")))

(defun assert-stash-before-execute ()
(should-not (file-exists-p (concat emaci-test-repo "file4.txt")))
(assert-job
(cadr (assoc "*default*" emaci-history))
"*default*" 1 'finished "finished\n" 0 "master" nil emaci-stashes
"*default*" 1 'finished "finished\n" 0 "master" "branch1" emaci-stashes
"*default*: Build #1" emaci-test-repo "cat file3.txt || exit 0" nil nil)
(should (equal (emaci//current-commit emaci-test-repo) "master")))
(should (equal (emaci//current-commit emaci-test-repo) "master"))
(should-not (file-exists-p (concat emaci-test-repo "file3.txt"))))

(ert-deftest-async
stash-apply (assert-stash-before-execute)
(should (file-exists-p (concat emaci-test-repo "file3.txt")))
(emaci//schedule nil emaci-test-repo "cat file3.txt || exit 0" nil emaci-stashes)
(should-not (file-exists-p (concat emaci-test-repo "file3.txt")))
(emaci//schedule nil emaci-test-repo "cat file3.txt || exit 0" "branch1" emaci-stashes)
(should-not (file-exists-p (concat emaci-test-repo "file3.txt"))))

;;; test-emaci.el ends here

0 comments on commit 2af4a79

Please sign in to comment.