Thread (7 messages) flat view 7 messages, 4 authors, 2016-06-15

Re: [PATCH 1/2] Add option to not delete a .git directory in remove_dir_recursively()

From: Johannes Sixt <hidden>
Date: 2016-06-15 22:47:00

Jason Holden schrieb:
quoted hunk ↗ jump to hunk
@@ -812,6 +812,19 @@ int remove_dir_recursively(struct strbuf *path, int only_empty)
 		strbuf_addch(path, '/');
 
 	len = path->len;
+
+	if (keep_dot_git) {
+		char end_of_path[6]; /* enough space for ".git/"*/
+		memset(end_of_path, '\0', 6);
+		if (len >= 5) {
+			strncpy(end_of_path, path->buf + len - 5, 5);
+			if (strcmp(end_of_path, ".git/") == 0) {
+				printf("********Found .git!!!!  Skipping delete\n");
I see no reason to ***shout!!!*** here. IOW:

				warning("not removing %s", dir);

is enough. This also sends the text to stderr.
+				return 0;
+			}
+		}
+	}
+
 	while ((e = readdir(dir)) != NULL) {
 		struct stat st;
 		if (is_dot_or_dotdot(e->d_name))
I think it is even better to move the check for ".git" below this 'if'. It
should not make a difference in practice.

-- Hannes
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help