emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 6ec6ff0: gited-do-sync-with-trunk: New command


From: Tino Calancha
Subject: [elpa] master 6ec6ff0: gited-do-sync-with-trunk: New command
Date: Sat, 1 Jul 2017 00:25:54 -0400 (EDT)

branch: master
commit 6ec6ff09d5c52fdb6cc98eea265b5e6d3db8787f
Author: Tino Calancha <address@hidden>
Commit: Tino Calancha <address@hidden>

    gited-do-sync-with-trunk: New command
    
    * gited.el (gited-do-sync-with-trunk): New command.  Bind it to 'T'.
    (gited--sync-with-trunk-target-name): New defun extracted from
    `gited-sync-with-trunk'.
    (gited--sync-with-trunk-target-name): Use it.
    (gited-sync-with-trunk): Idem.  Signal error if BRANCH-TARGET already exits.
    Update docstring.
---
 packages/gited/gited.el | 40 ++++++++++++++++++++++++++++++----------
 1 file changed, 30 insertions(+), 10 deletions(-)

diff --git a/packages/gited/gited.el b/packages/gited/gited.el
index 01c7a96..8f0bcf4 100644
--- a/packages/gited/gited.el
+++ b/packages/gited/gited.el
@@ -10,9 +10,9 @@
 ;; Compatibility: GNU Emacs: 24.4
 ;; Version: 0.2.5
 ;; Package-Requires: ((emacs "24.4") (cl-lib "0.5"))
-;; Last-Updated: Sat Jul 01 13:19:13 JST 2017
+;; Last-Updated: Sat Jul 01 13:24:22 JST 2017
 ;;           By: calancha
-;;     Update #: 669
+;;     Update #: 670
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;
@@ -2135,21 +2135,26 @@ Optional arg WRITE-FILE if non-nil, then write the 
patches to disk."
        (string< (buffer-name x) (buffer-name y)))
      )))
 
+(defun gited--sync-with-trunk-target-name (&optional branch)
+  (unless branch (setq branch (gited-get-branchname)))
+  (if (string-match "-new\\([0-9]*\\)\\'" branch)
+      (format "%s%d" (substring branch 0 (match-beginning 1))
+              (1+ (string-to-number (match-string 1 branch))))
+    (concat branch "-new1")))
+
 (defun gited-sync-with-trunk (branch-target)
   "Extract latest patches in branch at point and apply then into BRANCH-TARGET.
 BRANCH-TARGET is a new branch copied from (car (gited-trunk-branches)).
+
 The effect is similar than merge the branch at point with the trunk;
 one difference is that we don't modify the trunk, instead we copy it;
-another difference that we don't get a 'Merge branch...' commit in the log.
-this command set BRANCH-TARGET current."
+another difference is that we don't get a 'Merge branch...' commit in the log.
+This command sets BRANCH-TARGET current."
   (interactive
    (let* ((br (gited-get-branchname))
           (prompt
            (format "Syncronized '%s' into new branch: " br))
-          (def (if (string-match "-new\\([0-9]*\\)\\'" br)
-                   (format "%s%d" (substring br 0 (match-beginning 1))
-                           (1+ (string-to-number (match-string 1 br))))
-                 (concat br "-new1"))))
+          (def (gited--sync-with-trunk-target-name br)))
      (list
       (completing-read prompt
                        (gited-listed-branches)
@@ -2159,6 +2164,8 @@ this command set BRANCH-TARGET current."
   (unless (gited-remote-repository-p)
     (user-error "This command only works for repositories \
 tracking a remote repository"))
+  (when (gited-branch-exists-p branch-target)
+    (user-error "Branch '%s' already exists" branch-target))
   (if (null (ignore-errors (gited-extract-patches nil t)))
       (user-error "No new patches to apply")
     ;; If branch-target doesn't exists create it as copy of master.
@@ -2179,10 +2186,23 @@ tracking a remote repository"))
             (setq buf-patches (cdr buf-patches)
                   buf-commits (cdr buf-commits)))))
       (gited-checkout-branch branch-target)
-      (gited-update)
       (message "Successfully applied and committed %d commits!"
                num-commits))))
 
+(defun gited-do-sync-with-trunk (&optional dont-ask)
+  (interactive "P")
+  (dolist (br (or (gited-get-marked-branches) (list (gited-get-branchname))))
+    (let* ((prompt
+            (format "Syncronized '%s' into new branch: " br))
+           (def (gited--sync-with-trunk-target-name br))
+           (target
+            (if dont-ask def
+              (completing-read
+               prompt (gited-listed-branches)
+               nil nil def))))
+      (gited-sync-with-trunk target)))
+  (gited-update))
+
 (defun gited-bisecting-p ()
   "Return non-nil if a Git bisect is on process."
   (zerop (gited-git-command '("bisect" "log"))))
@@ -3298,7 +3318,7 @@ in the active region."
     (define-key map (kbd "C-c c") 'gited-commit)
     (define-key map (kbd "w") 'gited-copy-branchname-as-kill)
     (define-key map (kbd "e") 'gited-extract-patches)
-    (define-key map (kbd "T") 'gited-sync-with-trunk)
+    (define-key map (kbd "T") 'gited-do-sync-with-trunk)
     (define-key map (kbd "M") 'gited-merge-branch)
     (define-key map (kbd "c") 'gited-checkout-branch)
     (define-key map (kbd "v") 'gited-visit-branch-sources)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]