More detailed and structured information from git-svn.
* magit.el (magit-svn-enabled): alist of git-svn information returned.
This commit is contained in:
parent
ee01adf1f3
commit
3bfe230051
2 changed files with 48 additions and 13 deletions
45
magit.el
45
magit.el
|
@ -2190,23 +2190,42 @@ in log buffer."
|
||||||
(magit-run-git-async "svn" "dcommit"))
|
(magit-run-git-async "svn" "dcommit"))
|
||||||
|
|
||||||
(defun magit-svn-enabled ()
|
(defun magit-svn-enabled ()
|
||||||
(not (null (magit-get-svn-ref))))
|
(not (null (magit-get "svn-remote" "svn" "fetch"))))
|
||||||
|
|
||||||
|
(defun magit-get-svn-ref-info ()
|
||||||
|
"Gather details about the current git-svn repository (nil if
|
||||||
|
there isn't one). Keys of the alist are ref-path, trunk-ref-name
|
||||||
|
and local-ref-name."
|
||||||
|
(let* ((fetch (magit-get "svn-remote" "svn" "fetch"))
|
||||||
|
(branches (magit-get "svn-remote" "svn" "fetch")))
|
||||||
|
(when fetch
|
||||||
|
(list
|
||||||
|
(cons 'ref-path (file-name-directory
|
||||||
|
(cadr (split-string fetch ":"))))
|
||||||
|
(cons 'trunk-ref-name (file-name-nondirectory
|
||||||
|
(cadr (split-string fetch ":"))))
|
||||||
|
;; get the local ref from the log. This is actually
|
||||||
|
;; the way that git-svn does it.
|
||||||
|
(cons 'local-ref-name
|
||||||
|
(with-temp-buffer
|
||||||
|
(insert (magit-git-string "log" "--first-parent"))
|
||||||
|
(goto-char (point-min))
|
||||||
|
(when (re-search-forward "git-svn-id: .+/\\(.+?\\)@" nil t)
|
||||||
|
(match-string 1))))))))
|
||||||
|
|
||||||
|
(defun magit-get-svn-trunk-ref ()
|
||||||
|
"Get the best guess remote trunk ref for the current git-svn
|
||||||
|
based branch."
|
||||||
|
(let ((info (magit-get-svn-ref-info)))
|
||||||
|
(concat (cdr (assoc 'ref-path info))
|
||||||
|
(cdr (assoc 'trunk-ref-name info)))))
|
||||||
|
|
||||||
(defun magit-get-svn-ref ()
|
(defun magit-get-svn-ref ()
|
||||||
"Get the best guess remote ref for the current git-svn based
|
"Get the best guess remote ref for the current git-svn based
|
||||||
branch."
|
branch."
|
||||||
(let* ((info (magit-get "svn-remote" "svn" "fetch"))
|
(let ((info (magit-get-svn-ref-info)))
|
||||||
(refs))
|
(concat (cdr (assoc 'ref-path info))
|
||||||
(when info
|
(cdr (assoc 'local-ref-name info)))))
|
||||||
(concat
|
|
||||||
(file-name-directory (cadr (split-string info ":")))
|
|
||||||
(with-temp-buffer
|
|
||||||
;; grab the git-svn-id information, this is how git-svn.perl
|
|
||||||
;; does it :/
|
|
||||||
(insert (magit-git-string "log" "--first-parent"))
|
|
||||||
(goto-char (point-min))
|
|
||||||
(when (re-search-forward "git-svn-id: .+/\\(.+?\\)@" nil t)
|
|
||||||
(match-string 1)))))))
|
|
||||||
|
|
||||||
;;; Resetting
|
;;; Resetting
|
||||||
|
|
||||||
|
|
16
magit.etest
Normal file
16
magit.etest
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
(require 'el-mock)
|
||||||
|
|
||||||
|
(etest
|
||||||
|
("svn"
|
||||||
|
(equal (assoc 'trunk-ref-name
|
||||||
|
(with-mock
|
||||||
|
(stub magit-get => "someproject/trunk:refs/remotes/hello/trunk")
|
||||||
|
(magit-get-svn-ref-info)))
|
||||||
|
'(trunk-ref-name . "trunk")
|
||||||
|
"correct refpath from `magit-get-svn-ref-info'")
|
||||||
|
(equal (assoc 'refpath
|
||||||
|
(with-mock
|
||||||
|
(stub magit-get => "someproject/trunk:refs/remotes/hello/trunk")
|
||||||
|
(magit-get-svn-ref-info)))
|
||||||
|
'(refpath . "refs/remotes/hello/")
|
||||||
|
"correct refpath from `magit-get-svn-ref-info'")))
|
Loading…
Add table
Reference in a new issue