* [BUG] 'stg add FILE' when FILE is a symlink to dir adds dir contents
@ 2007-04-11 15:54 Tomash Brechko
2007-04-12 6:58 ` Karl Hasselström
2007-04-13 23:02 ` Catalin Marinas
0 siblings, 2 replies; 3+ messages in thread
From: Tomash Brechko @ 2007-04-11 15:54 UTC (permalink / raw)
To: git, Catalin Marinas
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
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [BUG] 'stg add FILE' when FILE is a symlink to dir adds dir contents
2007-04-11 15:54 [BUG] 'stg add FILE' when FILE is a symlink to dir adds dir contents Tomash Brechko
@ 2007-04-12 6:58 ` Karl Hasselström
2007-04-13 23:02 ` Catalin Marinas
1 sibling, 0 replies; 3+ messages in thread
From: Karl Hasselström @ 2007-04-12 6:58 UTC (permalink / raw)
To: git, Catalin Marinas
On 2007-04-11 19:54:52 +0400, Tomash Brechko wrote:
> 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):'.
Correct. From the Python library reference:
isdir(path)
Return True if path is an existing directory. This follows
symbolic links, so both islink() and isdir() can be true for the
same path.
So, os.path.islink() would be the function to use.
--
Karl Hasselström, kha@treskal.com
www.treskal.com/kalle
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [BUG] 'stg add FILE' when FILE is a symlink to dir adds dir contents
2007-04-11 15:54 [BUG] 'stg add FILE' when FILE is a symlink to dir adds dir contents Tomash Brechko
2007-04-12 6:58 ` Karl Hasselström
@ 2007-04-13 23:02 ` Catalin Marinas
1 sibling, 0 replies; 3+ messages in thread
From: Catalin Marinas @ 2007-04-13 23:02 UTC (permalink / raw)
To: git, Catalin Marinas
On 11/04/07, Tomash Brechko <tomash.brechko@gmail.com> wrote:
> 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.
Thanks for this.
> 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?
Because this code was implemented almost 2 years ago when I don't
think git-update-index was able to scan directories. Never looked at
re-implementing it.
> I also guess the code doesn't honor .gitignore.
It doesn't, unless git-update-index ignores the files passed on the
command line according to the .gitignore content.
> Could 'names' list be passed to git-update-index directly?
Probably, I'll give it a try and see whether it breaks anything.
--
Catalin
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-04-13 23:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-11 15:54 [BUG] 'stg add FILE' when FILE is a symlink to dir adds dir contents Tomash Brechko
2007-04-12 6:58 ` Karl Hasselström
2007-04-13 23:02 ` Catalin Marinas
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).