[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/gited 8502d7c 53/73: Handle multi remote repositories
From: |
Stefan Monnier |
Subject: |
[elpa] externals/gited 8502d7c 53/73: Handle multi remote repositories |
Date: |
Sun, 29 Nov 2020 00:00:38 -0500 (EST) |
branch: externals/gited
commit 8502d7cbc059e8b87cfc5cf57d8d7413008c8e13
Author: Tino Calancha <tino.calancha@gmail.com>
Commit: Tino Calancha <tino.calancha@gmail.com>
Handle multi remote repositories
It's common to have a local repository linked to more than one
remote repository. In such case we must specify the remote
repo. from which we want to fetch or push into.
This commit adds a new variable `gited-current-remote-rep'
to store the current remote repository; we pull/push
from/into that repository. It also adds a new command
`gited-change-current-remote-rep' to update this
variable.
Update file header. Bump version to 0.4.1.
* packages/gited/gited.el (gited-current-remote-rep): New variable.
(gited-toplevel-dir): When listing local branches display the
current remote repository in the header line.
(gited--update-header-line): New defun.
(gited-git-command-on-region): Move isolated ending parens to previous line.
(gited-pull, gited-push): Pull/push from/into the current remote rep.
(gited-mode-map): Bind `gited-change-current-remote-rep' to '*r'.
---
gited.el | 98 +++++++++++++++++++++++++++++++++++++++++++++-------------------
1 file changed, 70 insertions(+), 28 deletions(-)
diff --git a/gited.el b/gited.el
index 66459dd..7fdfc91 100644
--- a/gited.el
+++ b/gited.el
@@ -1,6 +1,6 @@
;;; gited.el --- Operate on Git branches like dired -*- lexical-binding:t -*-
;;
-;; Copyright (C) 2016-2017 Free Software Foundation, Inc.
+;; Copyright (C) 2016-2018 Free Software Foundation, Inc.
;;
;; Author: Tino Calancha <tino.calancha@gmail.com>
;; Maintainer: Tino Calancha <tino.calancha@gmail.com>
@@ -8,11 +8,11 @@
;; Created: Wed Oct 26 01:28:54 JST 2016
;; Compatibility: GNU Emacs: 24.4
-;; Version: 0.3.4
+;; Version: 0.4.1
;; Package-Requires: ((emacs "24.4") (cl-lib "0.5"))
-;; Last-Updated: Sun Jan 21 14:07:11 JST 2018
+;; Last-Updated: Mon Mar 26 16:46:14 JST 2018
;; By: calancha
-;; Update #: 683
+;; Update #: 684
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
@@ -98,21 +98,22 @@
;; `gited-branch-name-face', `gited-buffer',
;; `gited-buffer-name', `gited-commit-idx',
;; `gited-commit-msg-face', `gited-current-branch',
-;; `gited-date-idx', `gited-date-regexp',
-;; `gited-date-time-face', `gited-del-char',
-;; `gited-deletion-branch-face', `gited-deletion-face',
-;; `gited-edit-commit-mode-map', `gited-flag-mark-face',
-;; `gited-flag-mark-line-face', `gited-header',
-;; `gited-list-format', `gited-list-refs-format-command',
-;; `gited-log-buffer', `gited-mark-col-size',
-;; `gited-mark-face', `gited-mark-idx',
-;; `gited-marker-char', `gited-mode',
-;; `gited-mode-map', `gited-modified-branch',
-;; `gited-new-or-deleted-files-re', `gited-op-string',
-;; `gited-original-buffer', `gited-output-buffer',
-;; `gited-output-buffer-name', `gited-re-mark',
-;; `gited-ref-kind', `gited-section-highlight-face',
-;; `gited-toplevel-dir', `gited-trunk-branch'.
+;; `gited-current-remote-rep', `gited-date-idx',
+;; `gited-date-regexp', `gited-date-time-face',
+;; `gited-del-char', `gited-deletion-branch-face',
+;; `gited-deletion-face', `gited-edit-commit-mode-map',
+;; `gited-flag-mark-face', `gited-flag-mark-line-face',
+;; `gited-header', `gited-list-format',
+;; `gited-list-refs-format-command', `gited-log-buffer',
+;; `gited-mark-col-size', `gited-mark-face',
+;; `gited-mark-idx', `gited-marker-char',
+;; `gited-mode', `gited-mode-map',
+;; `gited-modified-branch', `gited-new-or-deleted-files-re',
+;; `gited-op-string', `gited-original-buffer',
+;; `gited-output-buffer', `gited-output-buffer-name',
+;; `gited-re-mark', `gited-ref-kind',
+;; `gited-section-highlight-face', `gited-toplevel-dir',
+;; `gited-trunk-branch'.
;;
;; Coustom variables defined here:
;;
@@ -195,10 +196,11 @@
;; `gited--move-to-end-of-column', `gited--output-buffer',
;; `gited--patch-or-commit-buffer', `gited--set-output-buffer-mode',
;; `gited--stash-branch', `gited--sync-with-trunk-target-name',
-;; `gited--update-padding', `gited--valid-ref-p',
-;; `gited-all-branches', `gited-async-operation-sentinel',
-;; `gited-at-header-line-p', `gited-bisecting-p',
-;; `gited-branch-exists-p', `gited-buffer-p',
+;; `gited--update-header-line', `gited--update-padding',
+;; `gited--valid-ref-p', `gited-all-branches',
+;; `gited-async-operation-sentinel', `gited-at-header-line-p',
+;; `gited-bisecting-p', `gited-branch-exists-p',
+;; `gited-buffer-p', `gited-change-current-remote-rep',
;; `gited-current-branch', `gited-current-branches-with-marks',
;; `gited-current-state-list', `gited-dir-under-Git-control-p',
;; `gited-edit-commit', `gited-fontify-current-branch',
@@ -257,6 +259,10 @@
"The branch currently checked out.")
(put 'gited-current-branch 'permanent-local t)
+(defvar-local gited-current-remote-rep "origin"
+ "The remote repository where we are pulling/pushing.")
+(put 'gited-current-remote-rep 'permanent-local t)
+
(defvar-local gited-toplevel-dir nil
"Absolute path of the top-level directory for the current repository.")
(put 'gited-toplevel-dir 'permanent-local t)
@@ -456,7 +462,7 @@ If you change this option, then you might want to change
(pcase gited-ref-kind
("tags" "Tags")
("remote" "Remote Branches")
- (_ "Branches")))
+ (_ (format "Branches (remote repository: %s)" gited-current-remote-rep))))
(defun gited--list-format-init (&optional col-names col-sizes)
"Initialize `gited-list-format'.
@@ -856,6 +862,38 @@ Optional arg UNQUOTE removes single quotes from the
output."
(while (re-search-forward "^'\\(.*\\)'$" nil t)
(replace-match "\\1")))))))
+(defun gited--update-header-line ()
+ "Update header line with current remote repository."
+ (let ((regexp "Branches (remote repository: \\([^)]+\\))"))
+ (when (string-match regexp header-line-format)
+ (setq header-line-format
+ (replace-match
+ gited-current-remote-rep nil nil header-line-format 1))
+ (force-mode-line-update))))
+
+(defun gited-change-current-remote-rep ()
+ (interactive)
+ (unless (derived-mode-p 'gited-mode)
+ (user-error "Not a Gited buffer"))
+ (let ((remote-repositories
+ (with-temp-buffer
+ (gited-git-command '("remote") (current-buffer))
+ (split-string (buffer-string) nil 'omit-nulls))))
+ (cond ((null (cdr remote-repositories))
+ (user-error "Only one remote repository!"))
+ ((null (cddr remote-repositories))
+ (setq gited-current-remote-rep
+ (car (delete gited-current-remote-rep remote-repositories))))
+ (t
+ (let ((remote-rep
+ (completing-read
+ (format "Choose remote repository")
+ remote-repositories
+ nil t)))
+ (setq gited-current-remote-rep remote-rep))))
+ (gited--update-header-line)
+ (message "Updated remote repository to '%s'" gited-current-remote-rep)))
+
(defun gited-git-command-on-region (args &optional buffer display)
"Execute a Git command with arguments ARGS and region as input.
Optional arg BUFFER is the output buffer.
@@ -2022,8 +2060,7 @@ show similar info as that command."
(length stashes)))
(insert (mapconcat 'identity stashes "\n")))
(display-buffer buf)
- (gited--set-output-buffer-mode buf 'outline)))
- )))
+ (gited--set-output-buffer-mode buf 'outline))))))
(defun gited-pull ()
"Run git pull in current branch."
@@ -2033,7 +2070,10 @@ show similar info as that command."
(y-or-n-p (format "Pull on '%s' branch? " branch))))
(message "OK, pull canceled")
(let ((buf (gited--output-buffer))
- (cmd (format "%s pull" vc-git-program))
+ (cmd (format "%s pull %s %s"
+ vc-git-program
+ gited-current-remote-rep
+ (gited-current-branch)))
(inhibit-read-only t))
(setq gited-output-buffer buf
gited-op-string cmd)
@@ -2051,7 +2091,8 @@ ref is not ancestor of the local ref."
gited-current-branch))))
(message "OK, push canceled")
(let ((buf (gited--output-buffer))
- (cmd (format "%s push %s" vc-git-program
+ (cmd (format "%s push %s master %s %s"
+ vc-git-program gited-current-remote-rep
(gited-current-branch)
(if force-with-lease "--force-with-lease" ""))))
(setq gited-output-buffer buf
gited-op-string cmd)
@@ -3447,6 +3488,7 @@ in the active region."
(define-key map (kbd "* p") 'gited-set-object-upstream)
(define-key map (kbd "* <") 'gited-pull)
(define-key map (kbd "* >") 'gited-push)
+ (define-key map (kbd "* r") 'gited-change-current-remote-rep)
(define-key map (kbd "o") 'gited-origin)
(define-key map (kbd "l") 'gited-log)
(define-key map (kbd "L") 'gited-log-last-n-commits)
- [elpa] externals/gited 5f57f01 21/73: * gited.el (gited-mode-map): Use prefix '* s' for all stash commands., (continued)
- [elpa] externals/gited 5f57f01 21/73: * gited.el (gited-mode-map): Use prefix '* s' for all stash commands., Stefan Monnier, 2020/11/29
- [elpa] externals/gited 8db1633 04/73: gited-update: Don't overwrite `tabulated-list-sort-key', Stefan Monnier, 2020/11/29
- [elpa] externals/gited 5138dee 01/73: Add new library gited.el, Stefan Monnier, 2020/11/29
- [elpa] externals/gited 9989d95 05/73: Fix sort of columns when gited-hide-details-mode is enabled, Stefan Monnier, 2020/11/29
- [elpa] externals/gited 861281e 06/73: * gited.el (gited-mark-branches-regexp): Fix docstring., Stefan Monnier, 2020/11/29
- [elpa] externals/gited eeadd65 26/73: Add missing docstrings for several commands, Stefan Monnier, 2020/11/29
- [elpa] externals/gited 239ac36 31/73: * gited.el: Bump version to 0.2.3., Stefan Monnier, 2020/11/29
- [elpa] externals/gited fd28d69 48/73: * gited-tests.el (gited-test1): Use gited--last-commit-title., Stefan Monnier, 2020/11/29
- [elpa] externals/gited 09c79b9 64/73: Separate versions from file names with --, Stefan Monnier, 2020/11/29
- [elpa] externals/gited ed83468 59/73: * packages/gited/gited.el: Bump version to v5.0.1, Stefan Monnier, 2020/11/29
- [elpa] externals/gited 8502d7c 53/73: Handle multi remote repositories,
Stefan Monnier <=
- [elpa] externals/gited 55fc368 54/73: Fix gited-push bug from previous commit, Stefan Monnier, 2020/11/29
- [elpa] externals/gited 8241ee5 41/73: gited-checkout-branch: Set right faces for marked branches, Stefan Monnier, 2020/11/29
- [elpa] externals/gited 0a303a1 70/73: Make code more compact by using pcase-dolist, Stefan Monnier, 2020/11/29
- [elpa] externals/gited 40e57eb 60/73: * gited/gited.el: Don't require `gited-ci`, which isn't found., Stefan Monnier, 2020/11/29
- [elpa] externals/gited b5fdc7e 61/73: Add missing file gited-ci.el, Stefan Monnier, 2020/11/29
- [elpa] externals/gited ad074e1 49/73: * packages/gited/gited.el (gited-stash-branch): Update Gited buffer on success, Stefan Monnier, 2020/11/29
- [elpa] externals/gited 36ec8fa 34/73: ; * packages/gited/gited.el: Update file header., Stefan Monnier, 2020/11/29
- [elpa] externals/gited f81463e 44/73: gited-git-checkout: New function, Stefan Monnier, 2020/11/29
- [elpa] externals/gited d78161b 56/73: * packages/gited/gited.el (gited-pull): Delete unused variable, Stefan Monnier, 2020/11/29
- [elpa] externals/gited 475e297 72/73: Support Gited buffers over a tramp connection, Stefan Monnier, 2020/11/29