Skip to content
Merged
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
6 changes: 5 additions & 1 deletion bin/git-merge-repo
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ git subtree add -P "$prefix" "$repo" "$branch" "${@:4}"
message=$(git log -1 --pretty=%B)

if test $flat -eq 1; then
old_stash=$(git rev-parse -q --verify refs/stash)
git stash -u
shopt -s dotglob
mv -i "$prefix"/* ./
git undo
git add .
git commit -am "$message"
git stash apply
if test "$(git rev-parse -q --verify refs/stash)" != "$old_stash"; then
git stash apply
fi
rm -drf "$prefix"
fi
53 changes: 53 additions & 0 deletions tests/git-merge-repo.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# shellcheck shell=bash

source "$BATS_TEST_DIRNAME/test_util.sh"

setup_file() {
test_util.setup_file
test_util.install_command merge-repo
test_util.install_command undo
}

setup() {
test_util.cd_test

mkdir other
(
cd other
test_util.git_init
printf '%s\n' 'lib' > lib.txt
printf '%s\n' 'build/' > .gitignore
git add .
git commit -m "lib"
)

mkdir main
cd main
test_util.git_init
printf '%s\n' 'app' > app.txt
git add .
git commit -m "app"
}

@test "merging into the current folder keeps dotfiles at the root" {
run git merge-repo ../other main .
assert_success

run git ls-tree -r --name-only HEAD
assert_output $'.gitignore\napp.txt\nlib.txt'
run git status --porcelain
assert_output ''
}

@test "merging into the current folder leaves an older stash alone" {
printf '%s\n' 'old work' >> app.txt
git stash

run git merge-repo ../other main .
assert_success

run cat app.txt
assert_output 'app'
run git stash list
assert_output --partial 'WIP on main'
}
Loading