git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[BUG] 'stg add FILE' when FILE is a symlink to dir adds dir contents

From
TBTomash Brechko <tomash.brechko@gmail.com>
Date
Apr 11, 2007, 15:54 UTC
Message-ID
<20070411155452.GL5329@moonlight.home>
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:
Show 23 quoted lines
> 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
Next: Karl Hasselström
Message 1 of 3 in “[BUG] 'stg add FILE' when FILE is a symlink to dir adds dir contents”
  1. Tomash BrechkoApr 11, 2007
  2. Karl HasselströmApr 12, 2007
  3. Catalin MarinasApr 13, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.