Code

Merge branch 'maint'
authorJunio C Hamano <gitster@pobox.com>
Tue, 15 Apr 2008 06:15:09 +0000 (23:15 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 15 Apr 2008 06:15:09 +0000 (23:15 -0700)
* maint:
  git clean: Add test to verify directories aren't removed with a prefix
  git clean: Don't automatically remove directories when run within subdirectory
  git-submodule - possibly use branch name to describe a module

builtin-clean.c
dir.c
git-submodule.sh
t/t7300-clean.sh

index fefec3010c434219234e7832051ada9ed2e52335..6778a03ae4c901d216e4b91cd41f2073e0e98589 100644 (file)
@@ -95,7 +95,8 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
 
        for (i = 0; i < dir.nr; i++) {
                struct dir_entry *ent = dir.entries[i];
-               int len, pos, matches;
+               int len, pos;
+               int matches = 0;
                struct cache_entry *ce;
                struct stat st;
 
@@ -127,18 +128,18 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
 
                if (pathspec) {
                        memset(seen, 0, argc > 0 ? argc : 1);
-                       matches = match_pathspec(pathspec, ent->name, ent->len,
+                       matches = match_pathspec(pathspec, ent->name, len,
                                                 baselen, seen);
-               } else {
-                       matches = 0;
                }
 
                if (S_ISDIR(st.st_mode)) {
                        strbuf_addstr(&directory, ent->name);
                        qname = quote_path_relative(directory.buf, directory.len, &buf, prefix);
-                       if (show_only && (remove_directories || matches)) {
+                       if (show_only && (remove_directories ||
+                           (matches == MATCHED_EXACTLY))) {
                                printf("Would remove %s\n", qname);
-                       } else if (remove_directories || matches) {
+                       } else if (remove_directories ||
+                                  (matches == MATCHED_EXACTLY)) {
                                if (!quiet)
                                        printf("Removing %s\n", qname);
                                if (remove_dir_recursively(&directory, 0) != 0) {
diff --git a/dir.c b/dir.c
index edc458e020772a7ab704e9cf69786d3aa641bcd4..d79762c7c0bc9e762ed8dc5f00fb2fd3ce01ad57 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -80,7 +80,7 @@ static int match_one(const char *match, const char *name, int namelen)
        if (strncmp(match, name, matchlen))
                return !fnmatch(match, name, 0) ? MATCHED_FNMATCH : 0;
 
-       if (!name[matchlen])
+       if (namelen == matchlen)
                return MATCHED_EXACTLY;
        if (match[matchlen-1] == '/' || name[matchlen] == '/')
                return MATCHED_RECURSIVELY;
index 7674346c8d9525b0d8928f48354bdbe0af8b8e23..a745e42bf7b19d6b813ff8e1e60e8b0ba41aaa14 100755 (executable)
@@ -327,7 +327,8 @@ set_name_rev () {
                cd "$1" && {
                        git describe "$2" 2>/dev/null ||
                        git describe --tags "$2" 2>/dev/null ||
-                       git describe --contains --tags --always "$2"
+                       git describe --contains "$2" 2>/dev/null ||
+                       git describe --all --always "$2"
                }
        ) )
        test -z "$revname" || revname=" ($revname)"
index afccfc9973ba864167387b1e1caf6fe8b12f68f9..a50492f7c065d034cb344eac965d51a82cb5a599 100755 (executable)
@@ -75,8 +75,8 @@ test_expect_success 'git-clean src/ src/' '
 
 test_expect_success 'git-clean with prefix' '
 
-       mkdir -p build docs &&
-       touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
+       mkdir -p build docs src/test &&
+       touch a.out src/part3.c docs/manual.txt obj.o build/lib.so src/test/1.c &&
        (cd src/ && git-clean) &&
        test -f Makefile &&
        test -f README &&
@@ -84,6 +84,7 @@ test_expect_success 'git-clean with prefix' '
        test -f src/part2.c &&
        test -f a.out &&
        test ! -f src/part3.c &&
+       test -f src/test/1.c &&
        test -f docs/manual.txt &&
        test -f obj.o &&
        test -f build/lib.so