summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorJacob Keller <jacob.keller@gmail.com>2017-04-13 17:12:24 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-04-19 01:01:41 (GMT)
commit2cfe66a8ee57fb3da18c262db8e6df95e263510b (patch)
tree0012929e62af8eee6a24e0795f46333d38a6d72f /builtin
parent2e5d6503bdc92260eae9c58b9fd1add7014bb853 (diff)
downloadgit-2cfe66a8ee57fb3da18c262db8e6df95e263510b.zip
git-2cfe66a8ee57fb3da18c262db8e6df95e263510b.tar.gz
git-2cfe66a8ee57fb3da18c262db8e6df95e263510b.tar.bz2
ls-files: fix path used when recursing into submodules
Don't assume that the current working directory is the root of the repository. Correctly generate the path for the recursing child processes by building it from the work_tree() root instead. Otherwise if we run ls-files using --git-dir or --work-tree it will not work correctly as it attempts to change directory into a potentially invalid location. Best case, it doesn't exist and we produce an error. Worst case we cd into the wrong location and unknown behavior occurs. Add a new test which highlights this possibility. Signed-off-by: Jacob Keller <jacob.keller@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/ls-files.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index e9b3546..a6c70db 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -203,6 +203,7 @@ static void show_gitlink(const struct cache_entry *ce)
{
struct child_process cp = CHILD_PROCESS_INIT;
int status;
+ char *dir;
prepare_submodule_repo_env(&cp.env_array);
argv_array_push(&cp.env_array, GIT_DIR_ENVIRONMENT);
@@ -221,8 +222,10 @@ static void show_gitlink(const struct cache_entry *ce)
argv_array_pushv(&cp.args, submodule_options.argv);
cp.git_cmd = 1;
- cp.dir = ce->name;
+ dir = mkpathdup("%s/%s", get_git_work_tree(), ce->name);
+ cp.dir = dir;
status = run_command(&cp);
+ free(dir);
if (status)
exit(status);
}