help-gnu-emacs
[Top][All Lists]
Advanced

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

Git adding-removing files


From: andrea
Subject: Git adding-removing files
Date: Thu, 10 Dec 2009 01:06:47 +0100
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.1.50 (darwin)

Given that I have a lot of git project around my home I started to think
that I need something more comfortable to manage my repos.

I use already magit and it's great, but when I add a new file I would
like in most of the cases to add it automatically to the repository.

I then initially wrote this code:

--8<---------------cut here---------------start------------->8---
(defun add-git-eventually ()
  "Ask if you want to add a file to the local git repository"
  (interactive)
  (let ((curr-file (file-name-nondirectory buffer-file-name)))
    (if (file-exists-p ".git")
        ;; Check that the file is not already in repository
        (if
            (string= "" (shell-command-to-string
                         (format "git ls-files | grep %s" curr-file)))
            (progn
              (message "we are in a git repo")
              (if (yes-or-no-p
                   (format "do you want to add %s to repository?\n"
                           curr-file))
                  (add-file-to-git curr-file)
                ;; TODO: Add the file to a list of non desired files
          (message "file already in repository")))))))

(defun add-file-to-git (fname)
  "adds the current file in the actual git repository"
  (interactive)
  (let ((cmd (format "git add -v %s" fname)))
    (message (concat "executing " cmd))
    (shell-command cmd)))

--8<---------------cut here---------------end--------------->8---

and I put an hook on "after-save", but then is becoming too annoying
when I don't wat to add a file

Changes I would like to do:
- check .git also in upper directories (but don't take the one in
  $HOME/.git

- exclude a file adding to info/exclude of the git repo.
  Adding all the files anyway it doesn't make much sense, maybe it
  should ask for a pattern or add the file by default.
  *append-to-file* is enough here?

- only try to add the file is not excluded already.
  this can be done with some git magic I think.

Any help?
the full file is here
http://github.com/AndreaCrotti/Emacs-conf/blob/master/.emacs.d/conf/git.el










reply via email to

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