@matheusbsbs / matheus-bagliano / commits / b8e9a00d40
Fork 0

git-branch -d: do not stop at the first failure.

If there are more than one branches to be deleted, failure on one will no longer stop git-branch to process the next ones. The command still reports failures by exitting non-zero status. Signed-off-by: Quy Tonthat <qtonthat@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>

Quy Tonthat committed Dec 19, 2006 at 09:42 UTC b8e9a00d40839a76928c54366a1c46ad54d7fd5d
1 file changed +39 -18
builtin-branch.c
+39 -18
@@ -93,13 +93,14 @@ static int in_merge_bases(const unsigned char *sha1,
93 return ret;
94 }
95
96 -static void delete_branches(int argc, const char **argv, int force, int kinds)
96 +static int delete_branches(int argc, const char **argv, int force, int kinds)
97 {
98 struct commit *rev, *head_rev = head_rev;
99 unsigned char sha1[20];
100 - char *name;
100 + char *name = NULL;
101 const char *fmt, *remote;
102 int i;
103 + int ret = 0;
104
105 switch (kinds) {
106 case REF_REMOTE_BRANCH:
@@ -121,16 +122,30 @@ static void delete_branches(int argc, const char **argv, int force, int kinds)
122 die("Couldn't look up commit object for HEAD");
123 }
124 for (i = 0; i < argc; i++) {
124 - if (kinds == REF_LOCAL_BRANCH && !strcmp(head, argv[i]))
125 - die("Cannot delete the branch you are currently on.");
125 + if (kinds == REF_LOCAL_BRANCH && !strcmp(head, argv[i])) {
126 + error("Cannot delete the branch '%s' "
127 + "which you are currently on.", argv[i]);
128 + ret = 1;
129 + continue;
130 + }
131 +
132 + if (name)
133 + free(name);
134
135 name = xstrdup(mkpath(fmt, argv[i]));
128 - if (!resolve_ref(name, sha1, 1, NULL))
129 - die("%sbranch '%s' not found.", remote, argv[i]);
136 + if (!resolve_ref(name, sha1, 1, NULL)) {
137 + error("%sbranch '%s' not found.",
138 + remote, argv[i]);
139 + ret = 1;
140 + continue;
141 + }
142
143 rev = lookup_commit_reference(sha1);
132 - if (!rev)
133 - die("Couldn't look up commit object for '%s'", name);
144 + if (!rev) {
145 + error("Couldn't look up commit object for '%s'", name);
146 + ret = 1;
147 + continue;
148 + }
149
150 /* This checks whether the merge bases of branch and
151 * HEAD contains branch -- which means that the HEAD
@@ -139,21 +154,27 @@ static void delete_branches(int argc, const char **argv, int force, int kinds)
154
155 if (!force &&
156 !in_merge_bases(sha1, rev, head_rev)) {
142 - fprintf(stderr,
143 - "The branch '%s' is not a strict subset of your current HEAD.\n"
144 - "If you are sure you want to delete it, run 'git branch -D %s'.\n",
145 - argv[i], argv[i]);
146 - exit(1);
157 + error("The branch '%s' is not a strict subset of "
158 + "your current HEAD.\n"
159 + "If you are sure you want to delete it, "
160 + "run 'git branch -D %s'.", argv[i], argv[i]);
161 + ret = 1;
162 + continue;
163 }
164
149 - if (delete_ref(name, sha1))
150 - printf("Error deleting %sbranch '%s'\n", remote,
165 + if (delete_ref(name, sha1)) {
166 + error("Error deleting %sbranch '%s'", remote,
167 argv[i]);
152 - else
168 + ret = 1;
169 + } else
170 printf("Deleted %sbranch %s.\n", remote, argv[i]);
171
155 - free(name);
172 }
173 +
174 + if (name)
175 + free(name);
176 +
177 + return(ret);
178 }
179
180 struct ref_item {
@@ -450,7 +471,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
471 head += 11;
472
473 if (delete)
453 - delete_branches(argc - i, argv + i, force_delete, kinds);
474 + return delete_branches(argc - i, argv + i, force_delete, kinds);
475 else if (i == argc)
476 print_ref_list(kinds, verbose, abbrev);
477 else if (rename && (i == argc - 1))