|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | | -origin_path="/tmp/impacted/repo_origin" |
4 | | -source_path="/tmp/impacted/source_repo" |
5 | | -new_clone_path="/tmp/impacted/new_clone" |
6 | | -no_remote_path="/tmp/impacted/no_remote" |
7 | | -ghub_actions_path="/tmp/impacted/ghub_actions_clone" |
| 3 | +# IMPORTANT: always use relative paths, as tests move the folders to temp dirs |
| 4 | +base_path="/tmp/impacted/" |
| 5 | +origin_path="repo_origin" |
| 6 | +source_path="source_repo" |
| 7 | +new_clone_path="new_clone" |
| 8 | +no_remote_path="no_remote" |
| 9 | +ghub_actions_path="ghub_actions_clone" |
| 10 | + |
| 11 | +base_branch="master" |
| 12 | +feature_branch="feature" |
| 13 | + |
| 14 | +mkdir -p $base_path |
| 15 | +cd $base_path |
8 | 16 |
|
9 | 17 | # create origin |
10 | 18 | mkdir -p $origin_path |
11 | | -(cd $origin_path && git init --bare) |
| 19 | +cd $origin_path && git init --bare |
| 20 | +cd .. |
12 | 21 |
|
13 | 22 | # create git repo |
14 | | -mkdir -p $source_path |
15 | | -(cd $source_path && git init && git remote add origin $origin_path) |
16 | | -(cd $source_path && echo "Hello, world!" >>README.md && git add README.md && git commit -m "Initial commit") |
17 | | -(cd $source_path && echo "Hello, world!" >>README.md && git add README.md && git commit -m "Update README") |
18 | | -(cd $source_path && git push origin master) |
19 | | - |
20 | | -base_branch="master" |
21 | | -feature_branch="feature" |
22 | | -base_commit=$(cd $source_path && git rev-parse HEAD) |
23 | | - |
| 23 | +mkdir -p $source_path && cd $source_path |
| 24 | +git init && git remote add origin "../$origin_path" |
| 25 | +echo "Hello, world!" >>README.md && git add README.md && git commit -m "Initial commit" |
| 26 | +echo "Hello, world!" >>README.md && git add README.md && git commit -m "Update README" |
| 27 | +git push origin master |
| 28 | +base_commit=$(git rev-parse HEAD) |
24 | 29 | # create feature branch |
25 | | -(cd $source_path && git checkout -b $feature_branch) |
26 | | -(cd $source_path && echo "Feature branch change" >>README.md && git add README.md && git commit -m "Updated README") |
27 | | -(cd $source_path && git push origin $feature_branch) |
| 30 | +git checkout -b $feature_branch |
| 31 | +echo "Feature branch change" >>README.md && git add README.md && git commit -m "Feature branch commit" |
| 32 | +git push origin $feature_branch |
| 33 | +cd .. |
28 | 34 |
|
29 | | -# create new clone |
30 | | -mkdir -p $new_clone_path |
31 | | -(cd $new_clone_path && git init) |
32 | | -(cd $new_clone_path && git remote add origin $origin_path) |
33 | | -(cd $new_clone_path && git fetch origin $feature_branch) |
34 | | -(cd $new_clone_path && git reset --hard "origin/$feature_branch") |
| 35 | +# clone with remote branch cloned into master branch of local repo |
| 36 | +mkdir -p $new_clone_path && cd $new_clone_path |
| 37 | +git init |
| 38 | +git remote add origin "../$origin_path" |
| 39 | +git fetch origin $feature_branch |
| 40 | +git reset --hard "origin/$feature_branch" |
| 41 | +cd .. |
35 | 42 |
|
36 | 43 | # remote pointing to non existing repo |
37 | | -mkdir -p $no_remote_path |
38 | | -(cd $no_remote_path && git init) |
39 | | -(cd $no_remote_path && echo "base branch file" >>README.md && git add README.md && git commit -m "first commit") |
40 | | -(cd $no_remote_path && git remote add origin "git@git.com:datadog/non_existing_repo.git") |
| 44 | +mkdir -p $no_remote_path && cd $no_remote_path |
| 45 | +git init |
| 46 | +echo "base branch file" >>README.md && git add README.md && git commit -m "first commit" |
| 47 | +git remote add origin "git@git.com:datadog/non_existing_repo.git" |
| 48 | +cd .. |
41 | 49 |
|
42 | 50 | # github actions style clone |
43 | | -mkdir -p $ghub_actions_path |
44 | | -(cd $ghub_actions_path && git init) |
45 | | -(cd $ghub_actions_path && git remote add origin $origin_path) |
46 | | -(cd $ghub_actions_path && git fetch --no-tags --prune --no-recurse-submodules origin $feature_branch) |
47 | | -(cd $ghub_actions_path && git checkout --progress --force -B $feature_branch "refs/remotes/origin/$feature_branch") |
| 51 | +mkdir -p $ghub_actions_path && cd $ghub_actions_path |
| 52 | +git init |
| 53 | +git remote add origin "../$origin_path" |
| 54 | +git fetch --no-tags --prune --no-recurse-submodules origin $feature_branch |
| 55 | +git checkout --progress --force -B $feature_branch "refs/remotes/origin/$feature_branch" |
| 56 | +cd .. |
48 | 57 |
|
49 | 58 | echo "BASE COMMIT: $base_commit" |
50 | 59 |
|
51 | 60 | # cleanup |
52 | | -(cd $source_path && rm -rf .git/hooks .git/info .git/logs .git/COMMIT_EDITMSG .git/description .git/index && mv .git git) |
53 | | -(cd $new_clone_path && rm -rf .git/hooks .git/info .git/logs .git/COMMIT_EDITMSG .git/description .git/index && mv .git git) |
54 | | -(cd $no_remote_path && rm -rf .git/hooks .git/info .git/logs .git/COMMIT_EDITMSG .git/description .git/index && mv .git git) |
55 | | -(cd $ghub_actions_path && rm -rf .git/hooks .git/info .git/logs .git/COMMIT_EDITMSG .git/description .git/index && mv .git git) |
| 61 | +(cd $origin_path && rm -rf hooks info logs COMMIT_EDITMSG description index README.md) |
| 62 | +(cd $source_path && rm -rf .git/hooks .git/info .git/logs .git/COMMIT_EDITMSG .git/description .git/index README.md && mv .git git) |
| 63 | +(cd $new_clone_path && rm -rf .git/hooks .git/info .git/logs .git/COMMIT_EDITMSG .git/description .git/index README.md && mv .git git) |
| 64 | +(cd $no_remote_path && rm -rf .git/hooks .git/info .git/logs .git/COMMIT_EDITMSG .git/description .git/index README.md && mv .git git) |
| 65 | +(cd $ghub_actions_path && rm -rf .git/hooks .git/info .git/logs .git/COMMIT_EDITMSG .git/description .git/index README.md && mv .git git) |
0 commit comments