gitbulk 0.0.7.364823 → 0.0.8.364829
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/git-repo-sync/LICENSE +29 -0
- data/lib/git-repo-sync/README.md +273 -0
- data/lib/git-repo-sync/git-sync.sh +31 -0
- data/lib/git-repo-sync/repo_settings/default_sync_project.sh +146 -0
- data/lib/git-repo-sync/request-git-sync.sh +44 -0
- data/lib/git-repo-sync/util/change_detector.sh +64 -0
- data/lib/git-repo-sync/util/gawk/base_processing.gawk +87 -0
- data/lib/git-repo-sync/util/gawk/change_detector.gawk +106 -0
- data/lib/git-repo-sync/util/gawk/global.gawk +47 -0
- data/lib/git-repo-sync/util/gawk/global_const.gawk +33 -0
- data/lib/git-repo-sync/util/gawk/global_util.gawk +55 -0
- data/lib/git-repo-sync/util/gawk/input_processing.gawk +144 -0
- data/lib/git-repo-sync/util/gawk/post_fetch_processing.gawk +585 -0
- data/lib/git-repo-sync/util/gawk/pre_fetch_processing.gawk +187 -0
- data/lib/git-repo-sync/util/repo_create.sh +72 -0
- data/lib/git-repo-sync/util/restore-after-crash.sh +23 -0
- data/lib/git-repo-sync/util/set_base_logic.sh +2 -0
- data/lib/git-repo-sync/util/set_env.sh +232 -0
- data/lib/git-repo-sync/util/sync_pass.sh +329 -0
- data/lib/gitbulk/version.rb +1 -1
- metadata +20 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cd7f800a675bd30ba38b8f91c543e852766dafe1c14bca17c9a576b31b224952
|
|
4
|
+
data.tar.gz: 3f93c0eb33ed223ccb386497b3a1d84a46f653ee2036dbb1dd49b55f9f44c22f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3bbee595f163d84975d8a8c94b3205ddf5065a7ef9bb7bf08a06efd1d4a1766fe7c5139a20a21e6b546a32b759bac963900fb639a46a026761132cd266e11cc5
|
|
7
|
+
data.tar.gz: dab1e2b185da33e5a3d7606c35b1cf419ac8a70a58de865619de6101d8310b7c261fff57c197da7cf7928bcc5eec09bda8ec65337d984625af7e59a26143e14e
|
data/Gemfile.lock
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020, Ilya Tretyakov, it3xl.ru, git-repo-sync, https://github.com/it3xl/git-repo-sync
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
10
|
+
list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
|
14
|
+
and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
17
|
+
contributors may be used to endorse or promote products derived from
|
|
18
|
+
this software without specific prior written permission.
|
|
19
|
+
|
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
# git-repo-sync
|
|
2
|
+
|
|
3
|
+
## Synchronization of Branches between Remote Git-repositories
|
|
4
|
+
|
|
5
|
+
* The **git-repo-sync** is a bash script that synchronizes branches between two remote Git-repositories.
|
|
6
|
+
* Git-tags are not synchronized.
|
|
7
|
+
* You configure once what branches to synchronize and how.
|
|
8
|
+
* You have to investigate some time to understand **git-repo-sync** conflict solving strategies and configuring.
|
|
9
|
+
* Your run **git-repo-sync** periodically, preferebly every few minutes.
|
|
10
|
+
|
|
11
|
+
*Warning!* Before reading the following keep in mind the difference between **local** and **remote** Git repositories.
|
|
12
|
+
|
|
13
|
+
If your people push (commit) often to a single synchronized Git-branch and do it to different remote Git-repositories, then:
|
|
14
|
+
|
|
15
|
+
* Run **git-repo-sync** before pushing to such the branch.
|
|
16
|
+
|
|
17
|
+
### Manual Action of Synchronization
|
|
18
|
+
|
|
19
|
+
If someone pushed to the same branch (to another remote repo) in between the runing of **git-repo-sync** and your pusing. In this case:
|
|
20
|
+
|
|
21
|
+
* Run **git-repo-sync**
|
|
22
|
+
* Udpate your local repository (git fetch).
|
|
23
|
+
* Check if your commits (push) wasn't deleted from your remote Git-repository. (FYI. You local commits in your local repository will not be changed!)
|
|
24
|
+
* If it was deleted in the remote repo:
|
|
25
|
+
* merge, rebase, etc., your local branch over the latest remote commits;
|
|
26
|
+
* repeat Git-push for your branch.
|
|
27
|
+
* Repeat everything until your pushed branch will be in expected commits in your remote Git-repository.
|
|
28
|
+
|
|
29
|
+
This situation is covered by notifications but you have to configure this by yourlself in your enterprise environment.
|
|
30
|
+
|
|
31
|
+
## Use Cases
|
|
32
|
+
|
|
33
|
+
* Adhesion of Git-remote-repositories of clients and software/support suppliers. Temporary or permanent.
|
|
34
|
+
* Independence from an external remote Git repository if it is slow and could be out of service time after time.
|
|
35
|
+
* You software teams have independent Git remote repositories.
|
|
36
|
+
|
|
37
|
+
## Requirements
|
|
38
|
+
|
|
39
|
+
* Install Git
|
|
40
|
+
* Use bash to run **git-repo-sync**. (It is not tested for zsh)
|
|
41
|
+
* Tune any automation to run **git-repo-sync** periodically - crones, schedulers, Jenkins, GitLab-CI, etc. Or run it periodically yourself.
|
|
42
|
+
|
|
43
|
+
This is enough for Windows, Arch based Linux (Manjaro), GNU based Linux
|
|
44
|
+
|
|
45
|
+
### macOS Additional Requirements
|
|
46
|
+
|
|
47
|
+
* Update bash by running (restart your shell after this)
|
|
48
|
+
* `brew install bash`
|
|
49
|
+
* Install gAWK (GNU AWK)
|
|
50
|
+
* `brew install gawk`
|
|
51
|
+
|
|
52
|
+
### Ubuntu Additional Requirements
|
|
53
|
+
|
|
54
|
+
* Install gAWK (GNU AWK).
|
|
55
|
+
* consider [this case](https://askubuntu.com/questions/561621/choosing-awk-version-on-ubuntu-14-04/561626#561626).
|
|
56
|
+
|
|
57
|
+
### Other Linux Additional Requirements
|
|
58
|
+
|
|
59
|
+
* Check gawk presence. Run `gawk '{ exit; }'` or see https://unix.stackexchange.com/a/236666/207074
|
|
60
|
+
* Check that bash version is 4.2 or above.
|
|
61
|
+
|
|
62
|
+
## How to use
|
|
63
|
+
|
|
64
|
+
Copy **git-repo-sync** somewhere
|
|
65
|
+
|
|
66
|
+
git clone https://github.com/it3xl/git-repo-sync.git
|
|
67
|
+
|
|
68
|
+
Let **git-repo-sync** know location of your remote Git repositories.<br/>
|
|
69
|
+
Modify `url_a` and `url_b` variables in [default_sync_project.sh](https://github.com/it3xl/git-repo-sync/blob/master/repo_settings/default_sync_project.sh).<br/>
|
|
70
|
+
You can use URL-s and file paths.
|
|
71
|
+
|
|
72
|
+
url_a=https://example.com/git/my_repo.git
|
|
73
|
+
|
|
74
|
+
url_b='/c/my-folder/my-local-git-repo-folder'
|
|
75
|
+
|
|
76
|
+
Run periodically the `git-sync.sh` file, which is located in the root of **git-repo-sync**.
|
|
77
|
+
|
|
78
|
+
bash git-sync.sh
|
|
79
|
+
|
|
80
|
+
The `git-sync.sh` will tell you if there are any troubles. For example you need to update awk to gAWK in Ubuntu.
|
|
81
|
+
|
|
82
|
+
## The Trade-off
|
|
83
|
+
|
|
84
|
+
_The Trade-off_ is an automated Git-conflict solving logic of git-repo-sync.
|
|
85
|
+
|
|
86
|
+
Even if you run **git-repo-sync** periodically and often, you still have a chance to get a Git-conflict. But a small chance.<br/>
|
|
87
|
+
So, you must know what to do in case of Git-conflicts solved by git-repo-sync.
|
|
88
|
+
|
|
89
|
+
### Minimize chances of The Trade-off
|
|
90
|
+
|
|
91
|
+
Run **git-repo-sync** before Git-pushing. I.e. synchronize your both Git-remote-repos before pushing into any of them.<br/>
|
|
92
|
+
In this case, Git will be responsible for conflict resolution, not **git-repo-sync**.
|
|
93
|
+
|
|
94
|
+
### When git-repo-sync will be solving the conflicts.
|
|
95
|
+
|
|
96
|
+
You should have the both
|
|
97
|
+
|
|
98
|
+
- You run **git-repo-sync** rarely. I.e. someone aready pushed commites exactly to your branch after last running of **git-repo-sync**.
|
|
99
|
+
- And you and your teammate have pushed changes to the same Git-branch but through different remote repositories and your remote repositories are no synchronized between your Git-pushes.
|
|
100
|
+
|
|
101
|
+
Basically, you don't know about **git-repo-sync** until you are in this situation.
|
|
102
|
+
|
|
103
|
+
### Behavior of git-repo-sync in case of Git-conflicst
|
|
104
|
+
|
|
105
|
+
**git-repo-sync** sees a Git-conflict and uses one of Conflict Solving strategies described below.<br/>
|
|
106
|
+
As a result, you should provide the below steps to fix The Trade-off.
|
|
107
|
+
|
|
108
|
+
### Your steps to fix The Trade-off
|
|
109
|
+
|
|
110
|
+
The main idea is "Re-push your local Git-commit in case of a conflict".
|
|
111
|
+
|
|
112
|
+
- Run **git-repo-sync** to synchronize both Git-remote-repositories (if you have no periodical auto-runs).
|
|
113
|
+
|
|
114
|
+
- Upload changes from your remote Git-repository to your local repository.
|
|
115
|
+
- Check if you local commit have lost its remote counterpart. I.e. the commit exist only in your local repository.
|
|
116
|
+
- Performe Git-merge/rebase of your local commit.
|
|
117
|
+
- Performe Git-push of your changes.
|
|
118
|
+
|
|
119
|
+
- Run **git-repo-sync** to synchronize your changes with changes from another side Git-remote-repository (if you have no periodical auto-runs).
|
|
120
|
+
|
|
121
|
+
### How do I know if there were Git-conflicts
|
|
122
|
+
|
|
123
|
+
- Check it manually. This is described in the above steps.
|
|
124
|
+
- **git-repo-sync** has notifications over plain text files. Ask your DevOps to distribute it.
|
|
125
|
+
|
|
126
|
+
## Using On Linux
|
|
127
|
+
|
|
128
|
+
Run `git-sync.sh` and it will tell you what **git-repo-sync** needs.<br/>
|
|
129
|
+
In most cases you have to install gAWK. This applies to Ubuntu.<br/>
|
|
130
|
+
Docker Alpine Linux images require *bash* and *gAWK* to be installed.<br/>
|
|
131
|
+
You have to update the *bash* if you use an extra old Linux distro.
|
|
132
|
+
|
|
133
|
+
## Using on Windows
|
|
134
|
+
|
|
135
|
+
Ha! You're lucky. You have to do nothing and have five options to run **git-repo-sync**.
|
|
136
|
+
|
|
137
|
+
Open PowerShell or CMD in the **git-repo-sync** folder and run one of three.
|
|
138
|
+
|
|
139
|
+
"C:\Program Files\Git\bin\bash.exe" git-sync.sh
|
|
140
|
+
"C:\Program Files\Git\usr\bin\bash.exe" git-sync.sh
|
|
141
|
+
"C:\Program Files\Git\git-bash.exe" git-sync.sh
|
|
142
|
+
|
|
143
|
+
Or you can reinstall Git and integrate the bash into your Windows during installation. Then run
|
|
144
|
+
|
|
145
|
+
bash git-sync.sh
|
|
146
|
+
|
|
147
|
+
Or you can try to update the PATH environment variable. Try to add the following (that wasn't tested by me)
|
|
148
|
+
|
|
149
|
+
;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin
|
|
150
|
+
|
|
151
|
+
## Do not synchronize all branches
|
|
152
|
+
|
|
153
|
+
Despite that there are [fair cases](https://github.com/it3xl/git-repo-sync/issues/3#issuecomment-771494886) when it is useful to sync all branches, this is not always a good idea.<br/>
|
|
154
|
+
Some well know Git-servers block some branches in different ways. Some of them create "trash"-branches which you do not want to see synchronized.<br/>
|
|
155
|
+
|
|
156
|
+
So, you can synchronize branches that have special prefixes only.<br/>
|
|
157
|
+
You could configure these prefixes in [default_sync_project.sh](https://github.com/it3xl/git-repo-sync/blob/master/repo_settings/default_sync_project.sh) configuration file.<br/>
|
|
158
|
+
What's important, these prefixes are related to correspondent *conflict solving strategies*.
|
|
159
|
+
|
|
160
|
+
## Conflict Solving Strategies
|
|
161
|
+
|
|
162
|
+
### The Victim Strategy
|
|
163
|
+
|
|
164
|
+
By default all branches are synced under this strategy.<br/>
|
|
165
|
+
You can do whatever you want with such branches from both sides (repositories).<br/>
|
|
166
|
+
In case of commit conflicts, any newest commit will win.<br/>
|
|
167
|
+
You can relocate branches to any position, delete and move them back in history if you run **git-repo-sync** regularly.<br/>
|
|
168
|
+
|
|
169
|
+
Use the following variable to limit branches synchronized by this strategy.
|
|
170
|
+
|
|
171
|
+
victim_branches_prefix=@
|
|
172
|
+
|
|
173
|
+
The most common value for victim_branches_prefix is "@".<br/>
|
|
174
|
+
In this case only branches that start with `@` will be synchronized.
|
|
175
|
+
E.g. `@dev`, `@dev-staging`, `@test`, `@test-staging`, `@my-feature`, etc.
|
|
176
|
+
|
|
177
|
+
### The Conventional Strategy
|
|
178
|
+
|
|
179
|
+
By using this strategy you limit what your teammates may do from another side repository with branches on your side remote repository.
|
|
180
|
+
|
|
181
|
+
Branches with the following prefix will be owned by the repo from [url_a](https://github.com/it3xl/git-repo-sync/blob/master/repo_settings/default_sync_project.sh) variable. Let's call it *A side*.
|
|
182
|
+
|
|
183
|
+
side_a_conventional_branches_prefix=client-
|
|
184
|
+
|
|
185
|
+
Branches with the following prefix will be owned by the repo from [url_b](https://github.com/it3xl/git-repo-sync/blob/master/repo_settings/default_sync_project.sh) variable. Let's call it *B side*.
|
|
186
|
+
|
|
187
|
+
side_b_conventional_branches_prefix=vendor-
|
|
188
|
+
|
|
189
|
+
Other examples of prefix pairs: `a-`, `b-`; `microsoft/`, `google/`; `foo-`, `bar-`;
|
|
190
|
+
|
|
191
|
+
On the owning side repo: You can do whatever you want with such branches.
|
|
192
|
+
|
|
193
|
+
On a repo of another side:<br/>
|
|
194
|
+
You can do fast-forward updates and merges.<br/>
|
|
195
|
+
You can move such branches back in Git-history if you run **git-repo-sync** periodically.
|
|
196
|
+
|
|
197
|
+
All commit conflicts will be solved in favor of the owning side.<br/>
|
|
198
|
+
|
|
199
|
+
### Other Unimplemented Strategies
|
|
200
|
+
|
|
201
|
+
Just propouse something interesting.<br/>
|
|
202
|
+
BTW, the Victim and Conventional approaches cover 80% of cases you need (I beleive).
|
|
203
|
+
|
|
204
|
+
## Disaster Protection
|
|
205
|
+
|
|
206
|
+
People have to make mistakes to become better. This is normal. But let's protect our clients from such the mistakes.<br/>
|
|
207
|
+
Define *sync_enabling_branch* variable
|
|
208
|
+
|
|
209
|
+
sync_enabling_branch=it3xl_git_repo_sync_enabled
|
|
210
|
+
|
|
211
|
+
Its value may represent any branch name.<br/>
|
|
212
|
+
Examples: `@test`, `client-prod`, `vendor-master`, `it3xl_git_repo_sync_enabled`.<br/>
|
|
213
|
+
|
|
214
|
+
The **git-repo-sync** will check if such a branch exist in both remote repositories and that it has the same or related commits, i.e. its commits are located in the same Git-tree.<br/>
|
|
215
|
+
This will protect you from occasional adhesion of unrelated git-repositories and deletion of branches that have the same names.<br/>
|
|
216
|
+
Git may store many independent projects (trees) in the same repository and this is uncommon behavior for many users.
|
|
217
|
+
|
|
218
|
+
I advise to use `it3xl_git_repo_sync_enabled` branch name to make this explicit for others that their remote Git-repo is synchronized with another remote repo.<br/>
|
|
219
|
+
They could search for the word *it3xl_git_repo_sync_enabled* in the Internet and understand the applied sync solution.
|
|
220
|
+
|
|
221
|
+
Be aware that a branch mentioned in the `sync_enabling_branch` variable will be alwasy synchronized by **git-repo-sync**.<br/>
|
|
222
|
+
Probably this is not a good idea to specify here the `master` branch name because a branch mentioned in `sync_enabling_branch` will be synchronized under the Victim strategy. But you can specify there a branch with one of your conventional prefixes for the Conventional syncing of it. For example `client-master`.
|
|
223
|
+
|
|
224
|
+
## Notes, Drawbacks & Limitations
|
|
225
|
+
* Usage with SSH isn't tested but possible.
|
|
226
|
+
* **git-repo-sync** is resilient for HTTP fails and interruptions.
|
|
227
|
+
* It has protections from an occasional deletion of your entire remote repository.
|
|
228
|
+
* Arbitrary Git-history rewriting is supported.
|
|
229
|
+
* Within a single installation, **git-repo-sync** can synchronize as many pairs of Git-repositories as you want. Every sync pair is a sync project for **git-repo-sync**.
|
|
230
|
+
* Git-tags are not synchronized.
|
|
231
|
+
* Remarks why: Some Git-servers block manipulations with Git-tags. Time was saved for research and covering all possible cases. Another repo's tags created issues for Git-tag based CI/CD-s.
|
|
232
|
+
* **git-repo-sync** doesn't attempt to do Git-merge or rebase. Just FYI.
|
|
233
|
+
|
|
234
|
+
## Support Operations
|
|
235
|
+
|
|
236
|
+
### Remote Repo Replacing Support
|
|
237
|
+
|
|
238
|
+
This is a real case of my customer. You may want to synchronize your existing Git-repo with a Git-repo of your new software parnter.
|
|
239
|
+
|
|
240
|
+
Option 1.<br/>
|
|
241
|
+
Create a new git-repo-sync project and use it (project description file or environment variables).
|
|
242
|
+
|
|
243
|
+
Option 2.<br/>
|
|
244
|
+
Modify your existing project. Update its description file or environment variables.<br/>
|
|
245
|
+
Delete `git-repo-sync/sync-projects/<your-sync-project-name>` directory.<br/>
|
|
246
|
+
Start synchronization as usual.
|
|
247
|
+
|
|
248
|
+
Option 3.<br/>
|
|
249
|
+
Your Git-repository is extra huge and you can't recreate it. This is a TL;DR. Ask a Git-professional for a help.
|
|
250
|
+
|
|
251
|
+
## Known Issues
|
|
252
|
+
|
|
253
|
+
### It is still untracked
|
|
254
|
+
`Something went wrong for <your-branch>. It is still untracked.
|
|
255
|
+
Possibly the program or the network were interrupted.`
|
|
256
|
+
|
|
257
|
+
* Disable your antivirus or Check Point.
|
|
258
|
+
* Check if this branch is blocked by your Git-server.
|
|
259
|
+
|
|
260
|
+
## Automation support
|
|
261
|
+
* **git-repo-sync** works with remote Git repositories asynchronously, by default.
|
|
262
|
+
* It works much faster under \*nix OS-es because Git-bash on Windows is slower. But compare to network latency, this is nothing.
|
|
263
|
+
* You can separate change detection and synchronization phases of **git-repo-sync** for readability of CI/CD logs.
|
|
264
|
+
* Multiple configuration capabilities are supported. Environment, configuration files, combination of them.
|
|
265
|
+
* Integration with **bash Git Credential Helper - [git-cred](https://github.com/it3xl/bash-git-credential-helper)** to obtain credentials from a parent shell environment.
|
|
266
|
+
* You shouldn't do anything in case of connectivity fails. Continue to run **git-repo-sync** periodically and everything will be restored automatically.
|
|
267
|
+
* After every synchronization, analyze notification files to send notifications about branch deletions or commit conflict solving.
|
|
268
|
+
See `git-repo-sync/sync-projects/<your-sync-project-name>/file-signals/`
|
|
269
|
+
* `notify_solving` - for conflict solving
|
|
270
|
+
* `notify_del` - for deletions
|
|
271
|
+
* See [instructions](https://github.com/it3xl/git-repo-sync/blob/master/repo_settings/default_sync_project.sh) on how to configure more synchronization pairs of remote Git repositories.
|
|
272
|
+
* Number of pairs is unlimited. Every pair is a separate sync project.
|
|
273
|
+
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# it3xl.ru git-repo-sync https://github.com/it3xl/git-repo-sync
|
|
2
|
+
|
|
3
|
+
set -euf +x -o pipefail
|
|
4
|
+
|
|
5
|
+
#echo
|
|
6
|
+
#echo Start $(basename $BASH_SOURCE)
|
|
7
|
+
|
|
8
|
+
invoke_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
9
|
+
source "$invoke_path/util/set_env.sh" "$@"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
echo
|
|
14
|
+
source "$path_git_sync_util/repo_create.sh"
|
|
15
|
+
cd "$path_sync_repo"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
rm -f "$env_notify_del_file"
|
|
19
|
+
rm -f "$env_notify_solving_file"
|
|
20
|
+
|
|
21
|
+
source "$path_git_sync_util/restore-after-crash.sh"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
source "$path_git_sync_util/sync_pass.sh"
|
|
25
|
+
source "$path_git_sync_util/sync_pass.sh"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
echo
|
|
29
|
+
echo @ RESULT: Successfully completed with $git_sync_pass_num_required sync-pass'/'es.
|
|
30
|
+
#echo
|
|
31
|
+
#echo End $(basename $BASH_SOURCE)
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# it3xl.ru git-repo-sync https://github.com/it3xl/git-repo-sync
|
|
2
|
+
#
|
|
3
|
+
## Post your questions on https://github.com/it3xl/git-repo-sync/issues
|
|
4
|
+
## I will be glad to explain the ambiguities and to improve this instruction for others.
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# Configure location of your remote Git repositories.
|
|
8
|
+
#
|
|
9
|
+
#url_a=/tmp/bb/gitlab/
|
|
10
|
+
#
|
|
11
|
+
#url_b=/tmp/bb/github/
|
|
12
|
+
|
|
13
|
+
# Don't sync all branches. Synchronize branches with the following prefix.
|
|
14
|
+
#
|
|
15
|
+
# victim_branches_prefix=@
|
|
16
|
+
|
|
17
|
+
# Prevent catastrophe!
|
|
18
|
+
# Don't sync repositories without the specified branch in the same Git-tree (same or related commits).
|
|
19
|
+
#
|
|
20
|
+
# sync_enabling_branch=it3xl_git_repo_sync_enabled
|
|
21
|
+
|
|
22
|
+
# Limit branch manipulations for another repository side.
|
|
23
|
+
# See "Conventional Syncing strategy" below.
|
|
24
|
+
#
|
|
25
|
+
# side_a_conventional_branches_prefix=client-
|
|
26
|
+
# side_b_conventional_branches_prefix=vendor-
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
# Automation integration. See details below
|
|
30
|
+
#
|
|
31
|
+
# git_sync_project_folder=my-sync-project
|
|
32
|
+
#
|
|
33
|
+
# use_bash_git_credential_helper=1
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
#
|
|
37
|
+
##
|
|
38
|
+
### Descriptions & Explanations
|
|
39
|
+
##
|
|
40
|
+
#
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
## This Configuration File
|
|
44
|
+
#
|
|
45
|
+
# Variables mentioned in this file configure synchronization of two remote Git-repositories.
|
|
46
|
+
# Use the following options to configure your synchronization.
|
|
47
|
+
#
|
|
48
|
+
## Uncomment and modify required variables in this file.
|
|
49
|
+
#
|
|
50
|
+
## Create a copy of this file in one of the following locations
|
|
51
|
+
# * git-repo-sync/repo_settings
|
|
52
|
+
# * git-repo-sync/../git-repo-sync.repo_settings
|
|
53
|
+
# Pass the name of your copied file to git-sync.sh as the first parameter for every run.
|
|
54
|
+
# Invocation example: $ ./git-sync.sh my-sync-project.sh
|
|
55
|
+
#
|
|
56
|
+
## Create a copy of this file in an arbitrary location.
|
|
57
|
+
# Pass its full path to git-sync.sh as the first parameter for every run.
|
|
58
|
+
# Or use a relative to "git-repo-sync" path.
|
|
59
|
+
#
|
|
60
|
+
## Declare the variables in your script or environment.
|
|
61
|
+
# Warning! Your configuration file will be ignored if your parent environment
|
|
62
|
+
# or calling script have the git_sync_project_folder variable.
|
|
63
|
+
|
|
64
|
+
## url_a
|
|
65
|
+
## url_b
|
|
66
|
+
# Let's call your two synchronized remote Git repositories as sides A and B.
|
|
67
|
+
# Then url_a and url_b variables point to git remote repositories of the A and B sides accordingly.
|
|
68
|
+
# It could be an URL or a file path (SSH addresses wasn't tested yet).
|
|
69
|
+
# For paths on Windows use the following notation
|
|
70
|
+
# url_a="/c/my-folder/my-git-local-repo-folder"
|
|
71
|
+
|
|
72
|
+
## victim_branches_prefix
|
|
73
|
+
# Limit branches which will be synchronized under a Victim Sync strategy.
|
|
74
|
+
# If undefined or empty then all branches will be synced.
|
|
75
|
+
# (except conventionally prefixed branches described below)
|
|
76
|
+
#
|
|
77
|
+
## The Victim Sync strategy.
|
|
78
|
+
# You can do whatever you want with such branches from both remote sides (repositories).
|
|
79
|
+
# In case of commit conflicts, any newest commit will win.
|
|
80
|
+
# You can relocate branches to any position or delete them, etc.
|
|
81
|
+
# You can move a branch back in history if you sync your repos regularly.
|
|
82
|
+
#
|
|
83
|
+
# The most common value is "@".
|
|
84
|
+
# Examples: @dev, @dev-staging, @test, @test-staging
|
|
85
|
+
|
|
86
|
+
## sync_enabling_branch
|
|
87
|
+
# Represents any branch name.
|
|
88
|
+
# The git-repo-sync will check that such a branch exist in both remote repositories
|
|
89
|
+
# and that it has the same or related commits, i.e. located in the same Git-tree.
|
|
90
|
+
# This will protect you from occasional adhesion of unrelated git-repositories.
|
|
91
|
+
# Git may store many independent projects in the same repository and this is uncommon behavior for many users.
|
|
92
|
+
#
|
|
93
|
+
# We advise to use it3xl_git_repo_sync_enabled name to make it explicit to others that their Git-repo is syncing with another remote repo.
|
|
94
|
+
# Examples: @test, client-prod, vendor-master, it3xl_git_repo_sync_enabled
|
|
95
|
+
|
|
96
|
+
## side_a_conventional_branches_prefix
|
|
97
|
+
# Branches with a prefix from this variable will be owned by the repo from "url_a". Let's call it A side.
|
|
98
|
+
#
|
|
99
|
+
## side_b_conventional_branches_prefix
|
|
100
|
+
# Branches with a prefix from this variable will be owned by the repo from "url_b". Let's call it B side.
|
|
101
|
+
#
|
|
102
|
+
# Branches with such prefixes will be updated under the Conventional Sync strategy.
|
|
103
|
+
# You can define both or one variable.
|
|
104
|
+
#
|
|
105
|
+
## The Conventional Sync strategy
|
|
106
|
+
# On a repo of the owning side: You can do whatever you want with such branches.
|
|
107
|
+
# On a repo of another side: You can do fast-forward updates and merges.
|
|
108
|
+
# You can move such a branch back in Git-history from an non-owning side if you run git-repo-sync regularly.
|
|
109
|
+
# All commit conflicts will be solved in favor of the owning side.
|
|
110
|
+
#
|
|
111
|
+
# Example of prefix pairs: client-, vendor-; a-, b-; microsoft/, google/
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
## git_sync_project_folder
|
|
115
|
+
# It defines a folder in which your sync-project artifacts will be stored inside of "git-repo-sync/sync-projects/".
|
|
116
|
+
# In the absence of git_sync_project_folder, its value will be taken from the name of a provided configuration file.
|
|
117
|
+
#
|
|
118
|
+
# Warning! Your configuration file will be ignored if your parent environment
|
|
119
|
+
# or calling script have this variable. In this case, all required variables must be configured in the parent environment.
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
## use_bash_git_credential_helper=1
|
|
123
|
+
# This variables enables using of the "git-cred", the "bash Git Credential Helper" from https://github.com/it3xl/bash-git-credential-helper
|
|
124
|
+
#
|
|
125
|
+
# Git-cred allows you to use Git-credential values from environment variables
|
|
126
|
+
# which are defined automatically by any Continues Integration (CI/CD) tool.
|
|
127
|
+
#
|
|
128
|
+
# You can use "git-cred" as an external tool and tune everything manually.
|
|
129
|
+
# But configuring it here allows you to initialize git-cred only once.
|
|
130
|
+
# BTW, "git-cred" allows a free relocation of your installation "git-repo-sync" folder.
|
|
131
|
+
#
|
|
132
|
+
# * Before using git-cred you must complete the following steps.
|
|
133
|
+
#
|
|
134
|
+
# ** Load Git sub-modules inside of your "git-repo-sync" folder (https://github.com/it3xl/git-repo-sync)
|
|
135
|
+
#
|
|
136
|
+
# ** Before any call to "git-sync.sh" or to "request-git-sync.sh", define the following environment variables in your CI/CD automation server or tool
|
|
137
|
+
# For the repo in $url_a
|
|
138
|
+
# git_cred_username_repo_a=some-login
|
|
139
|
+
# git_cred_password_repo_a=some-password
|
|
140
|
+
# For the repo in $url_b
|
|
141
|
+
# git_cred_username_repo_b=another-login
|
|
142
|
+
# git_cred_password_repo_b=another-password
|
|
143
|
+
#
|
|
144
|
+
# ** Assign use_bash_git_credential_helper variable to 1.
|
|
145
|
+
|
|
146
|
+
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# it3xl.ru git-repo-sync https://github.com/it3xl/git-repo-sync
|
|
2
|
+
|
|
3
|
+
set -euf +x -o pipefail
|
|
4
|
+
|
|
5
|
+
echo
|
|
6
|
+
echo Start $(basename $BASH_SOURCE)
|
|
7
|
+
|
|
8
|
+
invoke_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
9
|
+
source "$invoke_path/util/set_env.sh" "$@"
|
|
10
|
+
|
|
11
|
+
rm -f "$env_modifications_signal_file"
|
|
12
|
+
rm -f "$env_modifications_signal_file_a"
|
|
13
|
+
rm -f "$env_modifications_signal_file_b"
|
|
14
|
+
|
|
15
|
+
echo
|
|
16
|
+
source "$path_git_sync_util/repo_create.sh"
|
|
17
|
+
cd "$path_sync_repo"
|
|
18
|
+
|
|
19
|
+
source "$path_git_sync_util/restore-after-crash.sh"
|
|
20
|
+
|
|
21
|
+
source "$path_git_sync_util/change_detector.sh"
|
|
22
|
+
|
|
23
|
+
echo
|
|
24
|
+
if (( $changes_detected == 1 )); then
|
|
25
|
+
install -D /dev/null "$env_modifications_signal_file"
|
|
26
|
+
install -D /dev/null "$env_modifications_signal_file_a"
|
|
27
|
+
install -D /dev/null "$env_modifications_signal_file_b"
|
|
28
|
+
|
|
29
|
+
# Passing of remote refs to prevent excessive network requesting.
|
|
30
|
+
echo "$remote_refs_a" >> "$env_modifications_signal_file_a"
|
|
31
|
+
|
|
32
|
+
echo "$remote_refs_b" >> "$env_modifications_signal_file_b"
|
|
33
|
+
|
|
34
|
+
echo '@' RESULT: Synchronization requested.
|
|
35
|
+
else
|
|
36
|
+
echo '@' RESULT: Refs are the same. Exit.
|
|
37
|
+
echo
|
|
38
|
+
|
|
39
|
+
# exit
|
|
40
|
+
fi
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
echo
|
|
44
|
+
echo End $(basename $BASH_SOURCE)
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# it3xl.ru git-repo-sync https://github.com/it3xl/git-repo-sync
|
|
2
|
+
|
|
3
|
+
if [[ $env_allow_async == 1 ]]; then
|
|
4
|
+
echo '! Async (async remote refs checks are used)'
|
|
5
|
+
|
|
6
|
+
mkdir -p "$path_async_output"
|
|
7
|
+
|
|
8
|
+
git ls-remote --heads "$url_a" $sync_ref_specs > "$path_async_output/remote_refs_a.txt" &
|
|
9
|
+
pid_remote_refs_a=$!
|
|
10
|
+
git ls-remote --heads "$url_b" $sync_ref_specs > "$path_async_output/remote_refs_b.txt" &
|
|
11
|
+
pid_remote_refs_b=$!
|
|
12
|
+
|
|
13
|
+
err_remote_refs_a=0;
|
|
14
|
+
wait $pid_remote_refs_a || err_remote_refs_a=$?
|
|
15
|
+
err_remote_refs_b=0;
|
|
16
|
+
wait $pid_remote_refs_b || err_remote_refs_b=$?
|
|
17
|
+
|
|
18
|
+
remote_refs_a=$(<"$path_async_output/remote_refs_a.txt")
|
|
19
|
+
remote_refs_b=$(<"$path_async_output/remote_refs_b.txt")
|
|
20
|
+
|
|
21
|
+
if (( $err_remote_refs_a != 0 )); then
|
|
22
|
+
echo
|
|
23
|
+
echo "> Async fail | Change detection | $origin_a | Error $err_remote_refs_a"
|
|
24
|
+
echo "$remote_refs_a"
|
|
25
|
+
echo ">"
|
|
26
|
+
fi;
|
|
27
|
+
if (( $err_remote_refs_b != 0 )); then
|
|
28
|
+
echo
|
|
29
|
+
echo "> Async fail | Change detection | $origin_b | Error $err_remote_refs_b"
|
|
30
|
+
echo "$remote_refs_b"
|
|
31
|
+
echo ">"
|
|
32
|
+
fi;
|
|
33
|
+
if (( $err_remote_refs_a != 0 )); then
|
|
34
|
+
echo
|
|
35
|
+
echo "> Exit."
|
|
36
|
+
exit $err_remote_refs_a;
|
|
37
|
+
fi;
|
|
38
|
+
if (( $err_remote_refs_b != 0 )); then
|
|
39
|
+
echo
|
|
40
|
+
echo "> Exit."
|
|
41
|
+
exit $err_remote_refs_b;
|
|
42
|
+
fi;
|
|
43
|
+
else
|
|
44
|
+
echo '! Sync (sync remote refs checks are used)'
|
|
45
|
+
|
|
46
|
+
remote_refs_b=$(git ls-remote --heads "$url_b" $sync_ref_specs)
|
|
47
|
+
remote_refs_a=$(git ls-remote --heads "$url_a" $sync_ref_specs)
|
|
48
|
+
fi;
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
track_refs_a=$(git for-each-ref --format="%(objectname) %(refname)" $track_refspecs_a)
|
|
52
|
+
track_refs_b=$(git for-each-ref --format="%(objectname) %(refname)" $track_refspecs_b)
|
|
53
|
+
|
|
54
|
+
## remote_count=$(echo "$remote_refs_a" | awk 'END { print NR }';)
|
|
55
|
+
## track_count=$(echo "$track_refs_a" | awk 'END { print NR }';)
|
|
56
|
+
|
|
57
|
+
export remote_refs_a;
|
|
58
|
+
export remote_refs_b;
|
|
59
|
+
export track_refs_a;
|
|
60
|
+
export track_refs_b;
|
|
61
|
+
|
|
62
|
+
changes_detected=$($env_awk_edition --file="$path_git_sync_util/gawk/change_detector.gawk")
|
|
63
|
+
echo
|
|
64
|
+
|