use skip_prefix() to avoid more magic numbers
[gitweb.git] / builtin / checkout.c
index f71e74531d2a7d195ff2987f6dca3c69c636aa7c..cef1996d1663fb2f5d4b910bfd1661ebe2fe042b 100644 (file)
@@ -552,6 +552,12 @@ static int merge_working_tree(const struct checkout_opts *opts,
                }
        }
 
+       if (!active_cache_tree)
+               active_cache_tree = cache_tree();
+
+       if (!cache_tree_fully_valid(active_cache_tree))
+               cache_tree_update(&the_index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR);
+
        if (write_locked_index(&the_index, lock_file, COMMIT_LOCK))
                die(_("unable to write new index file"));
 
@@ -1144,10 +1150,8 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
                const char *argv0 = argv[0];
                if (!argc || !strcmp(argv0, "--"))
                        die (_("--track needs a branch name"));
-               if (starts_with(argv0, "refs/"))
-                       argv0 += 5;
-               if (starts_with(argv0, "remotes/"))
-                       argv0 += 8;
+               skip_prefix(argv0, "refs/", &argv0);
+               skip_prefix(argv0, "remotes/", &argv0);
                argv0 = strchr(argv0, '/');
                if (!argv0 || !argv0[1])
                        die (_("Missing branch name; try -b"));