File tree Expand file tree Collapse file tree 3 files changed +57
-0
lines changed Expand file tree Collapse file tree 3 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 6868 - archive_tar_gz and archive_tar and replaced by archive method with different signature
6969* 'commits' method has no max-count of returned commits anymore, it now behaves
7070 like git-rev-list
71+ * 'untracked_files' property added, returning all currently untracked files
7172
7273Diff
7374----
Original file line number Diff line number Diff line change @@ -285,6 +285,37 @@ def is_dirty(self):
285285 return False
286286
287287 return len (self .git .diff ('HEAD' , '--' ).strip ()) > 0
288+
289+ @property
290+ def untracked_files (self ):
291+ """
292+ Returns
293+ list(str,...)
294+
295+ Files currently untracked as they have not been staged yet. Paths
296+ are relative to the current working directory of the git command.
297+
298+ Note
299+ ignored files will not appear here, i.e. files mentioned in .gitignore
300+ """
301+ # make sure we get all files, no only untracked directores
302+ proc = self .git .commit (untracked_files = True , as_process = True )
303+ stream = iter (proc .stdout )
304+ untracked_files = list ()
305+ for line in stream :
306+ if not line .startswith ("# Untracked files:" ):
307+ continue
308+ # skip two lines
309+ stream .next ()
310+ stream .next ()
311+
312+ for untracked_info in stream :
313+ if not untracked_info .startswith ("#\t " ):
314+ break
315+ untracked_files .append (untracked_info .replace ("#\t " , "" ).rstrip ())
316+ # END for each utracked info line
317+ # END for each line
318+ return untracked_files
288319
289320 @property
290321 def active_branch (self ):
Original file line number Diff line number Diff line change @@ -225,3 +225,28 @@ def test_should_display_blame_information(self, git):
225225 assert_true ( tlist )
226226 assert_true ( isinstance ( tlist [0 ], basestring ) )
227227 assert_true ( len ( tlist ) < sum ( len (t ) for t in tlist ) ) # test for single-char bug
228+
229+ def test_untracked_files (self ):
230+ base = self .repo .git .git_dir
231+ files = (base + "/__test_myfile" , base + "/__test_other_file" )
232+ num_recently_untracked = 0
233+ try :
234+ for fpath in files :
235+ fd = open (fpath ,"wb" )
236+ fd .close ()
237+ # END for each filename
238+ untracked_files = self .repo .untracked_files
239+ num_recently_untracked = len (untracked_files )
240+
241+ # assure we have all names - they are relative to the git-dir
242+ num_test_untracked = 0
243+ for utfile in untracked_files :
244+ num_test_untracked += os .path .join (base , utfile ) in files
245+ assert len (files ) == num_test_untracked
246+ finally :
247+ for fpath in files :
248+ if os .path .isfile (fpath ):
249+ os .remove (fpath )
250+ # END handle files
251+
252+ assert len (self .repo .untracked_files ) == (num_recently_untracked - len (files ))
You can’t perform that action at this time.
0 commit comments