Finding the repository

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

 



At least in version 1.7.0.4, it seems git does not like being run
from outside the repository, even if the file(s) being operated
on are inside the repository, unless it is given a pointer to the
repository via the --git-dir= option or the GIT_DIR enironment
variable.

For example, suppose /foo/bar is a local repository and baz.c is a
file in the outermost directory that I want to remove.  This works:

  $ cd /foo/bar
  $ git rm baz.c

but this, which intuitively should mean exactly the same thing,
fails:

  $ cd /foo
  $ git rm bar/baz.c
  fatal: Not a git repository (or any of the parent directories): .git

I've written a wrapper script that solves this problem, but it is
more an illustration or proof of concept than a real "solution"
-- the command line parsing may well be imperfect, and it would
be semantically incorrect in such cases as committing multiple
(individually specified) files:  it would do a separate commit
of each pathname rather than a single commit of all pathnames.

Has anyone considered enhancing the automatic repository search in
git itself to look in the directory where the specified file(s) is/are
located, as a last resort before failing?  (Yes, this does present
the potential for operating on multiple repositories with a single
invocation of git; would that be a bad thing?)

--------

#!/usr/local/bin/bash

# smarter git:  if the current directory has no .git subdirectory
# (i.e. is not in a repository), try running git in the directory
# where each file is located instead of in the current directory.

[ "$1" == "--version" -o "$1" == "--help" -o "$1" == "--exec-path" \
  -o "x$GIT_DIR" != "x" -o -d .git ] && exec git "$@"

# Set defaults
flags=""
dirSet=0

# Collect flag params
while [[ "$1" == -?* ]] ; do
   case "$1" in
      --git-dir=* )
	dirSet=1
	;;
      * )
   esac
   flags="$flags $1"
   shift
done

[ "$dirSet" == "1" ] && exec git $flags "$@"

# next word must be the command

gitCmd="$1"
shift

# remaining words must be pathnames

for f in "$@"
do
   ( cd $(dirname "$f") && git $flags $gitCmd $(basename "$f") )
done
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]