Skip to content

Instantly share code, notes, and snippets.

@bricewge
Last active August 29, 2015 14:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bricewge/b86bc8cda8cc12fa1897 to your computer and use it in GitHub Desktop.
Save bricewge/b86bc8cda8cc12fa1897 to your computer and use it in GitHub Desktop.
magit/magit #460
(defun yingyang-link (gitdir worktree)
(interactive (list (read-directory-name "Gitdir: ")
(read-directory-name "Worktree: ")))
(with-temp-file (expand-file-name ".git" worktree)
(insert "gitdir: " (file-relative-name gitdir worktree) "\n"))
(magit-call-git "config" "-f" (expand-file-name "config" gitdir)
"core.worktree" (file-relative-name worktree gitdir)))
(defun yingyang-unlink (gitdir worktree)
(interactive (list (read-directory-name "Gitdir: ")
(read-directory-name "Worktree: ")))
;; This does `git config --unset core.worktree'. We don't actually
;; have to do this and not doing it would have some advantages, but
;; might be confusing.
(magit-set nil "core.worktree")
;; This causes an error if this actually is a directory, which is
;; a good thing, it saves us from having to do this explicitly :-)
(delete-file (expand-file-name ".git" worktree)))
(defvar vcsh-repo-d
(or (getenv "VCSH_HOOK_D")
(substitute-in-file-name "$HOME/vcsh/repo.d")))
(defvar vcsh-base
(or (getenv "VCSH_HOME") (getenv "HOME")))
(defun vcsh-link (repo)
(interactive
(list (completing-read "Vcsh repository: "
(directory-files "~/.config/vcsh/repo.d/" nil "^[^.]")
nil t)))
(setq repo (expand-file-name repo vcsh-repo-d))
;; "Fix" repositories that were created with --bare.
(let ((default-directory (file-name-as-directory repo)))
(magit-set "false" "core.bare"))
;; Regular link.
(yingyang-link repo vcsh-base))
(defun vcsh-unlink ()
(interactive)
(yingyang-unlink (with-temp-buffer
(insert-file-contents (expand-file-name vcsh-base ".git"))
(re-search-forward "gitdir: \\(.+\\)")
(file-name-absolute-p (match-string 1)))
vcsh-base))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment