Johannes Schindelin | 11be42a | 2006-07-26 03:52:35 +0200 | [diff] [blame] | 1 | /* |
| 2 | * "git mv" builtin command |
| 3 | * |
| 4 | * Copyright (C) 2006 Johannes Schindelin |
| 5 | */ |
Johannes Schindelin | 11be42a | 2006-07-26 03:52:35 +0200 | [diff] [blame] | 6 | #include "cache.h" |
| 7 | #include "builtin.h" |
| 8 | #include "dir.h" |
| 9 | #include "cache-tree.h" |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 10 | #include "string-list.h" |
Pierre Habouzit | c7a20c1 | 2007-10-07 14:19:33 +0200 | [diff] [blame] | 11 | #include "parse-options.h" |
Johannes Schindelin | 11be42a | 2006-07-26 03:52:35 +0200 | [diff] [blame] | 12 | |
Pierre Habouzit | c7a20c1 | 2007-10-07 14:19:33 +0200 | [diff] [blame] | 13 | static const char * const builtin_mv_usage[] = { |
Stephan Beyer | 1b1dd23 | 2008-07-13 15:36:15 +0200 | [diff] [blame] | 14 | "git mv [options] <source>... <destination>", |
Pierre Habouzit | c7a20c1 | 2007-10-07 14:19:33 +0200 | [diff] [blame] | 15 | NULL |
| 16 | }; |
Johannes Schindelin | 11be42a | 2006-07-26 03:52:35 +0200 | [diff] [blame] | 17 | |
| 18 | static const char **copy_pathspec(const char *prefix, const char **pathspec, |
| 19 | int count, int base_name) |
| 20 | { |
Johannes Schindelin | d78b0f3 | 2006-08-16 10:44:02 +0200 | [diff] [blame] | 21 | int i; |
Johannes Schindelin | 11be42a | 2006-07-26 03:52:35 +0200 | [diff] [blame] | 22 | const char **result = xmalloc((count + 1) * sizeof(const char *)); |
| 23 | memcpy(result, pathspec, count * sizeof(const char *)); |
| 24 | result[count] = NULL; |
Johannes Schindelin | d78b0f3 | 2006-08-16 10:44:02 +0200 | [diff] [blame] | 25 | for (i = 0; i < count; i++) { |
| 26 | int length = strlen(result[i]); |
Junio C Hamano | af82559 | 2010-01-22 14:17:06 -0800 | [diff] [blame] | 27 | int to_copy = length; |
| 28 | while (to_copy > 0 && is_dir_sep(result[i][to_copy - 1])) |
| 29 | to_copy--; |
| 30 | if (to_copy != length || base_name) { |
| 31 | char *it = xmemdupz(result[i], to_copy); |
Brandon Casey | 0d0ff65 | 2011-10-06 13:22:23 -0500 | [diff] [blame] | 32 | if (base_name) { |
| 33 | result[i] = xstrdup(basename(it)); |
| 34 | free(it); |
| 35 | } else |
| 36 | result[i] = it; |
Junio C Hamano | af82559 | 2010-01-22 14:17:06 -0800 | [diff] [blame] | 37 | } |
Johannes Schindelin | 11be42a | 2006-07-26 03:52:35 +0200 | [diff] [blame] | 38 | } |
Junio C Hamano | 971dfa1 | 2008-03-06 23:29:40 -0800 | [diff] [blame] | 39 | return get_pathspec(prefix, result); |
Johannes Schindelin | 11be42a | 2006-07-26 03:52:35 +0200 | [diff] [blame] | 40 | } |
| 41 | |
Johannes Schindelin | ac64a72 | 2006-07-26 19:47:54 +0200 | [diff] [blame] | 42 | static const char *add_slash(const char *path) |
| 43 | { |
| 44 | int len = strlen(path); |
| 45 | if (path[len - 1] != '/') { |
| 46 | char *with_slash = xmalloc(len + 2); |
| 47 | memcpy(with_slash, path, len); |
Junio C Hamano | 329a304 | 2006-08-08 12:21:33 -0700 | [diff] [blame] | 48 | with_slash[len++] = '/'; |
| 49 | with_slash[len] = 0; |
Johannes Schindelin | ac64a72 | 2006-07-26 19:47:54 +0200 | [diff] [blame] | 50 | return with_slash; |
| 51 | } |
| 52 | return path; |
| 53 | } |
| 54 | |
Johannes Schindelin | 11be42a | 2006-07-26 03:52:35 +0200 | [diff] [blame] | 55 | static struct lock_file lock_file; |
| 56 | |
Junio C Hamano | 7061cf0 | 2006-07-29 01:54:54 -0700 | [diff] [blame] | 57 | int cmd_mv(int argc, const char **argv, const char *prefix) |
Johannes Schindelin | 11be42a | 2006-07-26 03:52:35 +0200 | [diff] [blame] | 58 | { |
Pierre Habouzit | c7a20c1 | 2007-10-07 14:19:33 +0200 | [diff] [blame] | 59 | int i, newfd; |
Johannes Schindelin | 11be42a | 2006-07-26 03:52:35 +0200 | [diff] [blame] | 60 | int verbose = 0, show_only = 0, force = 0, ignore_errors = 0; |
Pierre Habouzit | c7a20c1 | 2007-10-07 14:19:33 +0200 | [diff] [blame] | 61 | struct option builtin_mv_options[] = { |
Jeff King | 07b8738 | 2011-12-12 02:51:24 -0500 | [diff] [blame] | 62 | OPT__VERBOSE(&verbose, "be verbose"), |
René Scharfe | e21adb8 | 2010-11-08 18:58:51 +0100 | [diff] [blame] | 63 | OPT__DRY_RUN(&show_only, "dry run"), |
René Scharfe | 76946b7 | 2010-11-08 19:01:54 +0100 | [diff] [blame] | 64 | OPT__FORCE(&force, "force move/rename even if target exists"), |
Pierre Habouzit | c7a20c1 | 2007-10-07 14:19:33 +0200 | [diff] [blame] | 65 | OPT_BOOLEAN('k', NULL, &ignore_errors, "skip move/rename errors"), |
| 66 | OPT_END(), |
| 67 | }; |
Johannes Schindelin | 11be42a | 2006-07-26 03:52:35 +0200 | [diff] [blame] | 68 | const char **source, **destination, **dest_path; |
Johannes Schindelin | ac64a72 | 2006-07-26 19:47:54 +0200 | [diff] [blame] | 69 | enum update_mode { BOTH = 0, WORKING_DIRECTORY, INDEX } *modes; |
Johannes Schindelin | 11be42a | 2006-07-26 03:52:35 +0200 | [diff] [blame] | 70 | struct stat st; |
Thiago Farina | 183113a | 2010-07-04 16:46:19 -0300 | [diff] [blame] | 71 | struct string_list src_for_dst = STRING_LIST_INIT_NODUP; |
Johannes Schindelin | 11be42a | 2006-07-26 03:52:35 +0200 | [diff] [blame] | 72 | |
Johannes Schindelin | ef90d6d | 2008-05-14 18:46:53 +0100 | [diff] [blame] | 73 | git_config(git_default_config, NULL); |
Johannes Schindelin | 11be42a | 2006-07-26 03:52:35 +0200 | [diff] [blame] | 74 | |
Stephen Boyd | 3778292 | 2009-05-23 11:53:12 -0700 | [diff] [blame] | 75 | argc = parse_options(argc, argv, prefix, builtin_mv_options, |
| 76 | builtin_mv_usage, 0); |
Pierre Habouzit | c7a20c1 | 2007-10-07 14:19:33 +0200 | [diff] [blame] | 77 | if (--argc < 1) |
| 78 | usage_with_options(builtin_mv_usage, builtin_mv_options); |
Johannes Schindelin | 11be42a | 2006-07-26 03:52:35 +0200 | [diff] [blame] | 79 | |
Jonathan Nieder | 99caeed | 2009-11-09 09:05:01 -0600 | [diff] [blame] | 80 | newfd = hold_locked_index(&lock_file, 1); |
| 81 | if (read_cache() < 0) |
Ævar Arnfjörð Bjarmason | 431b049 | 2011-02-22 23:42:03 +0000 | [diff] [blame] | 82 | die(_("index file corrupt")); |
Jonathan Nieder | 99caeed | 2009-11-09 09:05:01 -0600 | [diff] [blame] | 83 | |
Pierre Habouzit | c7a20c1 | 2007-10-07 14:19:33 +0200 | [diff] [blame] | 84 | source = copy_pathspec(prefix, argv, argc, 0); |
| 85 | modes = xcalloc(argc, sizeof(enum update_mode)); |
| 86 | dest_path = copy_pathspec(prefix, argv + argc, 1, 0); |
Johannes Schindelin | 11be42a | 2006-07-26 03:52:35 +0200 | [diff] [blame] | 87 | |
Johannes Schindelin | c5203bd | 2006-08-18 12:42:39 +0200 | [diff] [blame] | 88 | if (dest_path[0][0] == '\0') |
| 89 | /* special case: "." was normalized to "" */ |
Pierre Habouzit | c7a20c1 | 2007-10-07 14:19:33 +0200 | [diff] [blame] | 90 | destination = copy_pathspec(dest_path[0], argv, argc, 1); |
Johannes Schindelin | c5203bd | 2006-08-18 12:42:39 +0200 | [diff] [blame] | 91 | else if (!lstat(dest_path[0], &st) && |
Johannes Schindelin | ac64a72 | 2006-07-26 19:47:54 +0200 | [diff] [blame] | 92 | S_ISDIR(st.st_mode)) { |
| 93 | dest_path[0] = add_slash(dest_path[0]); |
Pierre Habouzit | c7a20c1 | 2007-10-07 14:19:33 +0200 | [diff] [blame] | 94 | destination = copy_pathspec(dest_path[0], argv, argc, 1); |
Johannes Schindelin | ac64a72 | 2006-07-26 19:47:54 +0200 | [diff] [blame] | 95 | } else { |
Pierre Habouzit | c7a20c1 | 2007-10-07 14:19:33 +0200 | [diff] [blame] | 96 | if (argc != 1) |
Jeff King | 7747164 | 2011-12-12 02:51:36 -0500 | [diff] [blame] | 97 | die("destination '%s' is not a directory", dest_path[0]); |
Johannes Schindelin | 11be42a | 2006-07-26 03:52:35 +0200 | [diff] [blame] | 98 | destination = dest_path; |
| 99 | } |
| 100 | |
| 101 | /* Checking */ |
Pierre Habouzit | c7a20c1 | 2007-10-07 14:19:33 +0200 | [diff] [blame] | 102 | for (i = 0; i < argc; i++) { |
Johannes Schindelin | 60a6bf5 | 2006-08-19 16:52:21 +0200 | [diff] [blame] | 103 | const char *src = source[i], *dst = destination[i]; |
| 104 | int length, src_is_dir; |
Johannes Schindelin | 11be42a | 2006-07-26 03:52:35 +0200 | [diff] [blame] | 105 | const char *bad = NULL; |
| 106 | |
| 107 | if (show_only) |
Ævar Arnfjörð Bjarmason | 431b049 | 2011-02-22 23:42:03 +0000 | [diff] [blame] | 108 | printf(_("Checking rename of '%s' to '%s'\n"), src, dst); |
Johannes Schindelin | 11be42a | 2006-07-26 03:52:35 +0200 | [diff] [blame] | 109 | |
Johannes Schindelin | 60a6bf5 | 2006-08-19 16:52:21 +0200 | [diff] [blame] | 110 | length = strlen(src); |
| 111 | if (lstat(src, &st) < 0) |
Ævar Arnfjörð Bjarmason | a7d5629 | 2011-02-22 23:42:04 +0000 | [diff] [blame] | 112 | bad = _("bad source"); |
Johannes Schindelin | 60a6bf5 | 2006-08-19 16:52:21 +0200 | [diff] [blame] | 113 | else if (!strncmp(src, dst, length) && |
| 114 | (dst[length] == 0 || dst[length] == '/')) { |
Ævar Arnfjörð Bjarmason | a7d5629 | 2011-02-22 23:42:04 +0000 | [diff] [blame] | 115 | bad = _("can not move directory into itself"); |
Johannes Schindelin | 60a6bf5 | 2006-08-19 16:52:21 +0200 | [diff] [blame] | 116 | } else if ((src_is_dir = S_ISDIR(st.st_mode)) |
| 117 | && lstat(dst, &st) == 0) |
Ævar Arnfjörð Bjarmason | a7d5629 | 2011-02-22 23:42:04 +0000 | [diff] [blame] | 118 | bad = _("cannot move directory over file"); |
Johannes Schindelin | 60a6bf5 | 2006-08-19 16:52:21 +0200 | [diff] [blame] | 119 | else if (src_is_dir) { |
Johannes Schindelin | aca085e | 2006-12-03 20:42:47 +0100 | [diff] [blame] | 120 | const char *src_w_slash = add_slash(src); |
| 121 | int len_w_slash = length + 1; |
Johannes Schindelin | 60a6bf5 | 2006-08-19 16:52:21 +0200 | [diff] [blame] | 122 | int first, last; |
Johannes Schindelin | ac64a72 | 2006-07-26 19:47:54 +0200 | [diff] [blame] | 123 | |
| 124 | modes[i] = WORKING_DIRECTORY; |
| 125 | |
Johannes Schindelin | aca085e | 2006-12-03 20:42:47 +0100 | [diff] [blame] | 126 | first = cache_name_pos(src_w_slash, len_w_slash); |
Johannes Schindelin | ac64a72 | 2006-07-26 19:47:54 +0200 | [diff] [blame] | 127 | if (first >= 0) |
Ævar Arnfjörð Bjarmason | 431b049 | 2011-02-22 23:42:03 +0000 | [diff] [blame] | 128 | die (_("Huh? %.*s is in index?"), |
Johannes Schindelin | aca085e | 2006-12-03 20:42:47 +0100 | [diff] [blame] | 129 | len_w_slash, src_w_slash); |
Johannes Schindelin | ac64a72 | 2006-07-26 19:47:54 +0200 | [diff] [blame] | 130 | |
| 131 | first = -1 - first; |
| 132 | for (last = first; last < active_nr; last++) { |
| 133 | const char *path = active_cache[last]->name; |
Johannes Schindelin | aca085e | 2006-12-03 20:42:47 +0100 | [diff] [blame] | 134 | if (strncmp(path, src_w_slash, len_w_slash)) |
Johannes Schindelin | ac64a72 | 2006-07-26 19:47:54 +0200 | [diff] [blame] | 135 | break; |
| 136 | } |
Johannes Schindelin | aca085e | 2006-12-03 20:42:47 +0100 | [diff] [blame] | 137 | free((char *)src_w_slash); |
Johannes Schindelin | ac64a72 | 2006-07-26 19:47:54 +0200 | [diff] [blame] | 138 | |
| 139 | if (last - first < 1) |
Ævar Arnfjörð Bjarmason | a7d5629 | 2011-02-22 23:42:04 +0000 | [diff] [blame] | 140 | bad = _("source directory is empty"); |
Johannes Schindelin | 60a6bf5 | 2006-08-19 16:52:21 +0200 | [diff] [blame] | 141 | else { |
| 142 | int j, dst_len; |
Johannes Schindelin | ac64a72 | 2006-07-26 19:47:54 +0200 | [diff] [blame] | 143 | |
| 144 | if (last - first > 0) { |
Jonas Fonseca | 83572c1 | 2006-08-26 16:16:18 +0200 | [diff] [blame] | 145 | source = xrealloc(source, |
Pierre Habouzit | c7a20c1 | 2007-10-07 14:19:33 +0200 | [diff] [blame] | 146 | (argc + last - first) |
Johannes Schindelin | ac64a72 | 2006-07-26 19:47:54 +0200 | [diff] [blame] | 147 | * sizeof(char *)); |
Jonas Fonseca | 83572c1 | 2006-08-26 16:16:18 +0200 | [diff] [blame] | 148 | destination = xrealloc(destination, |
Pierre Habouzit | c7a20c1 | 2007-10-07 14:19:33 +0200 | [diff] [blame] | 149 | (argc + last - first) |
Johannes Schindelin | ac64a72 | 2006-07-26 19:47:54 +0200 | [diff] [blame] | 150 | * sizeof(char *)); |
Jonas Fonseca | 83572c1 | 2006-08-26 16:16:18 +0200 | [diff] [blame] | 151 | modes = xrealloc(modes, |
Pierre Habouzit | c7a20c1 | 2007-10-07 14:19:33 +0200 | [diff] [blame] | 152 | (argc + last - first) |
Johannes Schindelin | ac64a72 | 2006-07-26 19:47:54 +0200 | [diff] [blame] | 153 | * sizeof(enum update_mode)); |
| 154 | } |
| 155 | |
Johannes Schindelin | 60a6bf5 | 2006-08-19 16:52:21 +0200 | [diff] [blame] | 156 | dst = add_slash(dst); |
Junio C Hamano | d089eba | 2008-01-28 22:44:27 -0800 | [diff] [blame] | 157 | dst_len = strlen(dst); |
Johannes Schindelin | ac64a72 | 2006-07-26 19:47:54 +0200 | [diff] [blame] | 158 | |
| 159 | for (j = 0; j < last - first; j++) { |
| 160 | const char *path = |
| 161 | active_cache[first + j]->name; |
Pierre Habouzit | c7a20c1 | 2007-10-07 14:19:33 +0200 | [diff] [blame] | 162 | source[argc + j] = path; |
| 163 | destination[argc + j] = |
Johannes Schindelin | 60a6bf5 | 2006-08-19 16:52:21 +0200 | [diff] [blame] | 164 | prefix_path(dst, dst_len, |
Junio C Hamano | d089eba | 2008-01-28 22:44:27 -0800 | [diff] [blame] | 165 | path + length + 1); |
Pierre Habouzit | c7a20c1 | 2007-10-07 14:19:33 +0200 | [diff] [blame] | 166 | modes[argc + j] = INDEX; |
Johannes Schindelin | ac64a72 | 2006-07-26 19:47:54 +0200 | [diff] [blame] | 167 | } |
Pierre Habouzit | c7a20c1 | 2007-10-07 14:19:33 +0200 | [diff] [blame] | 168 | argc += last - first; |
Johannes Schindelin | ac64a72 | 2006-07-26 19:47:54 +0200 | [diff] [blame] | 169 | } |
Matthieu Moy | 5aed3c6 | 2009-02-04 10:32:08 +0100 | [diff] [blame] | 170 | } else if (cache_name_pos(src, length) < 0) |
Ævar Arnfjörð Bjarmason | a7d5629 | 2011-02-22 23:42:04 +0000 | [diff] [blame] | 171 | bad = _("not under version control"); |
Matthieu Moy | 5aed3c6 | 2009-02-04 10:32:08 +0100 | [diff] [blame] | 172 | else if (lstat(dst, &st) == 0) { |
Ævar Arnfjörð Bjarmason | a7d5629 | 2011-02-22 23:42:04 +0000 | [diff] [blame] | 173 | bad = _("destination exists"); |
Johannes Schindelin | 11be42a | 2006-07-26 03:52:35 +0200 | [diff] [blame] | 174 | if (force) { |
| 175 | /* |
| 176 | * only files can overwrite each other: |
| 177 | * check both source and destination |
| 178 | */ |
Petr Baudis | 81dc230 | 2008-07-21 02:25:56 +0200 | [diff] [blame] | 179 | if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) { |
Jeff King | 534376c | 2011-12-12 16:54:42 -0500 | [diff] [blame] | 180 | if (verbose) |
| 181 | warning(_("overwriting '%s'"), dst); |
Johannes Schindelin | 11be42a | 2006-07-26 03:52:35 +0200 | [diff] [blame] | 182 | bad = NULL; |
Johannes Schindelin | 11be42a | 2006-07-26 03:52:35 +0200 | [diff] [blame] | 183 | } else |
Ævar Arnfjörð Bjarmason | a7d5629 | 2011-02-22 23:42:04 +0000 | [diff] [blame] | 184 | bad = _("Cannot overwrite"); |
Johannes Schindelin | 11be42a | 2006-07-26 03:52:35 +0200 | [diff] [blame] | 185 | } |
Matthieu Moy | 5aed3c6 | 2009-02-04 10:32:08 +0100 | [diff] [blame] | 186 | } else if (string_list_has_string(&src_for_dst, dst)) |
Ævar Arnfjörð Bjarmason | a7d5629 | 2011-02-22 23:42:04 +0000 | [diff] [blame] | 187 | bad = _("multiple sources for the same target"); |
Johannes Schindelin | 60a6bf5 | 2006-08-19 16:52:21 +0200 | [diff] [blame] | 188 | else |
Julian Phillips | 78a395d | 2010-06-26 00:41:35 +0100 | [diff] [blame] | 189 | string_list_insert(&src_for_dst, dst); |
Johannes Schindelin | 11be42a | 2006-07-26 03:52:35 +0200 | [diff] [blame] | 190 | |
Johannes Schindelin | 11be42a | 2006-07-26 03:52:35 +0200 | [diff] [blame] | 191 | if (bad) { |
| 192 | if (ignore_errors) { |
Pierre Habouzit | c7a20c1 | 2007-10-07 14:19:33 +0200 | [diff] [blame] | 193 | if (--argc > 0) { |
Johannes Schindelin | 11be42a | 2006-07-26 03:52:35 +0200 | [diff] [blame] | 194 | memmove(source + i, source + i + 1, |
Pierre Habouzit | c7a20c1 | 2007-10-07 14:19:33 +0200 | [diff] [blame] | 195 | (argc - i) * sizeof(char *)); |
Johannes Schindelin | 11be42a | 2006-07-26 03:52:35 +0200 | [diff] [blame] | 196 | memmove(destination + i, |
| 197 | destination + i + 1, |
Pierre Habouzit | c7a20c1 | 2007-10-07 14:19:33 +0200 | [diff] [blame] | 198 | (argc - i) * sizeof(char *)); |
Michael J Gruber | be17262 | 2009-01-14 18:03:22 +0100 | [diff] [blame] | 199 | i--; |
Johannes Schindelin | 11be42a | 2006-07-26 03:52:35 +0200 | [diff] [blame] | 200 | } |
| 201 | } else |
Ævar Arnfjörð Bjarmason | 431b049 | 2011-02-22 23:42:03 +0000 | [diff] [blame] | 202 | die (_("%s, source=%s, destination=%s"), |
Johannes Schindelin | 60a6bf5 | 2006-08-19 16:52:21 +0200 | [diff] [blame] | 203 | bad, src, dst); |
Johannes Schindelin | 11be42a | 2006-07-26 03:52:35 +0200 | [diff] [blame] | 204 | } |
| 205 | } |
| 206 | |
Pierre Habouzit | c7a20c1 | 2007-10-07 14:19:33 +0200 | [diff] [blame] | 207 | for (i = 0; i < argc; i++) { |
Johannes Schindelin | 60a6bf5 | 2006-08-19 16:52:21 +0200 | [diff] [blame] | 208 | const char *src = source[i], *dst = destination[i]; |
| 209 | enum update_mode mode = modes[i]; |
Petr Baudis | 81dc230 | 2008-07-21 02:25:56 +0200 | [diff] [blame] | 210 | int pos; |
Johannes Schindelin | 11be42a | 2006-07-26 03:52:35 +0200 | [diff] [blame] | 211 | if (show_only || verbose) |
Ævar Arnfjörð Bjarmason | 431b049 | 2011-02-22 23:42:03 +0000 | [diff] [blame] | 212 | printf(_("Renaming %s to %s\n"), src, dst); |
Johannes Schindelin | 60a6bf5 | 2006-08-19 16:52:21 +0200 | [diff] [blame] | 213 | if (!show_only && mode != INDEX && |
| 214 | rename(src, dst) < 0 && !ignore_errors) |
Ævar Arnfjörð Bjarmason | 431b049 | 2011-02-22 23:42:03 +0000 | [diff] [blame] | 215 | die_errno (_("renaming '%s' failed"), src); |
Johannes Schindelin | 11be42a | 2006-07-26 03:52:35 +0200 | [diff] [blame] | 216 | |
Johannes Schindelin | 60a6bf5 | 2006-08-19 16:52:21 +0200 | [diff] [blame] | 217 | if (mode == WORKING_DIRECTORY) |
Johannes Schindelin | ac64a72 | 2006-07-26 19:47:54 +0200 | [diff] [blame] | 218 | continue; |
| 219 | |
Petr Baudis | 81dc230 | 2008-07-21 02:25:56 +0200 | [diff] [blame] | 220 | pos = cache_name_pos(src, strlen(src)); |
| 221 | assert(pos >= 0); |
| 222 | if (!show_only) |
| 223 | rename_cache_entry_at(pos, dst); |
Johannes Schindelin | 11be42a | 2006-07-26 03:52:35 +0200 | [diff] [blame] | 224 | } |
| 225 | |
Petr Baudis | 81dc230 | 2008-07-21 02:25:56 +0200 | [diff] [blame] | 226 | if (active_cache_changed) { |
| 227 | if (write_cache(newfd, active_cache, active_nr) || |
| 228 | commit_locked_index(&lock_file)) |
Ævar Arnfjörð Bjarmason | 431b049 | 2011-02-22 23:42:03 +0000 | [diff] [blame] | 229 | die(_("Unable to write new index file")); |
Johannes Schindelin | 11be42a | 2006-07-26 03:52:35 +0200 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | return 0; |
| 233 | } |