diff options
author | Russell Belfer <rb@github.com> | 2014-04-02 12:07:27 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2014-04-22 15:23:43 -0700 |
commit | 24d17de255caa57b01c0c758e6fc81aad493806e (patch) | |
tree | 5d4831849777583e4cd2d6b46ac6a7a532fa468b /src/checkout.c | |
parent | a32d684f866e7710fd139d69ad5d1a8d0ae527c4 (diff) | |
download | libgit2-24d17de255caa57b01c0c758e6fc81aad493806e.tar.gz |
Make stash and checkout ignore contained repos
To emulate git, stash should not remove untracked git repositories
inside the parent repo, and checkout's REMOVE_UNTRACKED should
also skip over these items.
`git stash` actually prints a warning message for these items.
That should be possible with a checkout notify callback if you
wanted to, although it would require a bit of extra logic as things
are at the moment.
Diffstat (limited to 'src/checkout.c')
-rw-r--r-- | src/checkout.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/checkout.c b/src/checkout.c index 0b385226b..04b2a66b2 100644 --- a/src/checkout.c +++ b/src/checkout.c @@ -259,6 +259,17 @@ static int checkout_action_no_wd( return checkout_action_common(action, data, delta, NULL); } +static bool wd_item_is_removable(git_iterator *iter, const git_index_entry *wd) +{ + git_buf *full = NULL; + + if (wd->mode != GIT_FILEMODE_TREE) + return true; + if (git_iterator_current_workdir_path(&full, iter) < 0) + return true; + return !full || !git_path_contains(full, DOT_GIT); +} + static int checkout_action_wd_only( checkout_data *data, git_iterator *workdir, @@ -307,11 +318,13 @@ static int checkout_action_wd_only( /* found in index */; else if (git_iterator_current_is_ignored(workdir)) { notify = GIT_CHECKOUT_NOTIFY_IGNORED; - remove = ((data->strategy & GIT_CHECKOUT_REMOVE_IGNORED) != 0); + remove = ((data->strategy & GIT_CHECKOUT_REMOVE_IGNORED) != 0) && + wd_item_is_removable(workdir, wd); } else { notify = GIT_CHECKOUT_NOTIFY_UNTRACKED; - remove = ((data->strategy & GIT_CHECKOUT_REMOVE_UNTRACKED) != 0); + remove = ((data->strategy & GIT_CHECKOUT_REMOVE_UNTRACKED) != 0) && + wd_item_is_removable(workdir, wd); } error = checkout_notify(data, notify, NULL, wd); |