26
26
FILE_IS_IGNORED = 8
27
27
FILE_NOT_IN_CONFLICT = 9
28
28
FILE_ALREADY_RESOLVED = 10
29
+ FILE_IS_DIR = 11
29
30
30
31
# Possible Gitless's file types.
31
- TRACKED = 11
32
- UNTRACKED = 12
33
- IGNORED = 13
32
+ TRACKED = 12
33
+ UNTRACKED = 13
34
+ IGNORED = 14
34
35
35
36
# Possible diff output lines.
36
37
DIFF_INFO = git_file .DIFF_INFO # line carrying diff info for new hunk.
@@ -46,9 +47,11 @@ def track(fp):
46
47
fp: the file path of the file to track.
47
48
48
49
Returns:
49
- FILE_NOT_FOUND, FILE_ALREADY_TRACKED, FILE_IN_CONFLICT, FILE_IS_IGNORED or
50
- SUCCESS.
50
+ FILE_NOT_FOUND, FILE_IS_DIR, FILE_ALREADY_TRACKED, FILE_IN_CONFLICT,
51
+ FILE_IS_IGNORED or SUCCESS.
51
52
"""
53
+ if os .path .isdir (fp ):
54
+ return FILE_IS_DIR
52
55
f_st , s = _status (fp )
53
56
if f_st == FILE_NOT_FOUND :
54
57
return FILE_NOT_FOUND
@@ -81,9 +84,11 @@ def untrack(fp):
81
84
fp: the file path of the file to untrack.
82
85
83
86
Returns:
84
- FILE_NOT_FOUND, FILE_ALREADY_UNTRACKED, FILE_IN_CONFLICT, FILE_IS_IGNORED or
85
- SUCCESS.
87
+ FILE_NOT_FOUND, FILE_IS_DIR, FILE_ALREADY_UNTRACKED, FILE_IN_CONFLICT,
88
+ FILE_IS_IGNORED or SUCCESS.
86
89
"""
90
+ if os .path .isdir (fp ):
91
+ return FILE_IS_DIR
87
92
f_st , s = _status (fp )
88
93
if f_st == FILE_NOT_FOUND :
89
94
return FILE_NOT_FOUND
@@ -122,11 +127,13 @@ def diff(fp):
122
127
123
128
Returns:
124
129
a pair (result, out) where result is one of FILE_NOT_FOUND,
125
- FILE_IS_UNTRACKED or SUCCESS and out is the output of the diff command in a
126
- machine-friendly way: it's a tuple of the form
130
+ FILE_IS_UNTRACKED, FILE_IS_DIR or SUCCESS and out is the output of the diff
131
+ command in a machine-friendly way: it's a tuple of the form
127
132
(list of namedtuples with fields 'line', 'status', 'old_line_number',
128
133
'new_line_number', line number padding).
129
134
"""
135
+ if os .path .isdir (fp ):
136
+ return (FILE_IS_DIR , (None , None ))
130
137
f_st , s = _status (fp )
131
138
if f_st == git_status .FILE_NOT_FOUND :
132
139
return (FILE_NOT_FOUND , (None , None ))
@@ -157,9 +164,11 @@ def checkout(fp, cp='HEAD'):
157
164
cp: the commit point at which to checkout the file (defaults to HEAD).
158
165
159
166
Returns:
160
- a pair (status, out) where status is one of FILE_NOT_FOUND_AT_CP or SUCCESS
161
- and out is the content of fp at cp.
167
+ a pair (status, out) where status is one of FILE_IS_DIR,
168
+ FILE_NOT_FOUND_AT_CP or SUCCESS and out is the content of fp at cp.
162
169
"""
170
+ if os .path .isdir (fp ):
171
+ return (FILE_IS_DIR , None )
163
172
# "show" expects the full path with respect to the repo root.
164
173
rel_fp = os .path .join (repo_lib .cwd (), fp )[1 :]
165
174
ret , out = git_file .show (rel_fp , cp )
@@ -236,7 +245,9 @@ def resolve(fp):
236
245
if f_st .resolved :
237
246
return FILE_ALREADY_RESOLVED
238
247
239
- # In Git, to mark a file as resolved we have to add it.
248
+ # We don't use Git to keep track of resolved files, but just to make it feel
249
+ # like doing a resolve in Gitless is similar to doing a resolve in Git
250
+ # (i.e., add) we stage the file.
240
251
git_file .stage (fp )
241
252
# We add a file in the Gitless directory to be able to tell when a file has
242
253
# been marked as resolved.
@@ -278,7 +289,17 @@ def _build_f_st(s, fp):
278
289
elif s == git_status .TRACKED_MODIFIED :
279
290
ret = FileStatus (fp , TRACKED , True , True , True , False , False )
280
291
elif s == git_status .STAGED :
281
- # Staged file don't exist in the lr for Gitless.
292
+ # A file could have been "gl track"ed and later ignored by adding a matching
293
+ # pattern in a .gitignore file. We consider this kind of file to still be a
294
+ # tracked file. This is consistent with the idea that tracked files can't
295
+ # be ignored.
296
+ # TODO(sperezde): address the following rough edge: the user could untrack
297
+ # a tracked file (one that was not committed before) and if it's matched by
298
+ # a .gitignore file it will be ignored. The same thing won't happen if an
299
+ # already committed file is untracked (due to how Gitless keeps track of
300
+ # these kind of files).
301
+
302
+ # Staged files don't exist in the lr for Gitless.
282
303
ret = FileStatus (fp , TRACKED , False , True , True , False , False )
283
304
elif s == git_status .ASSUME_UNCHANGED :
284
305
# TODO(sperezde): detect whether it is modified or not?
@@ -287,15 +308,15 @@ def _build_f_st(s, fp):
287
308
ret = FileStatus (fp , TRACKED , True , False , True , False , False )
288
309
elif s == git_status .DELETED_STAGED :
289
310
# This can only happen if the user did a rm of a new file. The file doesn't
290
- # exist anymore for Gitless.
311
+ # exist as far as Gitless is concerned .
291
312
git_file .unstage (fp )
292
313
ret = None
293
314
elif s == git_status .DELETED_ASSUME_UNCHANGED :
294
315
ret = None
295
316
elif s == git_status .IN_CONFLICT :
296
317
wr = _was_resolved (fp )
297
318
ret = FileStatus (fp , TRACKED , True , True , True , not wr , wr )
298
- elif s == git_status .IGNORED or s == git_status . IGNORED_STAGED :
319
+ elif s == git_status .IGNORED :
299
320
ret = FileStatus (fp , IGNORED , False , True , True , True , False )
300
321
elif s == git_status .MODIFIED_MODIFIED :
301
322
# The file was marked as resolved and then modified. To Gitless, this is
0 commit comments