|
| 1 | +#!/usr/bin/env bats |
| 2 | + |
| 3 | +load addons-common |
| 4 | +load addons-fake |
| 5 | +load addons-repo |
| 6 | + |
| 7 | +setup() { |
| 8 | + repo-new |
| 9 | +} |
| 10 | + |
| 11 | +teardown() { |
| 12 | + repo-clean |
| 13 | + fake-clean |
| 14 | +} |
| 15 | + |
| 16 | +@test "'actualize-work': makes a rebase of the default local branch if there is no remote repository" { |
| 17 | + fake-pass "git rebase master" |
| 18 | + check git-elegant actualize-work |
| 19 | + [[ ${status} -eq 0 ]] |
| 20 | + [[ ! ${lines[*]} =~ "git fetch" ]] |
| 21 | + [[ ${lines[*]} =~ "git rebase master" ]] |
| 22 | +} |
| 23 | + |
| 24 | +@test "'actualize-work': makes a rebase of the default remote branch if there is a remote repository" { |
| 25 | + fake-pass "git remote" "origin" |
| 26 | + fake-pass "git rebase origin/master" |
| 27 | + fake-fail "git rebase master" |
| 28 | + check git-elegant actualize-work |
| 29 | + [[ ${status} -eq 0 ]] |
| 30 | + [[ ${lines[*]} =~ "git fetch" ]] |
| 31 | + [[ ${lines[*]} =~ "git rebase origin/master" ]] |
| 32 | +} |
| 33 | + |
| 34 | +@test "'actualize-work': uses local revision of the default remote branch if the fetch is failed" { |
| 35 | + fake-pass "git remote" "origin" |
| 36 | + fake-fail "git fetch" |
| 37 | + fake-pass "git rebase origin/master" |
| 38 | + fake-fail "git rebase master" |
| 39 | + check git-elegant actualize-work |
| 40 | + [[ ${status} -eq 0 ]] |
| 41 | + [[ ${lines[*]} =~ "git fetch" ]] |
| 42 | + [[ ${lines[*]} =~ "Unable to fetch. The last local revision will be used." ]] |
| 43 | + [[ ${lines[*]} =~ "git rebase origin/master" ]] |
| 44 | +} |
| 45 | + |
| 46 | +@test "'actualize-work': makes a rebase of the given local branch without remote-tracking branch" { |
| 47 | + fake-pass "git rebase branch" |
| 48 | + check git-elegant actualize-work branch |
| 49 | + [[ ${status} -eq 0 ]] |
| 50 | + [[ ${lines[*]} =~ "git rebase branch" ]] |
| 51 | + [[ ! ${lines[*]} =~ "git fetch" ]] |
| 52 | +} |
| 53 | + |
| 54 | +@test "'actualize-work': makes a rebase of the given local branch with remote-tracking branch" { |
| 55 | + fake-pass "git rev-parse --abbrev-ref rt@{upstream}" |
| 56 | + fake-pass "git fetch" |
| 57 | + fake-pass "git rev-parse --abbrev-ref rt@{upstream}" "origin/rt" |
| 58 | + fake-pass "git rebase origin/rt rt" |
| 59 | + fake-pass "git rebase rt" |
| 60 | + check git-elegant actualize-work rt |
| 61 | + [[ ${status} -eq 0 ]] |
| 62 | + [[ ${lines[*]} =~ "git fetch" ]] |
| 63 | + [[ ${lines[*]} =~ "git rebase origin/rt rt" ]] |
| 64 | + [[ ${lines[*]} =~ "git rebase rt" ]] |
| 65 | +} |
| 66 | + |
| 67 | +@test "'actualize-work': makes a rebase of the given remote-tracking branch" { |
| 68 | + fake-pass "git for-each-ref refs/remotes/only/remote" "true" |
| 69 | + fake-pass "git fetch" |
| 70 | + fake-pass "git rebase only/remote" |
| 71 | + check git-elegant actualize-work only/remote |
| 72 | + [[ ${status} -eq 0 ]] |
| 73 | + [[ ${lines[*]} =~ "git fetch" ]] |
| 74 | + [[ ${lines[*]} =~ "git rebase only/remote" ]] |
| 75 | +} |
| 76 | + |
| 77 | +@test "'actualize-work': uses local revision of thegiven remote-tracking branch if the fetch is failed" { |
| 78 | + fake-pass "git rev-parse --abbrev-ref rt@{upstream}" |
| 79 | + fake-fail "git fetch" |
| 80 | + fake-pass "git rev-parse --abbrev-ref rt@{upstream}" "origin/rt" |
| 81 | + fake-pass "git rebase origin/rt rt" |
| 82 | + fake-pass "git rebase rt" |
| 83 | + check git-elegant actualize-work rt |
| 84 | + [[ ${status} -eq 0 ]] |
| 85 | + [[ ${lines[*]} =~ "git fetch" ]] |
| 86 | + [[ ${lines[*]} =~ "Unable to fetch. The last local revision will be used." ]] |
| 87 | + [[ ${lines[*]} =~ "git rebase origin/rt rt" ]] |
| 88 | + [[ ${lines[*]} =~ "git rebase rt" ]] |
| 89 | +} |
| 90 | + |
| 91 | +@test "'actualize-work': uses stash pipe if uncommited changes are present" { |
| 92 | + repo-non-staged-change "A new line..." |
| 93 | + check git-elegant actualize-work |
| 94 | + [[ ${status} -eq 0 ]] |
| 95 | + [[ ${lines[@]} =~ "git stash push --message git-elegant actualize-work auto-stash:" ]] |
| 96 | + [[ ! ${lines[*]} =~ "git fetch" ]] |
| 97 | + [[ ${lines[*]} =~ "git rebase master" ]] |
| 98 | + [[ ${lines[@]} =~ "git stash pop" ]] |
| 99 | +} |
| 100 | + |
| 101 | +@test "'actualize-work': continues an existing rebase process there is an active rebase process" { |
| 102 | + repo "git checkout -b feature1" |
| 103 | + repo "git commit --allow-empty --message First" |
| 104 | + repo "git commit --allow-empty --message Second" |
| 105 | + repo "git rebase --exec 'grep bla-bla *.txt' @~1 || true " |
| 106 | + check git-elegant actualize-work |
| 107 | + [[ ${status} -eq 0 ]] |
| 108 | + [[ ${lines[@]} =~ "git rebase --continue" ]] |
| 109 | + [[ ${lines[@]} =~ "git rebase master" ]] |
| 110 | +} |
0 commit comments