{"thread":{"id":"7608","subject":"[BUG] 'stg add FILE' when FILE is a symlink to dir adds dir contents","startedAt":"2007-04-11T15:54:52Z","lastAt":"2007-04-13T23:02:22Z","messageCount":3,"participants":["Tomash Brechko","Karl Hasselström","Catalin Marinas"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"39120","messageId":"20070411155452.GL5329@moonlight.home","threadId":"7608","inReplyTo":null,"subject":"[BUG] 'stg add FILE' when FILE is a symlink to dir adds dir contents","fromName":"Tomash Brechko","fromEmail":"tomash.brechko@gmail.com","sentAt":"2007-04-11T15:54:52Z","receivedAt":"2007-04-11T15:54:52Z","isPatch":false,"sender":{"key":"tomash.brechko@gmail.com","avatar":null},"body":"Hello,\n\nI have noticed that 'stg add FILE' works differently from 'git add\nFILE' when file is a symlink to the directory: StGIT adds the contents\nof dir, while GIT adds the symlink itself.\n\nIn stgit/git.py we see:\n\n> def add(names):\n>     \"\"\"Add the files or recursively add the directory contents\n>     \"\"\"\n>     # generate the file list\n>     files = []\n>     for i in names:\n>         if not os.path.exists(i):\n>             raise GitException, 'Unknown file or directory: %s' % i\n> \n>         if os.path.isdir(i):\n>             # recursive search. We only add files\n>             for root, dirs, local_files in os.walk(i):\n>                 for name in [os.path.join(root, f) for f in local_files]:\n>                     if os.path.isfile(name):\n>                         files.append(os.path.normpath(name))\n>         elif os.path.isfile(i):\n>             files.append(os.path.normpath(i))\n>         else:\n>             raise GitException, '%s is not a file or directory' % i\n> \n>     if files:\n>         if __run('git-update-index --add --', files):\n>             raise GitException, 'Unable to add file'\n\n\nI have no knowledge of Python, so I can't fix it myself, but perhaps\none should check for symlink before 'if os.path.isdir(i):'.  This also\nwill fix 'elif os.path.isfile(i):' branch if 'os.path.normpath(i)'\ncall dereferences symlinks (I'm not sure if that is the case).\n\nBut curious, why does the code traverse the tree itself?  Why not to\ngive the file list directly to git-update-index, and let it decide\nwhat files to add, and how?  I also guess the code doesn't honor\n.gitignore.\n\nCould 'names' list be passed to git-update-index directly?\n\n\n-- \n   Tomash Brechko\n"},{"id":"39206","messageId":"20070412065810.GA22949@diana.vm.bytemark.co.uk","threadId":"7608","inReplyTo":"20070411155452.GL5329@moonlight.home","subject":"Re: [BUG] 'stg add FILE' when FILE is a symlink to dir adds dir contents","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2007-04-12T06:58:10Z","receivedAt":"2007-04-12T06:58:10Z","isPatch":false,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"On 2007-04-11 19:54:52 +0400, Tomash Brechko wrote:\n\n> I have no knowledge of Python, so I can't fix it myself, but perhaps\n> one should check for symlink before 'if os.path.isdir(i):'.\n\nCorrect. From the Python library reference:\n\n  isdir(path)\n    Return True if path is an existing directory. This follows\n    symbolic links, so both islink() and isdir() can be true for the\n    same path.\n\nSo, os.path.islink() would be the function to use.\n\n-- \nKarl Hasselström, kha@treskal.com\n      www.treskal.com/kalle\n"},{"id":"39317","messageId":"b0943d9e0704131602o694a46c8xb4101a05cf8ec2d3@mail.gmail.com","threadId":"7608","inReplyTo":"20070411155452.GL5329@moonlight.home","subject":"Re: [BUG] 'stg add FILE' when FILE is a symlink to dir adds dir contents","fromName":"Catalin Marinas","fromEmail":"catalin.marinas@gmail.com","sentAt":"2007-04-13T23:02:22Z","receivedAt":"2007-04-13T23:02:22Z","isPatch":false,"sender":{"key":"catalin.marinas@gmail.com","avatar":null},"body":"On 11/04/07, Tomash Brechko <tomash.brechko@gmail.com> wrote:\n> I have noticed that 'stg add FILE' works differently from 'git add\n> FILE' when file is a symlink to the directory: StGIT adds the contents\n> of dir, while GIT adds the symlink itself.\n\nThanks for this.\n\n> But curious, why does the code traverse the tree itself?  Why not to\n> give the file list directly to git-update-index, and let it decide\n> what files to add, and how?\n\nBecause this code was implemented almost 2 years ago when I don't\nthink git-update-index was able to scan directories. Never looked at\nre-implementing it.\n\n> I also guess the code doesn't honor .gitignore.\n\nIt doesn't, unless git-update-index ignores the files passed on the\ncommand line according to the .gitignore content.\n\n> Could 'names' list be passed to git-update-index directly?\n\nProbably, I'll give it a try and see whether it breaks anything.\n\n-- \nCatalin\n"}]}