@matheusbsbs / matheus-bagliano / commits / 811b10c746
Fork 0

git.el: Add a command to create a new branch.

Prompts for a branch name, create a new branch at HEAD and switch to it. Bound to C-c C-b by default. Based on a patch by Rémi Vanicat <vanicat@debian.org>. Signed-off-by: Alexandre Julliard <julliard@winehq.org>

Alexandre Julliard committed Nov 23, 2008 at 14:25 UTC 811b10c746a63d1818d52c9ecbf247d9a3891597
1 file changed +14
contrib/emacs/git.el
+14
@@ -1383,6 +1383,18 @@ Use a prefix arg if git should merge while checking out."
1383 (when (apply #'git-call-process-display-error "checkout" args)
1384 (git-update-status-files))))
1385
1386 +(defun git-branch (branch)
1387 + "Create a branch from the current HEAD and switch to it."
1388 + (interactive (list (git-read-commit-name "Branch: ")))
1389 + (unless git-status (error "Not in git-status buffer."))
1390 + (if (git-rev-parse (concat "refs/heads/" branch))
1391 + (if (yes-or-no-p (format "Branch %s already exists, replace it? " branch))
1392 + (and (git-call-process-display-error "branch" "-f" branch)
1393 + (git-call-process-display-error "checkout" branch))
1394 + (message "Canceled."))
1395 + (git-call-process-display-error "checkout" "-b" branch))
1396 + (git-refresh-ewoc-hf git-status))
1397 +
1398 (defun git-amend-commit ()
1399 "Undo the last commit on HEAD, and set things up to commit an
1400 amended version of it."
@@ -1498,6 +1510,7 @@ amended version of it."
1510 (define-key map "\M-\C-?" 'git-unmark-all)
1511 ; the commit submap
1512 (define-key commit-map "\C-a" 'git-amend-commit)
1513 + (define-key commit-map "\C-b" 'git-branch)
1514 (define-key commit-map "\C-o" 'git-checkout)
1515 ; the diff submap
1516 (define-key diff-map "b" 'git-diff-file-base)
@@ -1520,6 +1533,7 @@ amended version of it."
1533 ["Refresh" git-refresh-status t]
1534 ["Commit" git-commit-file t]
1535 ["Checkout..." git-checkout t]
1536 + ["New Branch..." git-branch t]
1537 ("Merge"
1538 ["Next Unmerged File" git-next-unmerged-file t]
1539 ["Prev Unmerged File" git-prev-unmerged-file t]