mirror of
https://github.com/git-for-windows/git.git
synced 2026-04-23 11:11:44 -05:00
Merge branch 'lj/refs' into next
* lj/refs: Uncomment test case: git branch c/d should barf if branch c exists. When creating branch c/d check that branch c does not already exists. Add pack-refs and show-ref test cases. runstatus: do not recurse into subdirectories if not needed
This commit is contained in:
27
dir.c
27
dir.c
@@ -283,7 +283,7 @@ static int dir_exists(const char *dirname, int len)
|
||||
* Also, we ignore the name ".git" (even if it is not a directory).
|
||||
* That likely will not change.
|
||||
*/
|
||||
static int read_directory_recursive(struct dir_struct *dir, const char *path, const char *base, int baselen)
|
||||
static int read_directory_recursive(struct dir_struct *dir, const char *path, const char *base, int baselen, int check_only)
|
||||
{
|
||||
DIR *fdir = opendir(path);
|
||||
int contents = 0;
|
||||
@@ -314,7 +314,6 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
|
||||
|
||||
switch (DTYPE(de)) {
|
||||
struct stat st;
|
||||
int subdir, rewind_base;
|
||||
default:
|
||||
continue;
|
||||
case DT_UNKNOWN:
|
||||
@@ -328,26 +327,30 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
|
||||
case DT_DIR:
|
||||
memcpy(fullname + baselen + len, "/", 2);
|
||||
len++;
|
||||
rewind_base = dir->nr;
|
||||
subdir = read_directory_recursive(dir, fullname, fullname,
|
||||
baselen + len);
|
||||
if (dir->show_other_directories &&
|
||||
(subdir || !dir->hide_empty_directories) &&
|
||||
!dir_exists(fullname, baselen + len)) {
|
||||
/* Rewind the read subdirectory */
|
||||
while (dir->nr > rewind_base)
|
||||
free(dir->entries[--dir->nr]);
|
||||
if (dir->hide_empty_directories &&
|
||||
!read_directory_recursive(dir,
|
||||
fullname, fullname,
|
||||
baselen + len, 1))
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
contents += subdir;
|
||||
|
||||
contents += read_directory_recursive(dir,
|
||||
fullname, fullname, baselen + len, 0);
|
||||
continue;
|
||||
case DT_REG:
|
||||
case DT_LNK:
|
||||
break;
|
||||
}
|
||||
add_name(dir, fullname, baselen + len);
|
||||
contents++;
|
||||
if (check_only)
|
||||
goto exit_early;
|
||||
else
|
||||
add_name(dir, fullname, baselen + len);
|
||||
}
|
||||
exit_early:
|
||||
closedir(fdir);
|
||||
|
||||
pop_exclude_per_directory(dir, exclude_stk);
|
||||
@@ -393,7 +396,7 @@ int read_directory(struct dir_struct *dir, const char *path, const char *base, i
|
||||
}
|
||||
}
|
||||
|
||||
read_directory_recursive(dir, path, base, baselen);
|
||||
read_directory_recursive(dir, path, base, baselen, 0);
|
||||
qsort(dir->entries, dir->nr, sizeof(struct dir_entry *), cmp_name);
|
||||
return dir->nr;
|
||||
}
|
||||
|
||||
@@ -121,6 +121,16 @@ then
|
||||
done
|
||||
fi
|
||||
|
||||
branchdir=$(dirname $branchname)
|
||||
while test "$branchdir" != "."
|
||||
do
|
||||
if git-show-ref --verify --quiet -- "refs/heads/$branchdir"
|
||||
then
|
||||
die "$branchdir already exists."
|
||||
fi
|
||||
branchdir=$(dirname $branchdir)
|
||||
done
|
||||
|
||||
prev=''
|
||||
if git-show-ref --verify --quiet -- "refs/heads/$branchname"
|
||||
then
|
||||
|
||||
70
t/t3210-pack-refs.sh
Executable file
70
t/t3210-pack-refs.sh
Executable file
@@ -0,0 +1,70 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2005 Amos Waterland
|
||||
# Copyright (c) 2006 Christian Couder
|
||||
#
|
||||
|
||||
test_description='git pack-refs should not change the branch semantic
|
||||
|
||||
This test runs git pack-refs and git show-ref and checks that the branch
|
||||
semantic is still the same.
|
||||
'
|
||||
. ./test-lib.sh
|
||||
|
||||
test_expect_success \
|
||||
'prepare a trivial repository' \
|
||||
'echo Hello > A &&
|
||||
git-update-index --add A &&
|
||||
git-commit -m "Initial commit." &&
|
||||
HEAD=$(git-rev-parse --verify HEAD)'
|
||||
|
||||
SHA1=
|
||||
|
||||
test_expect_success \
|
||||
'see if git show-ref works as expected' \
|
||||
'git-branch a &&
|
||||
SHA1=$(< .git/refs/heads/a) &&
|
||||
echo "$SHA1 refs/heads/a" >expect &&
|
||||
git-show-ref a >result &&
|
||||
diff expect result'
|
||||
|
||||
test_expect_success \
|
||||
'see if a branch still exists when packed' \
|
||||
'git-branch b &&
|
||||
git-pack-refs &&
|
||||
rm .git/refs/heads/b &&
|
||||
echo "$SHA1 refs/heads/b" >expect &&
|
||||
git-show-ref b >result &&
|
||||
diff expect result'
|
||||
|
||||
test_expect_failure \
|
||||
'git branch c/d should barf if branch c exists' \
|
||||
'git-branch c &&
|
||||
git-pack-refs &&
|
||||
rm .git/refs/heads/c &&
|
||||
git-branch c/d'
|
||||
|
||||
test_expect_success \
|
||||
'see if a branch still exists after git pack-refs --prune' \
|
||||
'git-branch e &&
|
||||
git-pack-refs --prune &&
|
||||
echo "$SHA1 refs/heads/e" >expect &&
|
||||
git-show-ref e >result &&
|
||||
diff expect result'
|
||||
|
||||
test_expect_failure \
|
||||
'see if git pack-refs --prune remove ref files' \
|
||||
'git-branch f &&
|
||||
git-pack-refs --prune &&
|
||||
ls .git/refs/heads/f'
|
||||
|
||||
test_expect_success \
|
||||
'git branch g should work when git branch g/h has been deleted' \
|
||||
'git-branch g/h &&
|
||||
git-pack-refs --prune &&
|
||||
git-branch -d g/h &&
|
||||
git-branch g &&
|
||||
git-pack-refs &&
|
||||
git-branch -d g'
|
||||
|
||||
test_done
|
||||
Reference in New Issue
Block a user