Code

user-manual: update for new default --track behavior
[git.git] / builtin-ls-files.c
index 61577ea13ffdf0143dcb8a13c37ae49c1f8f2018..d36181a75541df10c5dc1595ccca5a6fc429591f 100644 (file)
@@ -469,9 +469,11 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
                break;
        }
 
-       if (require_work_tree &&
-                       (!is_inside_work_tree() || is_inside_git_dir()))
-               die("This operation must be run in a work tree");
+       if (require_work_tree && !is_inside_work_tree()) {
+               const char *work_tree = get_git_work_tree();
+               if (!work_tree || chdir(work_tree))
+                       die("This operation must be run in a work tree");
+       }
 
        pathspec = get_pathspec(prefix, argv + i);