checkout-index: work from subdirectory.
With this, git-checkout-index from a subdirectory works as expected. Note that "git-checkout-index -a" checks out files only in the current directory and under. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Nov 26, 2005 at 00:22 UTC
c3e9a6534c88767e2ad9126ed45598157c28d1f4
1 file changed
+11
-1
checkout-index.c
+11
-1
@@ -34,6 +34,9 @@
34
*/
35
#include "cache.h"
36
37
+static const char *prefix;
38
+static int prefix_length;
39
+
40
static struct checkout state = {
41
.base_dir = "",
42
.base_dir_len = 0,
@@ -69,6 +72,10 @@ static int checkout_all(void)
72
struct cache_entry *ce = active_cache[i];
73
if (ce_stage(ce))
74
continue;
75
+ if (prefix && *prefix &&
76
+ ( ce_namelen(ce) <= prefix_length ||
77
+ memcmp(prefix, ce->name, prefix_length) ))
78
+ continue;
79
if (checkout_entry(ce, &state) < 0)
80
errs++;
81
}
@@ -91,6 +98,9 @@ int main(int argc, char **argv)
98
int newfd = -1;
99
int all = 0;
100
101
+ prefix = setup_git_directory();
102
+ prefix_length = prefix ? strlen(prefix) : 0;
103
+
104
if (read_cache() < 0) {
105
die("invalid cache");
106
}
@@ -155,7 +165,7 @@ int main(int argc, char **argv)
165
166
if (all)
167
die("git-checkout-index: don't mix '--all' and explicit filenames");
158
- checkout_file(arg);
168
+ checkout_file(prefix_path(prefix, prefix_length, arg));
169
}
170
171
if (all)