Skip to content

Fix a recently-introduced compile warning #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions builtin/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,7 @@ static int checkout(int submodule_progress)
memset(&opts, 0, sizeof opts);
opts.update = 1;
opts.merge = 1;
opts.clone = 1;
opts.fn = oneway_merge;
opts.verbose_update = (option_verbosity >= 0);
opts.src_index = &the_index;
Expand Down
1 change: 1 addition & 0 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,7 @@ struct checkout {
unsigned force:1,
quiet:1,
not_new:1,
clone:1,
refresh_cache:1;
};
#define CHECKOUT_INIT { NULL, "" }
Expand Down
28 changes: 28 additions & 0 deletions entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,31 @@ static int check_path(const char *path, int len, struct stat *st, int skiplen)
return lstat(path, st);
}

static void mark_colliding_entries(const struct checkout *state,
struct cache_entry *ce, struct stat *st)
{
#if !defined(GIT_WINDOWS_NATIVE) /* inode is always zero on Windows */
int i;

for (i = 0; i < state->istate->cache_nr; i++) {
struct cache_entry *dup = state->istate->cache[i];

if (dup == ce)
break;

if (dup->ce_flags & (CE_MATCHED | CE_VALID | CE_SKIP_WORKTREE))
continue;

if (dup->ce_stat_data.sd_ino == st->st_ino) {
dup->ce_flags |= CE_MATCHED;
break;
}
}
#endif

ce->ce_flags |= CE_MATCHED;
}

/*
* Write the contents from ce out to the working tree.
*
Expand Down Expand Up @@ -455,6 +480,9 @@ int checkout_entry(struct cache_entry *ce,
return -1;
}

if (state->clone)
mark_colliding_entries(state, ce, &st);

/*
* We unlink the old file, to get the new one with the
* right permissions (including umask, which is nasty
Expand Down
8 changes: 7 additions & 1 deletion t/t5601-clone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -624,10 +624,16 @@ test_expect_success 'clone on case-insensitive fs' '
git hash-object -w -t tree --stdin) &&
c=$(git commit-tree -m bogus $t) &&
git update-ref refs/heads/bogus $c &&
git clone -b bogus . bogus
git clone -b bogus . bogus 2>warning
)
'

test_expect_success !MINGW,!CYGWIN,CASE_INSENSITIVE_FS 'colliding file detection' '
grep X icasefs/warning &&
grep x icasefs/warning &&
test_i18ngrep "the following paths have collided" icasefs/warning
'

partial_clone () {
SERVER="$1" &&
URL="$2" &&
Expand Down
28 changes: 28 additions & 0 deletions unpack-trees.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,12 @@ static int check_updates(struct unpack_trees_options *o)
state.refresh_cache = 1;
state.istate = index;

if (o->clone) {
state.clone = 1;
for (i = 0; i < index->cache_nr; i++)
index->cache[i]->ce_flags &= ~CE_MATCHED;
}

progress = get_progress(o);

if (o->update)
Expand Down Expand Up @@ -423,6 +429,28 @@ static int check_updates(struct unpack_trees_options *o)
errs |= finish_delayed_checkout(&state);
if (o->update)
git_attr_set_direction(GIT_ATTR_CHECKIN, NULL);

if (o->clone) {
int printed_warning = 0;

for (i = 0; i < index->cache_nr; i++) {
struct cache_entry *ce = index->cache[i];

if (!(ce->ce_flags & CE_MATCHED))
continue;

if (!printed_warning) {
warning(_("the following paths have collided (e.g. case-sensitive paths\n"
"on a case-insensitive filesystem) and only one from the same\n"
"colliding group is in the working tree:\n"));
printed_warning = 1;
}

fprintf(stderr, " '%s'\n", ce->name);
ce->ce_flags &= ~CE_MATCHED;
}
}

return errs != 0;
}

Expand Down
1 change: 1 addition & 0 deletions unpack-trees.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ struct unpack_trees_options {
unsigned int reset,
merge,
update,
clone,
index_only,
nontrivial_merge,
trivial_merges_only,
Expand Down