unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Git adding-removing files
@ 2009-12-10  0:06 andrea
  0 siblings, 0 replies; only message in thread
From: andrea @ 2009-12-10  0:06 UTC (permalink / raw)
  To: help-gnu-emacs


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










^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-12-10  0:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-10  0:06 Git adding-removing files andrea

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).