git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tomash Brechko <tomash.brechko@gmail.com>
To: git@vger.kernel.org, Catalin Marinas <catalin.marinas@gmail.com>
Subject: [BUG] 'stg add FILE' when FILE is a symlink to dir adds dir contents
Date: Wed, 11 Apr 2007 19:54:52 +0400	[thread overview]
Message-ID: <20070411155452.GL5329@moonlight.home> (raw)

Hello,

I have noticed that 'stg add FILE' works differently from 'git add
FILE' when file is a symlink to the directory: StGIT adds the contents
of dir, while GIT adds the symlink itself.

In stgit/git.py we see:

> def add(names):
>     """Add the files or recursively add the directory contents
>     """
>     # generate the file list
>     files = []
>     for i in names:
>         if not os.path.exists(i):
>             raise GitException, 'Unknown file or directory: %s' % i
> 
>         if os.path.isdir(i):
>             # recursive search. We only add files
>             for root, dirs, local_files in os.walk(i):
>                 for name in [os.path.join(root, f) for f in local_files]:
>                     if os.path.isfile(name):
>                         files.append(os.path.normpath(name))
>         elif os.path.isfile(i):
>             files.append(os.path.normpath(i))
>         else:
>             raise GitException, '%s is not a file or directory' % i
> 
>     if files:
>         if __run('git-update-index --add --', files):
>             raise GitException, 'Unable to add file'


I have no knowledge of Python, so I can't fix it myself, but perhaps
one should check for symlink before 'if os.path.isdir(i):'.  This also
will fix 'elif os.path.isfile(i):' branch if 'os.path.normpath(i)'
call dereferences symlinks (I'm not sure if that is the case).

But curious, why does the code traverse the tree itself?  Why not to
give the file list directly to git-update-index, and let it decide
what files to add, and how?  I also guess the code doesn't honor
.gitignore.

Could 'names' list be passed to git-update-index directly?


-- 
   Tomash Brechko

             reply	other threads:[~2007-04-11 16:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-11 15:54 Tomash Brechko [this message]
2007-04-12  6:58 ` [BUG] 'stg add FILE' when FILE is a symlink to dir adds dir contents Karl Hasselström
2007-04-13 23:02 ` Catalin Marinas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070411155452.GL5329@moonlight.home \
    --to=tomash.brechko@gmail.com \
    --cc=catalin.marinas@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).