Compare commits
124 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 92092ed4af | |||
| fadf687a3e | |||
| 3a18870537 | |||
| cf80678ccc | |||
| 08ce4b6add | |||
| 39075a6269 | |||
| 906ead80a4 | |||
| 7038661296 | |||
| 543bf94a51 | |||
| 453f73c2a0 | |||
| 7e673200c8 | |||
| 44a716248e | |||
| d20006a325 | |||
| f8adec1413 | |||
| 868269359c | |||
| 61d4a4a0d8 | |||
| 4e4de95a07 | |||
| 9b64de7991 | |||
| e45de3b498 | |||
| 6e4c388195 | |||
| 6436a8194e | |||
| f10ae25b2a | |||
| fd6b3b7438 | |||
| d68ff012f2 | |||
| 9aad65edac | |||
| c370ef5815 | |||
| 8f5b743ea4 | |||
| c0e981dbd4 | |||
| 4303621b30 | |||
| 63e04a9dcf | |||
| 08ee946f2e | |||
| 81de5a2d70 | |||
| 3bf118f99a | |||
| dbf93c8f0e | |||
| 1ae0ceff60 | |||
| 07fa3ca291 | |||
| ab1892cbeb | |||
| ed1edf5075 | |||
| e6e9940757 | |||
| ff48b2a017 | |||
| ec45678ce3 | |||
| 9acf5b10d5 | |||
| eaf8e2bfa2 | |||
| 31b90af066 | |||
| f9d9dc587a | |||
| a94bd19362 | |||
| ef8a57c60e | |||
| 7a2fa7ae3f | |||
| 599973e10a | |||
| 0485facf33 | |||
| 2f6405ea10 | |||
| a4e993b7fc | |||
| 0fb9a22d47 | |||
| 76130c5b48 | |||
| 9f6c84d78c | |||
| fc91ee7a01 | |||
| c0168c3650 | |||
| 717b0d3a74 | |||
| ef381c7421 | |||
| fcbad5a3eb | |||
| cbc9792755 | |||
| ae9a928d45 | |||
| 3ff7b61518 | |||
| 3ac88260b5 | |||
| 54fc48b37d | |||
| 61a8d63374 | |||
| 92e4856dd9 | |||
| 02e9de0cbd | |||
| 552b3a6aad | |||
| fcc22791e5 | |||
| b183590096 | |||
| 27586b5ff0 | |||
| 70eac10eaa | |||
| 1e941e02ed | |||
| 1ffc522d51 | |||
| 66814876a8 | |||
| 3501b785c9 | |||
| 24badb9b64 | |||
| 4c94ead06f | |||
| 7514d1fd3e | |||
| d85c98c3ef | |||
| e3563fcaa6 | |||
| 1a1231b672 | |||
| a3ccea9dcb | |||
| 4a9f1bc278 | |||
| 0b181b9b79 | |||
| 6d747d8e89 | |||
| 72dd861677 | |||
| 59c6164c1f | |||
| 4722d5a8ff | |||
| 4eb88260c8 | |||
| a51e5f8918 | |||
| c66620a0fc | |||
| f0c8805cf3 | |||
| da601c2d5f | |||
| ed06c52c8f | |||
| 14b200ee3d | |||
| d5eddc4476 | |||
| d26a76d064 | |||
| d39df526de | |||
| 6e6050c71b | |||
| 98580d32ad | |||
| 115eb7c74a | |||
|
|
8b7b91d005 | ||
| 7aa45c7768 | |||
| a065de5b2d | |||
| d976ccefc2 | |||
| de186901d0 | |||
| c9f4d41780 | |||
| b3906c646a | |||
| 43c47bdca6 | |||
| df0b5728fc | |||
| d0b78686e2 | |||
| f02a0fc17a | |||
| 4e83aba672 | |||
| e2e55b8e79 | |||
| 655379cd61 | |||
| 340085abf8 | |||
| f5f8dfa188 | |||
| e43d4bf3cd | |||
| 48f3bc0199 | |||
| 0973ae36b8 | |||
| 09c67d4908 | |||
| 47841dadfb |
49
CONTRIBUTING.md
Normal file
49
CONTRIBUTING.md
Normal file
@@ -0,0 +1,49 @@
|
||||
# Contributing
|
||||
|
||||
GRM is still in very early development. I started GRM mainly to scratch my own
|
||||
itches (and am heavily dogfooding it). If you have a new use case for GRM, go
|
||||
for it!
|
||||
|
||||
The branching strategy is a simplified
|
||||
[git-flow](https://nvie.com/posts/a-successful-git-branching-model/).
|
||||
|
||||
* `master` is the "production" branch. Each commit is a new release.
|
||||
* `develop` is the branch where new stuff is coming in.
|
||||
* feature branches branch off of `develop` and merge back into it.
|
||||
|
||||
So to contribute, just fork the repo and create a pull request against
|
||||
`develop`. If you plan bigger changes, please consider opening an issue first,
|
||||
so we can discuss it.
|
||||
|
||||
If you want, add yourself to the `CONTRIBUTORS` file in your pull request.
|
||||
|
||||
## Code formatting
|
||||
|
||||
For Rust, just use `cargo fmt`. For Python, use
|
||||
[black](https://github.com/psf/black). I'd rather not spend any effort in
|
||||
configuring the formatters (not possible for black anyway).
|
||||
|
||||
## Tooling
|
||||
|
||||
GRM uses [`just`](https://github.com/casey/just) as a command runner. See
|
||||
[here](https://github.com/casey/just#installation) for installation
|
||||
instructions (it's most likely just a simple `cargo install just`).
|
||||
|
||||
## Testing
|
||||
|
||||
There are two distinct test suites: One for unit test (`just test-unit`) and
|
||||
integration tests (`just test-integration`) that is part of the rust crate, and
|
||||
a separate e2e test suite in python (`just test-e2e`).
|
||||
|
||||
To run all tests, run `just test`.
|
||||
|
||||
When contributing, consider whether it makes sense to add tests that to prevent
|
||||
regressions in the future. When fixing bugs, it makes sense to add tests that
|
||||
expose the wrong behaviour beforehand.
|
||||
|
||||
## Documentation
|
||||
|
||||
The documentation lives in `docs` and uses
|
||||
[mdBook](https://github.com/rust-lang/mdBook). Please document new user-facing
|
||||
features here!
|
||||
|
||||
1
CONTRIBUTORS
Normal file
1
CONTRIBUTORS
Normal file
@@ -0,0 +1 @@
|
||||
nonnominandus
|
||||
248
Cargo.lock
generated
248
Cargo.lock
generated
@@ -24,9 +24,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.0.1"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
|
||||
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
@@ -36,9 +36,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.72"
|
||||
version = "1.0.73"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee"
|
||||
checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
|
||||
dependencies = [
|
||||
"jobserver",
|
||||
]
|
||||
@@ -51,9 +51,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "3.0.0-beta.5"
|
||||
version = "3.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "feff3878564edb93745d58cf63e17b63f24142506e7a20c87a5521ed7bfb1d63"
|
||||
checksum = "6d76c22c9b9b215eeb8d016ad3a90417bd13cb24cf8142756e6472445876cab7"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"bitflags",
|
||||
@@ -64,16 +64,15 @@ dependencies = [
|
||||
"strsim",
|
||||
"termcolor",
|
||||
"textwrap",
|
||||
"unicase",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "3.0.0-beta.5"
|
||||
version = "3.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b15c6b4f786ffb6192ffe65a36855bc1fc2444bcd0945ae16748dcd6ed7d0d3"
|
||||
checksum = "5fd1122e63869df2cb309f449da1ad54a7c6dfeb7c7e6ccd8e0825d9eb93bb72"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"heck 0.4.0",
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -82,9 +81,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "comfy-table"
|
||||
version = "5.0.0"
|
||||
version = "5.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c42350b81f044f576ff88ac750419f914abb46a03831bb1747134344ee7a4e64"
|
||||
checksum = "b103d85ca6e209388771bfb7aa6b68a7aeec4afbf6f0a0264bfbf50360e5212e"
|
||||
dependencies = [
|
||||
"crossterm",
|
||||
"strum",
|
||||
@@ -109,9 +108,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "crossterm"
|
||||
version = "0.22.1"
|
||||
version = "0.23.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c85525306c4291d1b73ce93c8acf9c339f9b213aef6c1d85c3830cbf1c16325c"
|
||||
checksum = "77b75a27dc8d220f1f8521ea69cd55a34d720a200ebb3a624d9aa19193d3b432"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"crossterm_winapi",
|
||||
@@ -177,9 +176,9 @@ checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.3"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753"
|
||||
checksum = "418d37c8b1d42553c93648be529cb70f920d3baf8ef469b74b9638df426e0b4c"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
@@ -188,7 +187,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "git-repo-manager"
|
||||
version = "0.3.0"
|
||||
version = "0.6.1"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"comfy-table",
|
||||
@@ -196,6 +195,7 @@ dependencies = [
|
||||
"git2",
|
||||
"regex",
|
||||
"serde",
|
||||
"serde_yaml",
|
||||
"shellexpand",
|
||||
"tempdir",
|
||||
"toml",
|
||||
@@ -203,9 +203,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "git2"
|
||||
version = "0.13.24"
|
||||
version = "0.13.25"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "845e007a28f1fcac035715988a234e8ec5458fd825b20a20c7dec74237ef341f"
|
||||
checksum = "f29229cc1b24c0e6062f6e742aa3e256492a5323365e5ed3413599f8a5eff7d6"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"libc",
|
||||
@@ -231,6 +231,12 @@ dependencies = [
|
||||
"unicode-segmentation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.19"
|
||||
@@ -253,23 +259,14 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "1.7.0"
|
||||
version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5"
|
||||
checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "instant"
|
||||
version = "0.1.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jobserver"
|
||||
version = "0.1.24"
|
||||
@@ -287,15 +284,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.108"
|
||||
version = "0.2.119"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119"
|
||||
checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4"
|
||||
|
||||
[[package]]
|
||||
name = "libgit2-sys"
|
||||
version = "0.12.25+1.3.0"
|
||||
version = "0.12.26+1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f68169ef08d6519b2fe133ecc637408d933c0174b23b80bb2f79828966fbaab"
|
||||
checksum = "19e1c899248e606fbfe68dcb31d8b0176ebab833b103824af31bddf4b7457494"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
@@ -332,10 +329,16 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lock_api"
|
||||
version = "0.4.5"
|
||||
name = "linked-hash-map"
|
||||
version = "0.5.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712a4d093c9976e24e7dbca41db895dabcbac38eb5f4045393d17a95bdfb1109"
|
||||
checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3"
|
||||
|
||||
[[package]]
|
||||
name = "lock_api"
|
||||
version = "0.4.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "88943dd7ef4a2e5a4bfa2753aaab3013e34ce2533d1996fb18ef591e315e2b3b"
|
||||
dependencies = [
|
||||
"scopeguard",
|
||||
]
|
||||
@@ -385,30 +388,30 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ntapi"
|
||||
version = "0.3.6"
|
||||
version = "0.3.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44"
|
||||
checksum = "c28774a7fd2fbb4f0babd8237ce554b73af68021b5f695a3cebd6c59bac0980f"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.8.0"
|
||||
version = "1.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56"
|
||||
checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5"
|
||||
|
||||
[[package]]
|
||||
name = "openssl-probe"
|
||||
version = "0.1.4"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "28988d872ab76095a6e6ac88d99b54fd267702734fd7ffe610ca27f533ddb95a"
|
||||
checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
|
||||
|
||||
[[package]]
|
||||
name = "openssl-sys"
|
||||
version = "0.9.71"
|
||||
version = "0.9.72"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7df13d165e607909b363a4757a6f133f8a818a74e9d3a98d09c6128e15fa4c73"
|
||||
checksum = "7e46109c383602735fa0a2e48dd2b7c892b048e1bf69e5c3b1d804b7d9c203cb"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"cc",
|
||||
@@ -419,36 +422,34 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "os_str_bytes"
|
||||
version = "4.2.0"
|
||||
version = "6.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "addaa943333a514159c80c97ff4a93306530d965d27e139188283cd13e06a799"
|
||||
checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "parking_lot"
|
||||
version = "0.11.2"
|
||||
version = "0.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99"
|
||||
checksum = "87f5ec2493a61ac0506c0f4199f99070cbe83857b0337006a30f3e6719b8ef58"
|
||||
dependencies = [
|
||||
"instant",
|
||||
"lock_api",
|
||||
"parking_lot_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "parking_lot_core"
|
||||
version = "0.8.5"
|
||||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216"
|
||||
checksum = "28141e0cc4143da2443301914478dc976a61ffdb3f043058310c70df2fed8954"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"instant",
|
||||
"libc",
|
||||
"redox_syscall",
|
||||
"smallvec",
|
||||
"winapi",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -459,9 +460,9 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.22"
|
||||
version = "0.3.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "12295df4f294471248581bc09bef3c38a5e46f1e36d6a37353621a0c6c357e1f"
|
||||
checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error"
|
||||
@@ -489,18 +490,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.32"
|
||||
version = "1.0.36"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43"
|
||||
checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.10"
|
||||
version = "1.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05"
|
||||
checksum = "864d3e96a899863136fc6e99f3d7cae289dafe43bf2c5ac19b70df7210c0a145"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
@@ -587,6 +588,18 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f2cc38e8fa666e2de3c4aba7edeb5ffc5246c1c2ed0e3d17e560aeeba736b23f"
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f"
|
||||
|
||||
[[package]]
|
||||
name = "scopeguard"
|
||||
version = "1.1.0"
|
||||
@@ -595,24 +608,36 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.130"
|
||||
version = "1.0.136"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913"
|
||||
checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.130"
|
||||
version = "1.0.136"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b"
|
||||
checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_yaml"
|
||||
version = "0.8.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4a521f2940385c165a24ee286aa8599633d162077a54bdcae2a6fd5a7bfa7a0"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"ryu",
|
||||
"serde",
|
||||
"yaml-rust",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shellexpand"
|
||||
version = "2.1.0"
|
||||
@@ -624,9 +649,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "signal-hook"
|
||||
version = "0.3.10"
|
||||
version = "0.3.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c98891d737e271a2954825ef19e46bd16bdb98e2746f2eec4f7a4ef7946efd1"
|
||||
checksum = "647c97df271007dcea485bb74ffdb57f2e683f1306c854f468a0c244badabf2d"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"signal-hook-registry",
|
||||
@@ -654,9 +679,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.7.0"
|
||||
version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309"
|
||||
checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83"
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
@@ -666,27 +691,28 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
||||
|
||||
[[package]]
|
||||
name = "strum"
|
||||
version = "0.22.0"
|
||||
version = "0.23.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7ac893c7d471c8a21f31cfe213ec4f6d9afeed25537c772e08ef3f005f8729e"
|
||||
checksum = "cae14b91c7d11c9a851d3fbc80a963198998c2a64eec840477fa92d8ce9b70bb"
|
||||
|
||||
[[package]]
|
||||
name = "strum_macros"
|
||||
version = "0.22.0"
|
||||
version = "0.23.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "339f799d8b549e3744c7ac7feb216383e4005d94bdb22561b3ab8f3b808ae9fb"
|
||||
checksum = "5bb0dc7ee9c15cea6199cde9a127fa16a4c5819af85395457ad72d68edc85a38"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"heck 0.3.3",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"rustversion",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.81"
|
||||
version = "1.0.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f2afee18b8beb5a596ecb4a2dce128c719b4ba399d34126b9e4396e3f9860966"
|
||||
checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -727,9 +753,6 @@ name = "textwrap"
|
||||
version = "0.14.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80"
|
||||
dependencies = [
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinyvec"
|
||||
@@ -755,15 +778,6 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicase"
|
||||
version = "2.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6"
|
||||
dependencies = [
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-bidi"
|
||||
version = "0.3.7"
|
||||
@@ -781,9 +795,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "unicode-segmentation"
|
||||
version = "1.8.0"
|
||||
version = "1.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b"
|
||||
checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-width"
|
||||
@@ -817,9 +831,9 @@ checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.3"
|
||||
version = "0.9.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
|
||||
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
@@ -857,3 +871,55 @@ name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.32.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3df6e476185f92a12c072be4a189a0210dcdcf512a1891d6dff9edb874deadc6"
|
||||
dependencies = [
|
||||
"windows_aarch64_msvc",
|
||||
"windows_i686_gnu",
|
||||
"windows_i686_msvc",
|
||||
"windows_x86_64_gnu",
|
||||
"windows_x86_64_msvc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.32.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d8e92753b1c443191654ec532f14c199742964a061be25d77d7a96f09db20bf5"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.32.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a711c68811799e017b6038e0922cb27a5e2f43a2ddb609fe0b6f3eeda9de615"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.32.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "146c11bb1a02615db74680b32a68e2d61f553cc24c4eb5b4ca10311740e44172"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.32.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c912b12f7454c6620635bbff3450962753834be2a594819bd5e945af18ec64bc"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.32.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "504a2476202769977a040c6364301a3f65d0cc9e3fb08600b2bda150a0488316"
|
||||
|
||||
[[package]]
|
||||
name = "yaml-rust"
|
||||
version = "0.4.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85"
|
||||
dependencies = [
|
||||
"linked-hash-map",
|
||||
]
|
||||
|
||||
26
Cargo.toml
26
Cargo.toml
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "git-repo-manager"
|
||||
version = "0.3.0"
|
||||
version = "0.6.1"
|
||||
edition = "2021"
|
||||
authors = [
|
||||
"Hannes Körber <hannes@hkoerber.de>",
|
||||
@@ -32,34 +32,38 @@ path = "src/lib.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "grm"
|
||||
path = "src/main.rs"
|
||||
path = "src/grm/main.rs"
|
||||
|
||||
[dependencies]
|
||||
|
||||
[dependencies.toml]
|
||||
version = "0.5.8"
|
||||
version = "=0.5.8"
|
||||
|
||||
[dependencies.serde]
|
||||
version = "1.0.130"
|
||||
version = "=1.0.136"
|
||||
features = ["derive"]
|
||||
|
||||
[dependencies.git2]
|
||||
version = "0.13.24"
|
||||
version = "=0.13.25"
|
||||
|
||||
[dependencies.shellexpand]
|
||||
version = "2.1.0"
|
||||
version = "=2.1.0"
|
||||
|
||||
[dependencies.clap]
|
||||
version = "3.0.0-beta.5"
|
||||
version = "=3.1.1"
|
||||
features = ["derive", "cargo"]
|
||||
|
||||
[dependencies.console]
|
||||
version = "0.15.0"
|
||||
version = "=0.15.0"
|
||||
|
||||
[dependencies.regex]
|
||||
version = "1.5.4"
|
||||
version = "=1.5.4"
|
||||
|
||||
[dependencies.comfy-table]
|
||||
version = "5.0.0"
|
||||
version = "=5.0.1"
|
||||
|
||||
[dependencies.serde_yaml]
|
||||
version = "=0.8.23"
|
||||
|
||||
[dev-dependencies.tempdir]
|
||||
version = "0.3.7"
|
||||
version = "=0.3.7"
|
||||
|
||||
42
Justfile
42
Justfile
@@ -1,7 +1,10 @@
|
||||
check:
|
||||
check: check-cargo-lock check-pip-requirements test
|
||||
cargo check
|
||||
cargo fmt --check
|
||||
cargo clippy --no-deps
|
||||
cargo clippy --no-deps -- -Dwarnings
|
||||
|
||||
check-cargo-lock:
|
||||
cargo update --locked
|
||||
|
||||
lint-fix:
|
||||
cargo clippy --no-deps --fix
|
||||
@@ -12,12 +15,43 @@ release:
|
||||
install:
|
||||
cargo install --path .
|
||||
|
||||
test:
|
||||
test: test-unit test-integration test-e2e
|
||||
|
||||
test-unit:
|
||||
cargo test --lib --bins
|
||||
|
||||
update-dependencies:
|
||||
test-integration:
|
||||
cargo test --test "*"
|
||||
|
||||
e2e-venv:
|
||||
cd ./e2e_tests \
|
||||
&& python3 -m venv venv \
|
||||
&& . ./venv/bin/activate \
|
||||
&& pip --disable-pip-version-check install -r ./requirements.txt >/dev/null
|
||||
|
||||
|
||||
test-e2e +tests=".": e2e-venv release
|
||||
cd ./e2e_tests \
|
||||
&& . ./venv/bin/activate \
|
||||
&& TMPDIR=/dev/shm python -m pytest --color=yes {{tests}}
|
||||
|
||||
update-dependencies: update-cargo-dependencies update-pip-requirements
|
||||
|
||||
update-cargo-dependencies:
|
||||
@cd ./depcheck \
|
||||
&& python3 -m venv ./venv \
|
||||
&& . ./venv/bin/activate \
|
||||
&& pip --disable-pip-version-check install -r ./requirements.txt > /dev/null \
|
||||
&& ./update-cargo-dependencies.py
|
||||
|
||||
update-pip-requirements: e2e-venv
|
||||
@cd ./e2e_tests \
|
||||
&& ./update_requirementstxt.sh
|
||||
|
||||
check-pip-requirements: e2e-venv
|
||||
@cd ./e2e_tests \
|
||||
&& . ./venv/bin/activate \
|
||||
&& pip list --outdated | grep -q '.' && exit 1 || exit 0
|
||||
|
||||
clean:
|
||||
cargo clean
|
||||
|
||||
674
LICENSE
Normal file
674
LICENSE
Normal file
@@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
@@ -10,9 +10,17 @@ import tomlkit
|
||||
|
||||
INDEX_DIR = "crates.io-index"
|
||||
|
||||
AUTOUPDATE_DISABLED = []
|
||||
|
||||
if os.path.exists(INDEX_DIR):
|
||||
subprocess.run(
|
||||
["git", "pull", "--depth=1", "origin"],
|
||||
["git", "fetch", "--depth=1", "origin"],
|
||||
cwd=INDEX_DIR,
|
||||
check=True,
|
||||
capture_output=True,
|
||||
)
|
||||
subprocess.run(
|
||||
["git", "reset", "--hard", "origin/master"],
|
||||
cwd=INDEX_DIR,
|
||||
check=True,
|
||||
capture_output=True,
|
||||
@@ -29,9 +37,16 @@ with open("../Cargo.toml", "r") as cargo_config:
|
||||
|
||||
update_necessary = False
|
||||
|
||||
# This updates the crates.io index, see https://github.com/rust-lang/cargo/issues/3377
|
||||
subprocess.run(
|
||||
["cargo", "update", "--dry-run"],
|
||||
check=True,
|
||||
capture_output=False, # to get some git output
|
||||
)
|
||||
|
||||
for tier in ["dependencies", "dev-dependencies"]:
|
||||
for name, dependency in cargo[tier].items():
|
||||
version = dependency["version"]
|
||||
version = dependency["version"].lstrip("=")
|
||||
if len(name) >= 4:
|
||||
info_file = f"{INDEX_DIR}/{name[0:2]}/{name[2:4]}/{name}"
|
||||
elif len(name) == 3:
|
||||
@@ -53,6 +68,13 @@ for tier in ["dependencies", "dev-dependencies"]:
|
||||
latest_version = version
|
||||
|
||||
if latest_version != current_version:
|
||||
if name in AUTOUPDATE_DISABLED:
|
||||
print(
|
||||
f"{name} {current_version}: There is a new version available "
|
||||
f"({latest_version}, current {current_version}), but autoupdating "
|
||||
f"is explictly disabled for {name}"
|
||||
)
|
||||
continue
|
||||
update_necessary = True
|
||||
if latest_version < current_version:
|
||||
print(
|
||||
@@ -62,13 +84,60 @@ for tier in ["dependencies", "dev-dependencies"]:
|
||||
print(
|
||||
f"{name}: New version found: {latest_version} (current {current_version})"
|
||||
)
|
||||
cargo[tier][name]["version"] = str(latest_version)
|
||||
|
||||
|
||||
if update_necessary is True:
|
||||
cargo[tier][name]["version"] = f"={str(latest_version)}"
|
||||
with open("../Cargo.toml", "w") as cargo_config:
|
||||
cargo_config.write(tomlkit.dumps(cargo))
|
||||
sys.exit(1)
|
||||
else:
|
||||
|
||||
try:
|
||||
cmd = subprocess.run(
|
||||
["cargo", "update", "-Z", "no-index-update", "--aggressive", "--package", name],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(e.stdout)
|
||||
print(e.stderr)
|
||||
raise
|
||||
|
||||
message = f"dependencies: Update {name} to {latest_version}"
|
||||
subprocess.run(
|
||||
["git", "commit", "--message", message, "../Cargo.toml", "../Cargo.lock"],
|
||||
check=True,
|
||||
capture_output=True
|
||||
)
|
||||
|
||||
|
||||
# Note that we have to restart this lookup every time, as later packages can depend
|
||||
# on former packages
|
||||
while True:
|
||||
with open("../Cargo.lock", "r") as f:
|
||||
cargo_lock = tomlkit.parse(f.read())
|
||||
for package in cargo_lock['package']:
|
||||
spec = f"{package['name']}:{package['version']}"
|
||||
try:
|
||||
cmd = subprocess.run(
|
||||
["cargo", "update", "-Z", "no-index-update", "--aggressive", "--package", spec],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(e.stdout)
|
||||
print(e.stderr)
|
||||
raise
|
||||
if len(cmd.stderr) != 0:
|
||||
update_necessary = True
|
||||
message = "Cargo.lock: {}".format(cmd.stderr.split("\n")[0].strip())
|
||||
print(message)
|
||||
cmd = subprocess.run(
|
||||
["git", "commit", "--message", message, "../Cargo.lock"],
|
||||
check=True,
|
||||
capture_output=True
|
||||
)
|
||||
break
|
||||
else:
|
||||
break
|
||||
|
||||
if update_necessary is False:
|
||||
print("Everything up to date")
|
||||
sys.exit(0)
|
||||
|
||||
@@ -5,3 +5,4 @@
|
||||
- [Repository trees](./repos.md)
|
||||
- [Git Worktrees](./worktrees.md)
|
||||
- [FAQ](./faq.md)
|
||||
- [Contributing](./contributing.md)
|
||||
|
||||
1
docs/src/contributing.md
Symbolic link
1
docs/src/contributing.md
Symbolic link
@@ -0,0 +1 @@
|
||||
../../CONTRIBUTING.md
|
||||
@@ -5,7 +5,8 @@ Manager](https://github.com/hakoerber/git-repo-manager/) (GRM for short), a
|
||||
tool that helps you manage git repositories.
|
||||
|
||||
GRM helps you manage git repositories in a declarative way. Configure your
|
||||
repositories in a TOML file, GRM does the rest. Take a look at [the example
|
||||
repositories in a TOML or YAML file, GRM does the rest. Take a look at [the
|
||||
example
|
||||
configuration](https://github.com/hakoerber/git-repo-manager/blob/master/example.config.toml)
|
||||
to get a feel for the way you configure your repositories. See the [repository
|
||||
tree chapter](./repos.md) for details.
|
||||
|
||||
@@ -74,3 +74,9 @@ $ grm repos status
|
||||
╰──────────┴──────────┴────────┴──────────┴───────┴─────────╯
|
||||
```
|
||||
|
||||
## YAML
|
||||
|
||||
By default, the repo configuration uses TOML. If you prefer YAML, just give it
|
||||
a YAML file instead (file ending does not matter, `grm` will figure out the format
|
||||
itself). For generating a configuration, pass `--format yaml` to `grm repo find`
|
||||
to generate YAML instead of TOML.
|
||||
|
||||
@@ -71,6 +71,10 @@ Now, when you run a `grm sync`, you'll notice that the directory of the reposito
|
||||
is empty! Well, not totally, there is a hidden directory called `.git-main-working-tree`.
|
||||
This is where the repository actually "lives" (it's a bare checkout).
|
||||
|
||||
Note that there are few specific things you can configure for a certain
|
||||
workspace. This is all done in an optional `grm.toml` file right in the root
|
||||
of the worktree. More on that later.
|
||||
|
||||
### Creating a new worktree
|
||||
|
||||
To actually work, you'll first have to create a new worktree checkout. All
|
||||
@@ -130,6 +134,36 @@ The behaviour of `--track` differs depending on the existence of the remote bran
|
||||
new remote tracking branch, using the default branch (either `main` or `master`)
|
||||
as the base
|
||||
|
||||
Often, you'll have a workflow that uses tracking branches by default. It would
|
||||
be quite tedious to add `--track` every single time. Luckily, the `grm.toml` file
|
||||
supports defaults for the tracking behaviour. See this for an example:
|
||||
|
||||
```toml
|
||||
[track]
|
||||
default = true
|
||||
default_remote = "origin"
|
||||
```
|
||||
|
||||
This will set up a tracking branch on `origin` that has the same name as the local
|
||||
branch.
|
||||
|
||||
Sometimes, you might want to have a certain prefix for all your tracking branches.
|
||||
Maybe to prevent collissions with other contributors. You can simply set
|
||||
`default_remote_prefix` in `grm.toml`:
|
||||
|
||||
```toml
|
||||
[track]
|
||||
default = true
|
||||
default_remote = "origin"
|
||||
default_remote_prefix = "myname"
|
||||
```
|
||||
|
||||
When using branch `my-feature-branch`, the remote tracking branch would be
|
||||
`origin/myname/my-feature-branch` in this case.
|
||||
|
||||
Note that `--track` overrides any configuration in `grm.toml`. If you want to
|
||||
disable tracking, use `--no-track`.
|
||||
|
||||
### Showing the status of your worktrees
|
||||
|
||||
There is a handy little command that will show your an overview over all worktrees
|
||||
@@ -195,6 +229,39 @@ $ grm wt clean
|
||||
Note that this will not delete the default branch of the repository. It can of
|
||||
course still be delete with `grm wt delete` if neccessary.
|
||||
|
||||
### Persistent branches
|
||||
|
||||
You most likely have a few branches that are "special", that you don't want to
|
||||
clean up and that are the usual target for feature branches to merge into. GRM
|
||||
calls them "persistent branches" and treats them a bit differently:
|
||||
|
||||
* Their worktrees will never be deleted by `grm wt clean`
|
||||
* If the branches in other worktrees are merged into them, they will be cleaned
|
||||
up, even though they may not be in line with their upstream. Same goes for
|
||||
`grm wt delete`, which will not require a `--force` flag. Note that of
|
||||
course, actual changes in the worktree will still block an automatic cleanup!
|
||||
* As soon as you enable persistent branches, non-persistent branches will only
|
||||
ever cleaned up when merged into a persistent branch.
|
||||
|
||||
To elaborate: This is mostly relevant for a feature-branch workflow. Whenever a
|
||||
feature branch is merged, it can usually be thrown away. As merging is usually
|
||||
done on some remote code management platform (GitHub, GitLab, ...), this means
|
||||
that you usually keep a branch around until it is merged into one of the "main"
|
||||
branches (`master`, `main`, `develop`, ...)
|
||||
|
||||
Enable persistent branches by setting the following in the `grm.toml` in the
|
||||
worktree root:
|
||||
|
||||
```toml
|
||||
persistent_branches = [
|
||||
"master",
|
||||
"develop",
|
||||
]
|
||||
```
|
||||
|
||||
Note that setting persistent branches will disable any detection of "default"
|
||||
branches. The first entry will be considered your repositories' default branch.
|
||||
|
||||
### Converting an existing repository
|
||||
|
||||
It is possible to convert an existing directory to a worktree setup, using `grm
|
||||
@@ -212,6 +279,81 @@ Commit them and try again!
|
||||
Afterwards, the directory is empty, as there are no worktrees checked out yet.
|
||||
Now you can use the usual commands to set up worktrees.
|
||||
|
||||
### Working with remotes
|
||||
|
||||
To fetch all remote references from all remotes in a worktree setup, you can
|
||||
use the following command:
|
||||
|
||||
```
|
||||
grm wt fetch
|
||||
[✔] Fetched from all remotes
|
||||
```
|
||||
|
||||
This is equivalent to running `git fetch --all` in any of the worktrees.
|
||||
|
||||
Often, you may want to pull all remote changes into your worktrees. For this,
|
||||
use the `git pull` equivalent:
|
||||
|
||||
```
|
||||
grm wt pull
|
||||
[✔] master: Done
|
||||
[✔] my-cool-branch: Done
|
||||
```
|
||||
|
||||
This will refuse when there are local changes, or if the branch cannot be fast
|
||||
forwarded. If you want to rebase your local branches, use the `--rebase` switch:
|
||||
|
||||
```
|
||||
grm wt pull --rebase
|
||||
[✔] master: Done
|
||||
[✔] my-cool-branch: Done
|
||||
```
|
||||
|
||||
As noted, this will fail if there are any local changes in your worktree. If you
|
||||
want to stash these changes automatically before the pull (and unstash them
|
||||
afterwards), use the `--stash` option.
|
||||
|
||||
This will rebase your changes onto the upstream branch. This is mainly helpful
|
||||
for persistent branches that change on the remote side.
|
||||
|
||||
There is a similar rebase feature that rebases onto the **default** branch instead:
|
||||
|
||||
```
|
||||
grm wt rebase
|
||||
[✔] master: Done
|
||||
[✔] my-cool-branch: Done
|
||||
```
|
||||
|
||||
This is super helpful for feature branches. If you want to incorporate changes
|
||||
made on the remote branches, use `grm wt rebase` and all your branches will
|
||||
be up to date. If you want to also update to remote tracking branches in one go,
|
||||
use the `--pull` flag, and `--rebase` if you want to rebase instead of aborting
|
||||
on non-fast-forwards:
|
||||
|
||||
```
|
||||
grm wt rebase --pull --rebase
|
||||
[✔] master: Done
|
||||
[✔] my-cool-branch: Done
|
||||
```
|
||||
|
||||
"So, what's the difference between `pull --rebase` and `rebase --pull`? Why the
|
||||
hell is there a `--rebase` flag in the `rebase` command?"
|
||||
|
||||
Yes, it's kind of weird. Remember that `pull` only ever updates each worktree
|
||||
to their remote branch, if possible. `rebase` rabases onto the **default** branch
|
||||
instead. The switches to `rebase` are just convenience, so you do not have to
|
||||
run two commands.
|
||||
|
||||
* `rebase --pull` is the same as `pull` && `rebase`
|
||||
* `rebase --pull --rebase` is the same as `pull --rebase` && `rebase`
|
||||
|
||||
I understand that the UX is not the most intuitive. If you can think of an
|
||||
improvement, please let me know (e.g. via an GitHub issue)!
|
||||
|
||||
As with `pull`, `rebase` will also refuse to run when there are changes in your
|
||||
worktree. And you can also use the `--stash` option to stash/unstash changes
|
||||
automatically.
|
||||
|
||||
### Manual access
|
||||
|
||||
GRM isn't doing any magic, it's just git under the hood. If you need to have access
|
||||
|
||||
2
e2e_tests/.gitignore
vendored
Normal file
2
e2e_tests/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/venv/
|
||||
/__pycache__/
|
||||
291
e2e_tests/helpers.py
Normal file
291
e2e_tests/helpers.py
Normal file
@@ -0,0 +1,291 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import os.path
|
||||
import subprocess
|
||||
import tempfile
|
||||
import hashlib
|
||||
|
||||
import git
|
||||
|
||||
binary = os.path.join(
|
||||
os.path.dirname(os.path.dirname(os.path.realpath(__file__))), "target/release/grm"
|
||||
)
|
||||
|
||||
|
||||
def grm(args, cwd=None, is_invalid=False):
|
||||
cmd = subprocess.run([binary] + args, cwd=cwd, capture_output=True, text=True)
|
||||
if not is_invalid:
|
||||
assert "USAGE" not in cmd.stderr
|
||||
print(f"grmcmd: {args}")
|
||||
print(f"stdout:\n{cmd.stdout}")
|
||||
print(f"stderr:\n{cmd.stderr}")
|
||||
assert "panicked" not in cmd.stderr
|
||||
return cmd
|
||||
|
||||
|
||||
def shell(script):
|
||||
script = "set -o errexit\nset -o nounset\n" + script
|
||||
subprocess.run(["bash"], input=script, text=True, check=True)
|
||||
|
||||
|
||||
def checksum_directory(path):
|
||||
"""
|
||||
Gives a "checksum" of a directory that includes all files & directories
|
||||
recursively, including owner/group/permissions. Useful to compare that a
|
||||
directory did not change after a command was run.
|
||||
|
||||
The following makes it a bit complicated:
|
||||
|
||||
> Whether or not the lists are sorted depends on the file system.
|
||||
|
||||
- https://docs.python.org/3/library/os.html#os.walk
|
||||
|
||||
This means we have to first get a list of all hashes of files and
|
||||
directories, then sort the hashes and then create the hash for the whole
|
||||
directory.
|
||||
"""
|
||||
path = os.path.realpath(path)
|
||||
|
||||
hashes = []
|
||||
|
||||
if not os.path.exists(path):
|
||||
raise f"{path} not found"
|
||||
|
||||
def get_stat_hash(path):
|
||||
checksum = hashlib.md5()
|
||||
|
||||
# A note about bytes(). You may think that it converts something to
|
||||
# bytes (akin to str()). But it actually creates a list of zero bytes
|
||||
# with the length specified by the parameter.
|
||||
#
|
||||
# This is kinda couterintuitive to me:
|
||||
#
|
||||
# str(5) => '5'
|
||||
# bytes(5) => b'\x00\x00\x00\x00\x00'
|
||||
def int_to_bytes(i):
|
||||
return i.to_bytes((i.bit_length() + 7) // 8, byteorder="big")
|
||||
|
||||
# lstat() instead of stat() so symlinks are not followed. So symlinks
|
||||
# are treated as-is and will also be checked for changes.
|
||||
stat = os.lstat(path)
|
||||
|
||||
# Note that the list of attributes does not include any timings except
|
||||
# mtime.
|
||||
for s in [
|
||||
stat.st_mode, # type & permission bits
|
||||
stat.st_ino, # inode
|
||||
stat.st_uid,
|
||||
stat.st_gid,
|
||||
# it's a float in seconds, so this gives us ~1us precision
|
||||
int(stat.st_mtime * 1e6),
|
||||
]:
|
||||
checksum.update(int_to_bytes(s))
|
||||
return checksum.digest()
|
||||
|
||||
for root, dirs, files in os.walk(path):
|
||||
for file in files:
|
||||
checksum = hashlib.md5()
|
||||
filepath = os.path.join(root, file)
|
||||
checksum.update(str.encode(filepath))
|
||||
checksum.update(get_stat_hash(filepath))
|
||||
with open(filepath, "rb") as f:
|
||||
while True:
|
||||
data = f.read(8192)
|
||||
if not data:
|
||||
break
|
||||
checksum.update(data)
|
||||
hashes.append(checksum.digest())
|
||||
|
||||
for d in dirs:
|
||||
checksum = hashlib.md5()
|
||||
dirpath = os.path.join(root, d)
|
||||
checksum.update(get_stat_hash(dirpath))
|
||||
hashes.append(checksum.digest())
|
||||
|
||||
checksum = hashlib.md5()
|
||||
for c in sorted(hashes):
|
||||
checksum.update(c)
|
||||
return checksum.hexdigest()
|
||||
|
||||
|
||||
class TempGitRepository:
|
||||
def __init__(self, dir=None):
|
||||
self.dir = dir
|
||||
pass
|
||||
|
||||
def __enter__(self):
|
||||
self.tmpdir = tempfile.TemporaryDirectory(dir=self.dir)
|
||||
self.remote_1_dir = tempfile.TemporaryDirectory()
|
||||
self.remote_2_dir = tempfile.TemporaryDirectory()
|
||||
shell(
|
||||
f"""
|
||||
cd {self.tmpdir.name}
|
||||
git init
|
||||
echo test > root-commit
|
||||
git add root-commit
|
||||
git commit -m "root-commit"
|
||||
git remote add origin file://{self.remote_1_dir.name}
|
||||
git remote add otherremote file://{self.remote_2_dir.name}
|
||||
"""
|
||||
)
|
||||
return self.tmpdir.name
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
del self.tmpdir
|
||||
del self.remote_1_dir
|
||||
del self.remote_2_dir
|
||||
|
||||
|
||||
class TempGitRepositoryWorktree:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def __enter__(self):
|
||||
self.tmpdir = tempfile.TemporaryDirectory()
|
||||
self.remote_1_dir = tempfile.TemporaryDirectory()
|
||||
self.remote_2_dir = tempfile.TemporaryDirectory()
|
||||
shell(
|
||||
f"""
|
||||
cd {self.remote_1_dir.name}
|
||||
git init --bare
|
||||
"""
|
||||
)
|
||||
shell(
|
||||
f"""
|
||||
cd {self.remote_2_dir.name}
|
||||
git init --bare
|
||||
"""
|
||||
)
|
||||
shell(
|
||||
f"""
|
||||
cd {self.tmpdir.name}
|
||||
git init
|
||||
echo test > root-commit-in-worktree-1
|
||||
git add root-commit-in-worktree-1
|
||||
git commit -m "root-commit-in-worktree-1"
|
||||
echo test > root-commit-in-worktree-2
|
||||
git add root-commit-in-worktree-2
|
||||
git commit -m "root-commit-in-worktree-2"
|
||||
git remote add origin file://{self.remote_1_dir.name}
|
||||
git remote add otherremote file://{self.remote_2_dir.name}
|
||||
git push origin HEAD:master
|
||||
git ls-files | xargs rm -rf
|
||||
mv .git .git-main-working-tree
|
||||
git --git-dir .git-main-working-tree config core.bare true
|
||||
"""
|
||||
)
|
||||
commit = git.Repo(
|
||||
f"{self.tmpdir.name}/.git-main-working-tree"
|
||||
).head.commit.hexsha
|
||||
return (self.tmpdir.name, commit)
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
del self.tmpdir
|
||||
del self.remote_1_dir
|
||||
del self.remote_2_dir
|
||||
|
||||
|
||||
class RepoTree:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def __enter__(self):
|
||||
self.root = tempfile.TemporaryDirectory()
|
||||
self.config = tempfile.NamedTemporaryFile()
|
||||
with open(self.config.name, "w") as f:
|
||||
f.write(
|
||||
f"""
|
||||
[[trees]]
|
||||
root = "{self.root.name}"
|
||||
|
||||
[[trees.repos]]
|
||||
name = "test"
|
||||
|
||||
[[trees.repos]]
|
||||
name = "test_worktree"
|
||||
worktree_setup = true
|
||||
"""
|
||||
)
|
||||
|
||||
cmd = grm(["repos", "sync", "--config", self.config.name])
|
||||
assert cmd.returncode == 0
|
||||
return (self.root.name, self.config.name, ["test", "test_worktree"])
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
del self.root
|
||||
del self.config
|
||||
|
||||
|
||||
class EmptyDir:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def __enter__(self):
|
||||
self.tmpdir = tempfile.TemporaryDirectory()
|
||||
return self.tmpdir.name
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
del self.tmpdir
|
||||
|
||||
|
||||
class NonGitDir:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def __enter__(self):
|
||||
self.tmpdir = tempfile.TemporaryDirectory()
|
||||
shell(
|
||||
f"""
|
||||
cd {self.tmpdir.name}
|
||||
mkdir testdir
|
||||
touch testdir/test
|
||||
touch test2
|
||||
"""
|
||||
)
|
||||
return self.tmpdir.name
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
del self.tmpdir
|
||||
|
||||
|
||||
class TempGitFileRemote:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def __enter__(self):
|
||||
self.tmpdir = tempfile.TemporaryDirectory()
|
||||
shell(
|
||||
f"""
|
||||
cd {self.tmpdir.name}
|
||||
git init
|
||||
echo test > root-commit-in-remote-1
|
||||
git add root-commit-in-remote-1
|
||||
git commit -m "root-commit-in-remote-1"
|
||||
echo test > root-commit-in-remote-2
|
||||
git add root-commit-in-remote-2
|
||||
git commit -m "root-commit-in-remote-2"
|
||||
git ls-files | xargs rm -rf
|
||||
mv .git/* .
|
||||
git config core.bare true
|
||||
"""
|
||||
)
|
||||
head_commit_sha = git.Repo(self.tmpdir.name).head.commit.hexsha
|
||||
return (self.tmpdir.name, head_commit_sha)
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
del self.tmpdir
|
||||
|
||||
|
||||
class NonExistentPath:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def __enter__(self):
|
||||
self.dir = "/doesnotexist"
|
||||
if os.path.exists(self.dir):
|
||||
raise f"{self.dir} exists for some reason"
|
||||
return self.dir
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
pass
|
||||
14
e2e_tests/requirements.txt
Normal file
14
e2e_tests/requirements.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
attrs==21.4.0
|
||||
gitdb==4.0.9
|
||||
GitPython==3.1.27
|
||||
iniconfig==1.1.1
|
||||
packaging==21.3
|
||||
pluggy==1.0.0
|
||||
py==1.11.0
|
||||
pyparsing==3.0.7
|
||||
pytest==7.0.1
|
||||
PyYAML==6.0
|
||||
smmap==5.0.0
|
||||
toml==0.10.2
|
||||
tomli==2.0.1
|
||||
typing_extensions==4.1.1
|
||||
13
e2e_tests/test_basic.py
Normal file
13
e2e_tests/test_basic.py
Normal file
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from helpers import *
|
||||
|
||||
|
||||
def test_invalid_command():
|
||||
cmd = grm(["whatever"], is_invalid=True)
|
||||
assert "USAGE" in cmd.stderr
|
||||
|
||||
|
||||
def test_help():
|
||||
cmd = grm(["--help"])
|
||||
assert "USAGE" in cmd.stdout
|
||||
277
e2e_tests/test_repos_find.py
Normal file
277
e2e_tests/test_repos_find.py
Normal file
@@ -0,0 +1,277 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import tempfile
|
||||
|
||||
import toml
|
||||
import pytest
|
||||
import yaml
|
||||
|
||||
from helpers import *
|
||||
|
||||
|
||||
def test_repos_find_nonexistent():
|
||||
with NonExistentPath() as nonexistent_dir:
|
||||
cmd = grm(["repos", "find", nonexistent_dir])
|
||||
assert "does not exist" in cmd.stderr.lower()
|
||||
assert cmd.returncode != 0
|
||||
assert not os.path.exists(nonexistent_dir)
|
||||
|
||||
|
||||
def test_repos_find_file():
|
||||
with tempfile.NamedTemporaryFile() as tmpfile:
|
||||
cmd = grm(["repos", "find", tmpfile.name])
|
||||
assert "not a directory" in cmd.stderr.lower()
|
||||
assert cmd.returncode != 0
|
||||
|
||||
|
||||
def test_repos_find_empty():
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
cmd = grm(["repos", "find", tmpdir])
|
||||
assert cmd.returncode == 0
|
||||
assert len(cmd.stdout) == 0
|
||||
assert len(cmd.stderr) != 0
|
||||
|
||||
|
||||
def test_repos_find_invalid_format():
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
cmd = grm(
|
||||
["repos", "find", tmpdir, "--format", "invalidformat"], is_invalid=True
|
||||
)
|
||||
assert cmd.returncode != 0
|
||||
assert len(cmd.stdout) == 0
|
||||
assert "isn't a valid value" in cmd.stderr
|
||||
|
||||
|
||||
def test_repos_find_non_git_repos():
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
shell(
|
||||
f"""
|
||||
cd {tmpdir}
|
||||
mkdir non_git
|
||||
(
|
||||
cd ./non_git
|
||||
echo test > test
|
||||
)
|
||||
"""
|
||||
)
|
||||
|
||||
cmd = grm(["repos", "find", tmpdir])
|
||||
|
||||
assert cmd.returncode == 0
|
||||
assert len(cmd.stdout) == 0
|
||||
assert len(cmd.stderr) != 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize("default", [True, False])
|
||||
@pytest.mark.parametrize("configtype", ["toml", "yaml"])
|
||||
def test_repos_find(configtype, default):
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
shell(
|
||||
f"""
|
||||
cd {tmpdir}
|
||||
mkdir repo1
|
||||
(
|
||||
cd ./repo1
|
||||
git init
|
||||
echo test > test
|
||||
git add test
|
||||
git commit -m "commit1"
|
||||
git remote add origin https://example.com/repo2.git
|
||||
git remote add someremote ssh://example.com/repo2.git
|
||||
)
|
||||
mkdir repo2
|
||||
(
|
||||
cd ./repo2
|
||||
git init
|
||||
git co -b main
|
||||
echo test > test
|
||||
git add test
|
||||
git commit -m "commit1"
|
||||
git remote add origin https://example.com/repo2.git
|
||||
)
|
||||
mkdir non_git
|
||||
(
|
||||
cd non_git
|
||||
echo test > test
|
||||
)
|
||||
"""
|
||||
)
|
||||
|
||||
args = ["repos", "find", tmpdir]
|
||||
if not default:
|
||||
args += ["--format", configtype]
|
||||
cmd = grm(args)
|
||||
assert cmd.returncode == 0
|
||||
assert len(cmd.stderr) == 0
|
||||
|
||||
if default or configtype == "toml":
|
||||
output = toml.loads(cmd.stdout)
|
||||
elif configtype == "yaml":
|
||||
output = yaml.safe_load(cmd.stdout)
|
||||
else:
|
||||
raise NotImplementedError()
|
||||
|
||||
assert isinstance(output, dict)
|
||||
assert set(output.keys()) == {"trees"}
|
||||
assert isinstance(output["trees"], list)
|
||||
assert len(output["trees"]) == 1
|
||||
for tree in output["trees"]:
|
||||
assert set(tree.keys()) == {"root", "repos"}
|
||||
assert tree["root"] == tmpdir
|
||||
assert isinstance(tree["repos"], list)
|
||||
assert len(tree["repos"]) == 2
|
||||
|
||||
repo1 = [r for r in tree["repos"] if r["name"] == "repo1"][0]
|
||||
assert repo1["worktree_setup"] is False
|
||||
assert isinstance(repo1["remotes"], list)
|
||||
assert len(repo1["remotes"]) == 2
|
||||
|
||||
origin = [r for r in repo1["remotes"] if r["name"] == "origin"][0]
|
||||
assert set(origin.keys()) == {"name", "type", "url"}
|
||||
assert origin["type"] == "https"
|
||||
assert origin["url"] == "https://example.com/repo2.git"
|
||||
|
||||
someremote = [r for r in repo1["remotes"] if r["name"] == "someremote"][0]
|
||||
assert set(origin.keys()) == {"name", "type", "url"}
|
||||
assert someremote["type"] == "ssh"
|
||||
assert someremote["url"] == "ssh://example.com/repo2.git"
|
||||
|
||||
repo2 = [r for r in tree["repos"] if r["name"] == "repo2"][0]
|
||||
assert repo2["worktree_setup"] is False
|
||||
assert isinstance(repo1["remotes"], list)
|
||||
assert len(repo2["remotes"]) == 1
|
||||
|
||||
origin = [r for r in repo2["remotes"] if r["name"] == "origin"][0]
|
||||
assert set(origin.keys()) == {"name", "type", "url"}
|
||||
assert origin["type"] == "https"
|
||||
assert origin["url"] == "https://example.com/repo2.git"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("default", [True, False])
|
||||
@pytest.mark.parametrize("configtype", ["toml", "yaml"])
|
||||
def test_repos_find_in_root(configtype, default):
|
||||
with TempGitRepository() as repo_dir:
|
||||
|
||||
args = ["repos", "find", repo_dir]
|
||||
if not default:
|
||||
args += ["--format", configtype]
|
||||
cmd = grm(args)
|
||||
assert cmd.returncode == 0
|
||||
assert len(cmd.stderr) == 0
|
||||
|
||||
if default or configtype == "toml":
|
||||
output = toml.loads(cmd.stdout)
|
||||
elif configtype == "yaml":
|
||||
output = yaml.safe_load(cmd.stdout)
|
||||
else:
|
||||
raise NotImplementedError()
|
||||
|
||||
assert isinstance(output, dict)
|
||||
assert set(output.keys()) == {"trees"}
|
||||
assert isinstance(output["trees"], list)
|
||||
assert len(output["trees"]) == 1
|
||||
for tree in output["trees"]:
|
||||
assert set(tree.keys()) == {"root", "repos"}
|
||||
assert tree["root"] == os.path.dirname(repo_dir)
|
||||
assert isinstance(tree["repos"], list)
|
||||
assert len(tree["repos"]) == 1
|
||||
|
||||
repo1 = [
|
||||
r for r in tree["repos"] if r["name"] == os.path.basename(repo_dir)
|
||||
][0]
|
||||
assert repo1["worktree_setup"] is False
|
||||
assert isinstance(repo1["remotes"], list)
|
||||
assert len(repo1["remotes"]) == 2
|
||||
|
||||
origin = [r for r in repo1["remotes"] if r["name"] == "origin"][0]
|
||||
assert set(origin.keys()) == {"name", "type", "url"}
|
||||
assert origin["type"] == "file"
|
||||
|
||||
someremote = [r for r in repo1["remotes"] if r["name"] == "otherremote"][0]
|
||||
assert set(origin.keys()) == {"name", "type", "url"}
|
||||
assert someremote["type"] == "file"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("configtype", ["toml", "yaml"])
|
||||
@pytest.mark.parametrize("default", [True, False])
|
||||
def test_repos_find_with_invalid_repo(configtype, default):
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
shell(
|
||||
f"""
|
||||
cd {tmpdir}
|
||||
mkdir repo1
|
||||
(
|
||||
cd ./repo1
|
||||
git init
|
||||
echo test > test
|
||||
git add test
|
||||
git commit -m "commit1"
|
||||
git remote add origin https://example.com/repo2.git
|
||||
git remote add someremote ssh://example.com/repo2.git
|
||||
)
|
||||
mkdir repo2
|
||||
(
|
||||
cd ./repo2
|
||||
git init
|
||||
git co -b main
|
||||
echo test > test
|
||||
git add test
|
||||
git commit -m "commit1"
|
||||
git remote add origin https://example.com/repo2.git
|
||||
)
|
||||
mkdir broken_repo
|
||||
(
|
||||
cd broken_repo
|
||||
echo "broken" > .git
|
||||
)
|
||||
"""
|
||||
)
|
||||
|
||||
args = ["repos", "find", tmpdir]
|
||||
if not default:
|
||||
args += ["--format", configtype]
|
||||
cmd = grm(args)
|
||||
assert cmd.returncode == 0
|
||||
assert "broken" in cmd.stderr
|
||||
|
||||
if default or configtype == "toml":
|
||||
output = toml.loads(cmd.stdout)
|
||||
elif configtype == "yaml":
|
||||
output = yaml.safe_load(cmd.stdout)
|
||||
else:
|
||||
raise NotImplementedError()
|
||||
|
||||
assert isinstance(output, dict)
|
||||
assert set(output.keys()) == {"trees"}
|
||||
assert isinstance(output["trees"], list)
|
||||
assert len(output["trees"]) == 1
|
||||
for tree in output["trees"]:
|
||||
assert set(tree.keys()) == {"root", "repos"}
|
||||
assert tree["root"] == tmpdir
|
||||
assert isinstance(tree["repos"], list)
|
||||
assert len(tree["repos"]) == 2
|
||||
|
||||
repo1 = [r for r in tree["repos"] if r["name"] == "repo1"][0]
|
||||
assert repo1["worktree_setup"] is False
|
||||
assert isinstance(repo1["remotes"], list)
|
||||
assert len(repo1["remotes"]) == 2
|
||||
|
||||
origin = [r for r in repo1["remotes"] if r["name"] == "origin"][0]
|
||||
assert set(origin.keys()) == {"name", "type", "url"}
|
||||
assert origin["type"] == "https"
|
||||
assert origin["url"] == "https://example.com/repo2.git"
|
||||
|
||||
someremote = [r for r in repo1["remotes"] if r["name"] == "someremote"][0]
|
||||
assert set(origin.keys()) == {"name", "type", "url"}
|
||||
assert someremote["type"] == "ssh"
|
||||
assert someremote["url"] == "ssh://example.com/repo2.git"
|
||||
|
||||
repo2 = [r for r in tree["repos"] if r["name"] == "repo2"][0]
|
||||
assert repo2["worktree_setup"] is False
|
||||
assert isinstance(repo1["remotes"], list)
|
||||
assert len(repo2["remotes"]) == 1
|
||||
|
||||
origin = [r for r in repo2["remotes"] if r["name"] == "origin"][0]
|
||||
assert set(origin.keys()) == {"name", "type", "url"}
|
||||
assert origin["type"] == "https"
|
||||
assert origin["url"] == "https://example.com/repo2.git"
|
||||
13
e2e_tests/test_repos_status.py
Normal file
13
e2e_tests/test_repos_status.py
Normal file
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import tempfile
|
||||
|
||||
from helpers import *
|
||||
|
||||
|
||||
def test_repos_sync_worktree_clone():
|
||||
with RepoTree() as (root, config, repos):
|
||||
cmd = grm(["repos", "status", "--config", config])
|
||||
assert cmd.returncode == 0
|
||||
for repo in repos:
|
||||
assert repo in cmd.stdout
|
||||
663
e2e_tests/test_repos_sync.py
Normal file
663
e2e_tests/test_repos_sync.py
Normal file
@@ -0,0 +1,663 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import tempfile
|
||||
import re
|
||||
import textwrap
|
||||
|
||||
import pytest
|
||||
import toml
|
||||
import git
|
||||
|
||||
from helpers import *
|
||||
|
||||
templates = {
|
||||
"repo_simple": {
|
||||
"toml": """
|
||||
[[trees]]
|
||||
root = "{root}"
|
||||
|
||||
[[trees.repos]]
|
||||
name = "test"
|
||||
""",
|
||||
"yaml": """
|
||||
trees:
|
||||
- root: "{root}"
|
||||
repos:
|
||||
- name: "test"
|
||||
""",
|
||||
},
|
||||
"repo_with_remote": {
|
||||
"toml": """
|
||||
[[trees]]
|
||||
root = "{root}"
|
||||
|
||||
[[trees.repos]]
|
||||
name = "test"
|
||||
|
||||
[[trees.repos.remotes]]
|
||||
name = "{remotename}"
|
||||
url = "file://{remote}"
|
||||
type = "file"
|
||||
""",
|
||||
"yaml": textwrap.dedent(
|
||||
"""
|
||||
trees:
|
||||
- root: "{root}"
|
||||
repos:
|
||||
- name: test
|
||||
remotes:
|
||||
- name: "{remotename}"
|
||||
url: "file://{remote}"
|
||||
type: "file"
|
||||
"""
|
||||
),
|
||||
},
|
||||
"repo_with_two_remotes": {
|
||||
"toml": """
|
||||
[[trees]]
|
||||
root = "{root}"
|
||||
|
||||
[[trees.repos]]
|
||||
name = "test"
|
||||
|
||||
[[trees.repos.remotes]]
|
||||
name = "origin"
|
||||
url = "file://{remote1}"
|
||||
type = "file"
|
||||
|
||||
[[trees.repos.remotes]]
|
||||
name = "origin2"
|
||||
url = "file://{remote2}"
|
||||
type = "file"
|
||||
""",
|
||||
"yaml": textwrap.dedent(
|
||||
"""
|
||||
trees:
|
||||
- root: "{root}"
|
||||
repos:
|
||||
- name: "test"
|
||||
remotes:
|
||||
- name: "origin"
|
||||
url: "file://{remote1}"
|
||||
type: "file"
|
||||
- name: "origin2"
|
||||
url: "file://{remote2}"
|
||||
type: "file"
|
||||
"""
|
||||
),
|
||||
},
|
||||
"worktree_repo_simple": {
|
||||
"toml": """
|
||||
[[trees]]
|
||||
root = "{root}"
|
||||
|
||||
[[trees.repos]]
|
||||
name = "test"
|
||||
worktree_setup = true
|
||||
""",
|
||||
"yaml": textwrap.dedent(
|
||||
"""
|
||||
trees:
|
||||
- root: "{root}"
|
||||
repos:
|
||||
- name: test
|
||||
worktree_setup: true
|
||||
"""
|
||||
),
|
||||
},
|
||||
"worktree_repo_with_remote": {
|
||||
"toml": """
|
||||
[[trees]]
|
||||
root = "{root}"
|
||||
|
||||
[[trees.repos]]
|
||||
name = "test"
|
||||
worktree_setup = true
|
||||
|
||||
[[trees.repos.remotes]]
|
||||
name = "origin"
|
||||
url = "file://{remote}"
|
||||
type = "file"
|
||||
""",
|
||||
"yaml": textwrap.dedent(
|
||||
"""
|
||||
trees:
|
||||
- root: "{root}"
|
||||
repos:
|
||||
- name: test
|
||||
worktree_setup: true
|
||||
remotes:
|
||||
- name: origin
|
||||
url: "file://{remote}"
|
||||
type: "file"
|
||||
"""
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("configtype", ["toml", "yaml"])
|
||||
def test_repos_sync_config_is_valid_symlink(configtype):
|
||||
with tempfile.TemporaryDirectory() as target:
|
||||
with TempGitFileRemote() as (remote, head_commit_sha):
|
||||
with tempfile.NamedTemporaryFile() as config:
|
||||
with tempfile.TemporaryDirectory() as config_dir:
|
||||
config_symlink = os.path.join(config_dir, "cfglink")
|
||||
os.symlink(config.name, config_symlink)
|
||||
|
||||
with open(config.name, "w") as f:
|
||||
f.write(
|
||||
templates["repo_with_remote"][configtype].format(
|
||||
root=target, remote=remote, remotename="origin"
|
||||
)
|
||||
)
|
||||
|
||||
subprocess.run(["cat", config.name])
|
||||
|
||||
cmd = grm(["repos", "sync", "--config", config_symlink])
|
||||
assert cmd.returncode == 0
|
||||
|
||||
git_dir = os.path.join(target, "test")
|
||||
assert os.path.exists(git_dir)
|
||||
with git.Repo(git_dir) as repo:
|
||||
assert not repo.bare
|
||||
assert not repo.is_dirty()
|
||||
assert set([str(r) for r in repo.remotes]) == {"origin"}
|
||||
assert str(repo.active_branch) == "master"
|
||||
assert str(repo.head.commit) == head_commit_sha
|
||||
|
||||
|
||||
def test_repos_sync_config_is_invalid_symlink():
|
||||
with tempfile.TemporaryDirectory() as target:
|
||||
with tempfile.TemporaryDirectory() as config_dir:
|
||||
with NonExistentPath() as nonexistent_dir:
|
||||
config_symlink = os.path.join(config_dir, "cfglink")
|
||||
os.symlink(nonexistent_dir, config_symlink)
|
||||
|
||||
cmd = grm(["repos", "sync", "--config", config_symlink])
|
||||
|
||||
assert cmd.returncode != 0
|
||||
assert len(cmd.stdout) == 0
|
||||
assert "not found" in cmd.stderr.lower()
|
||||
assert not os.path.exists(os.path.join(target, "test"))
|
||||
assert not os.path.exists(os.path.join(target, "test"))
|
||||
|
||||
|
||||
def test_repos_sync_config_is_directory():
|
||||
with tempfile.TemporaryDirectory() as config:
|
||||
cmd = grm(["repos", "sync", "--config", config])
|
||||
|
||||
assert cmd.returncode != 0
|
||||
assert len(cmd.stdout) == 0
|
||||
assert "is a directory" in cmd.stderr.lower()
|
||||
|
||||
|
||||
def test_repos_sync_config_is_unreadable():
|
||||
with tempfile.TemporaryDirectory() as config_dir:
|
||||
config_path = os.path.join(config_dir, "cfg")
|
||||
open(config_path, "w")
|
||||
os.chmod(config_path, 0o0000)
|
||||
cmd = grm(["repos", "sync", "--config", config_path])
|
||||
|
||||
assert os.path.exists(config_path)
|
||||
assert cmd.returncode != 0
|
||||
assert len(cmd.stdout) == 0
|
||||
assert "permission denied" in cmd.stderr.lower()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("configtype", ["toml", "yaml"])
|
||||
def test_repos_sync_unmanaged_repos(configtype):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
with TempGitRepository(dir=root) as unmanaged_repo:
|
||||
with tempfile.NamedTemporaryFile() as config:
|
||||
with open(config.name, "w") as f:
|
||||
f.write(templates["repo_simple"][configtype].format(root=root))
|
||||
|
||||
cmd = grm(["repos", "sync", "--config", config.name])
|
||||
assert cmd.returncode == 0
|
||||
|
||||
git_dir = os.path.join(root, "test")
|
||||
assert os.path.exists(git_dir)
|
||||
|
||||
# this removes the prefix (root) from the path (unmanaged_repo)
|
||||
unmanaged_repo_name = os.path.relpath(unmanaged_repo, root)
|
||||
regex = f".*unmanaged.*{unmanaged_repo_name}"
|
||||
assert any([re.match(regex, l) for l in cmd.stderr.lower().split("\n")])
|
||||
|
||||
|
||||
@pytest.mark.parametrize("configtype", ["toml", "yaml"])
|
||||
def test_repos_sync_root_is_file(configtype):
|
||||
with tempfile.NamedTemporaryFile() as target:
|
||||
with tempfile.NamedTemporaryFile() as config:
|
||||
with open(config.name, "w") as f:
|
||||
f.write(templates["repo_simple"][configtype].format(root=target.name))
|
||||
|
||||
cmd = grm(["repos", "sync", "--config", config.name])
|
||||
assert cmd.returncode != 0
|
||||
assert len(cmd.stdout) == 0
|
||||
assert "not a directory" in cmd.stderr.lower()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("configtype", ["toml", "yaml"])
|
||||
def test_repos_sync_normal_clone(configtype):
|
||||
with tempfile.TemporaryDirectory() as target:
|
||||
with TempGitFileRemote() as (remote1, remote1_head_commit_sha):
|
||||
with TempGitFileRemote() as (remote2, remote2_head_commit_sha):
|
||||
with tempfile.NamedTemporaryFile() as config:
|
||||
with open(config.name, "w") as f:
|
||||
f.write(
|
||||
templates["repo_with_two_remotes"][configtype].format(
|
||||
root=target, remote1=remote1, remote2=remote2
|
||||
)
|
||||
)
|
||||
|
||||
cmd = grm(["repos", "sync", "--config", config.name])
|
||||
assert cmd.returncode == 0
|
||||
|
||||
git_dir = os.path.join(target, "test")
|
||||
assert os.path.exists(git_dir)
|
||||
with git.Repo(git_dir) as repo:
|
||||
assert not repo.bare
|
||||
assert not repo.is_dirty()
|
||||
assert set([str(r) for r in repo.remotes]) == {
|
||||
"origin",
|
||||
"origin2",
|
||||
}
|
||||
assert str(repo.active_branch) == "master"
|
||||
assert str(repo.head.commit) == remote1_head_commit_sha
|
||||
|
||||
assert len(repo.remotes) == 2
|
||||
urls = list(repo.remote("origin").urls)
|
||||
assert len(urls) == 1
|
||||
assert urls[0] == f"file://{remote1}"
|
||||
|
||||
urls = list(repo.remote("origin2").urls)
|
||||
assert len(urls) == 1
|
||||
assert urls[0] == f"file://{remote2}"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("configtype", ["toml", "yaml"])
|
||||
def test_repos_sync_normal_init(configtype):
|
||||
with tempfile.TemporaryDirectory() as target:
|
||||
with tempfile.NamedTemporaryFile() as config:
|
||||
with open(config.name, "w") as f:
|
||||
f.write(templates["repo_simple"][configtype].format(root=target))
|
||||
|
||||
cmd = grm(["repos", "sync", "--config", config.name])
|
||||
assert cmd.returncode == 0
|
||||
|
||||
git_dir = os.path.join(target, "test")
|
||||
assert os.path.exists(git_dir)
|
||||
with git.Repo(git_dir) as repo:
|
||||
assert not repo.bare
|
||||
assert not repo.is_dirty()
|
||||
# as there are no commits yet, HEAD does not point to anything
|
||||
# valid
|
||||
assert not repo.head.is_valid()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("configtype", ["toml", "yaml"])
|
||||
def test_repos_sync_normal_add_remote(configtype):
|
||||
with tempfile.TemporaryDirectory() as target:
|
||||
with TempGitFileRemote() as (remote1, remote1_head_commit_sha):
|
||||
with TempGitFileRemote() as (remote2, remote2_head_commit_sha):
|
||||
with tempfile.NamedTemporaryFile() as config:
|
||||
with open(config.name, "w") as f:
|
||||
f.write(
|
||||
templates["repo_with_remote"][configtype].format(
|
||||
root=target, remote=remote1, remotename="origin"
|
||||
)
|
||||
)
|
||||
|
||||
cmd = grm(["repos", "sync", "--config", config.name])
|
||||
assert cmd.returncode == 0
|
||||
|
||||
git_dir = os.path.join(target, "test")
|
||||
|
||||
assert os.path.exists(git_dir)
|
||||
with git.Repo(git_dir) as repo:
|
||||
assert not repo.bare
|
||||
assert not repo.is_dirty()
|
||||
assert set([str(r) for r in repo.remotes]) == {"origin"}
|
||||
assert str(repo.active_branch) == "master"
|
||||
assert str(repo.head.commit) == remote1_head_commit_sha
|
||||
|
||||
with open(config.name, "w") as f:
|
||||
f.write(
|
||||
templates["repo_with_two_remotes"][configtype].format(
|
||||
root=target, remote1=remote1, remote2=remote2
|
||||
)
|
||||
)
|
||||
|
||||
cmd = grm(["repos", "sync", "--config", config.name])
|
||||
assert cmd.returncode == 0
|
||||
with git.Repo(git_dir) as repo:
|
||||
assert set([str(r) for r in repo.remotes]) == {
|
||||
"origin",
|
||||
"origin2",
|
||||
}
|
||||
|
||||
urls = list(repo.remote("origin").urls)
|
||||
assert len(urls) == 1
|
||||
assert urls[0] == f"file://{remote1}"
|
||||
|
||||
urls = list(repo.remote("origin2").urls)
|
||||
assert len(urls) == 1
|
||||
assert urls[0] == f"file://{remote2}"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("configtype", ["toml", "yaml"])
|
||||
def test_repos_sync_normal_remove_remote(configtype):
|
||||
with tempfile.TemporaryDirectory() as target:
|
||||
with TempGitFileRemote() as (remote1, remote1_head_commit_sha):
|
||||
with TempGitFileRemote() as (remote2, remote2_head_commit_sha):
|
||||
with tempfile.NamedTemporaryFile() as config:
|
||||
with open(config.name, "w") as f:
|
||||
f.write(
|
||||
templates["repo_with_two_remotes"][configtype].format(
|
||||
root=target, remote1=remote1, remote2=remote2
|
||||
)
|
||||
)
|
||||
|
||||
cmd = grm(["repos", "sync", "--config", config.name])
|
||||
assert cmd.returncode == 0
|
||||
|
||||
git_dir = os.path.join(target, "test")
|
||||
|
||||
assert os.path.exists(git_dir)
|
||||
with git.Repo(git_dir) as repo:
|
||||
assert not repo.bare
|
||||
assert not repo.is_dirty()
|
||||
assert set([str(r) for r in repo.remotes]) == {
|
||||
"origin",
|
||||
"origin2",
|
||||
}
|
||||
assert str(repo.active_branch) == "master"
|
||||
assert str(repo.head.commit) == remote1_head_commit_sha
|
||||
|
||||
with open(config.name, "w") as f:
|
||||
f.write(
|
||||
templates["repo_with_remote"][configtype].format(
|
||||
root=target, remote=remote2, remotename="origin2"
|
||||
)
|
||||
)
|
||||
|
||||
cmd = grm(["repos", "sync", "--config", config.name])
|
||||
assert cmd.returncode == 0
|
||||
shell(f"cd {git_dir} && git remote -v")
|
||||
with git.Repo(git_dir) as repo:
|
||||
"""
|
||||
There is some bug(?) in GitPython. It does not properly
|
||||
detect removed remotes. It will still report the old
|
||||
remove in repo.remotes.
|
||||
|
||||
So instead, we make sure that we get an Exception when
|
||||
we try to access the old remove via repo.remote().
|
||||
|
||||
Note that repo.remote() checks the actual repo lazily.
|
||||
Even `exists()` seems to just check against repo.remotes
|
||||
and will return True even if the remote is not actually
|
||||
configured. So we have to force GitPython to hit the filesystem.
|
||||
calling Remotes.urls does. But it returns an iterator
|
||||
that first has to be unwrapped via list(). Only THEN
|
||||
do we actually get an exception of the remotes does not
|
||||
exist.
|
||||
"""
|
||||
with pytest.raises(git.exc.GitCommandError):
|
||||
list(repo.remote("origin").urls)
|
||||
|
||||
urls = list(repo.remote("origin2").urls)
|
||||
assert len(urls) == 1
|
||||
assert urls[0] == f"file://{remote2}"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("configtype", ["toml", "yaml"])
|
||||
def test_repos_sync_normal_change_remote_url(configtype):
|
||||
with tempfile.TemporaryDirectory() as target:
|
||||
with TempGitFileRemote() as (remote1, remote1_head_commit_sha):
|
||||
with TempGitFileRemote() as (remote2, remote2_head_commit_sha):
|
||||
with tempfile.NamedTemporaryFile() as config:
|
||||
with open(config.name, "w") as f:
|
||||
f.write(
|
||||
templates["repo_with_remote"][configtype].format(
|
||||
root=target, remote=remote1, remotename="origin"
|
||||
)
|
||||
)
|
||||
|
||||
cmd = grm(["repos", "sync", "--config", config.name])
|
||||
assert cmd.returncode == 0
|
||||
|
||||
git_dir = os.path.join(target, "test")
|
||||
|
||||
assert os.path.exists(git_dir)
|
||||
with git.Repo(git_dir) as repo:
|
||||
assert not repo.bare
|
||||
assert not repo.is_dirty()
|
||||
assert set([str(r) for r in repo.remotes]) == {"origin"}
|
||||
assert str(repo.active_branch) == "master"
|
||||
assert str(repo.head.commit) == remote1_head_commit_sha
|
||||
|
||||
with open(config.name, "w") as f:
|
||||
f.write(
|
||||
templates["repo_with_remote"][configtype].format(
|
||||
root=target, remote=remote2, remotename="origin"
|
||||
)
|
||||
)
|
||||
|
||||
cmd = grm(["repos", "sync", "--config", config.name])
|
||||
assert cmd.returncode == 0
|
||||
with git.Repo(git_dir) as repo:
|
||||
assert set([str(r) for r in repo.remotes]) == {"origin"}
|
||||
|
||||
urls = list(repo.remote("origin").urls)
|
||||
assert len(urls) == 1
|
||||
assert urls[0] == f"file://{remote2}"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("configtype", ["toml", "yaml"])
|
||||
def test_repos_sync_normal_change_remote_name(configtype):
|
||||
with tempfile.TemporaryDirectory() as target:
|
||||
with TempGitFileRemote() as (remote1, remote1_head_commit_sha):
|
||||
with TempGitFileRemote() as (remote2, remote2_head_commit_sha):
|
||||
with tempfile.NamedTemporaryFile() as config:
|
||||
with open(config.name, "w") as f:
|
||||
f.write(
|
||||
templates["repo_with_remote"][configtype].format(
|
||||
root=target, remote=remote1, remotename="origin"
|
||||
)
|
||||
)
|
||||
|
||||
cmd = grm(["repos", "sync", "--config", config.name])
|
||||
assert cmd.returncode == 0
|
||||
|
||||
git_dir = os.path.join(target, "test")
|
||||
|
||||
assert os.path.exists(git_dir)
|
||||
with git.Repo(git_dir) as repo:
|
||||
assert not repo.bare
|
||||
assert not repo.is_dirty()
|
||||
assert set([str(r) for r in repo.remotes]) == {"origin"}
|
||||
assert str(repo.active_branch) == "master"
|
||||
assert str(repo.head.commit) == remote1_head_commit_sha
|
||||
|
||||
with open(config.name, "w") as f:
|
||||
f.write(
|
||||
templates["repo_with_remote"][configtype].format(
|
||||
root=target, remote=remote1, remotename="origin2"
|
||||
)
|
||||
)
|
||||
|
||||
cmd = grm(["repos", "sync", "--config", config.name])
|
||||
assert cmd.returncode == 0
|
||||
with git.Repo(git_dir) as repo:
|
||||
# See the note in `test_repos_sync_normal_remove_remote()`
|
||||
# about repo.remotes
|
||||
with pytest.raises(git.exc.GitCommandError):
|
||||
list(repo.remote("origin").urls)
|
||||
|
||||
urls = list(repo.remote("origin2").urls)
|
||||
assert len(urls) == 1
|
||||
assert urls[0] == f"file://{remote1}"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("configtype", ["toml", "yaml"])
|
||||
def test_repos_sync_worktree_clone(configtype):
|
||||
with tempfile.TemporaryDirectory() as target:
|
||||
with TempGitFileRemote() as (remote, head_commit_sha):
|
||||
with tempfile.NamedTemporaryFile() as config:
|
||||
with open(config.name, "w") as f:
|
||||
f.write(
|
||||
templates["worktree_repo_with_remote"][configtype].format(
|
||||
root=target, remote=remote, remotename="origin"
|
||||
)
|
||||
)
|
||||
|
||||
cmd = grm(["repos", "sync", "--config", config.name])
|
||||
assert cmd.returncode == 0
|
||||
|
||||
worktree_dir = f"{target}/test"
|
||||
assert os.path.exists(worktree_dir)
|
||||
|
||||
assert set(os.listdir(worktree_dir)) == {".git-main-working-tree"}
|
||||
|
||||
with git.Repo(
|
||||
os.path.join(worktree_dir, ".git-main-working-tree")
|
||||
) as repo:
|
||||
assert repo.bare
|
||||
assert set([str(r) for r in repo.remotes]) == {"origin"}
|
||||
assert str(repo.active_branch) == "master"
|
||||
assert str(repo.head.commit) == head_commit_sha
|
||||
|
||||
|
||||
@pytest.mark.parametrize("configtype", ["toml", "yaml"])
|
||||
def test_repos_sync_worktree_init(configtype):
|
||||
with tempfile.TemporaryDirectory() as target:
|
||||
with tempfile.NamedTemporaryFile() as config:
|
||||
with open(config.name, "w") as f:
|
||||
f.write(
|
||||
templates["worktree_repo_simple"][configtype].format(root=target)
|
||||
)
|
||||
|
||||
cmd = grm(["repos", "sync", "--config", config.name])
|
||||
assert cmd.returncode == 0
|
||||
|
||||
worktree_dir = f"{target}/test"
|
||||
assert os.path.exists(worktree_dir)
|
||||
|
||||
assert set(os.listdir(worktree_dir)) == {".git-main-working-tree"}
|
||||
with git.Repo(os.path.join(worktree_dir, ".git-main-working-tree")) as repo:
|
||||
assert repo.bare
|
||||
# as there are no commits yet, HEAD does not point to anything
|
||||
# valid
|
||||
assert not repo.head.is_valid()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("configtype", ["toml", "yaml"])
|
||||
def test_repos_sync_invalid_syntax(configtype):
|
||||
with tempfile.NamedTemporaryFile() as config:
|
||||
with open(config.name, "w") as f:
|
||||
if configtype == "toml":
|
||||
f.write(
|
||||
f"""
|
||||
[[trees]]
|
||||
root = invalid as there are no quotes ;)
|
||||
"""
|
||||
)
|
||||
elif configtype == "yaml":
|
||||
f.write(
|
||||
f"""
|
||||
trees:
|
||||
wrong:
|
||||
indentation:
|
||||
"""
|
||||
)
|
||||
else:
|
||||
raise NotImplementedError()
|
||||
cmd = grm(["repos", "sync", "--config", config.name])
|
||||
assert cmd.returncode != 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize("configtype", ["toml", "yaml"])
|
||||
def test_repos_sync_unchanged(configtype):
|
||||
with tempfile.TemporaryDirectory() as target:
|
||||
with TempGitFileRemote() as (remote1, remote1_head_commit_sha):
|
||||
with TempGitFileRemote() as (remote2, remote2_head_commit_sha):
|
||||
with tempfile.NamedTemporaryFile() as config:
|
||||
with open(config.name, "w") as f:
|
||||
f.write(
|
||||
templates["repo_with_two_remotes"][configtype].format(
|
||||
root=target, remote1=remote1, remote2=remote2
|
||||
)
|
||||
)
|
||||
|
||||
cmd = grm(["repos", "sync", "--config", config.name])
|
||||
assert cmd.returncode == 0
|
||||
|
||||
before = checksum_directory(target)
|
||||
cmd = grm(["repos", "sync", "--config", config.name])
|
||||
after = checksum_directory(target)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
assert before == after
|
||||
|
||||
|
||||
@pytest.mark.parametrize("configtype", ["toml", "yaml"])
|
||||
def test_repos_sync_normal_change_to_worktree(configtype):
|
||||
with tempfile.TemporaryDirectory() as target:
|
||||
with TempGitFileRemote() as (remote1, remote1_head_commit_sha):
|
||||
with TempGitFileRemote() as (remote2, remote2_head_commit_sha):
|
||||
with tempfile.NamedTemporaryFile() as config:
|
||||
with open(config.name, "w") as f:
|
||||
f.write(
|
||||
templates["repo_with_remote"][configtype].format(
|
||||
root=target, remote=remote1, remotename="origin"
|
||||
)
|
||||
)
|
||||
|
||||
cmd = grm(["repos", "sync", "--config", config.name])
|
||||
assert cmd.returncode == 0
|
||||
|
||||
git_dir = os.path.join(target, "test")
|
||||
|
||||
with open(config.name, "w") as f:
|
||||
f.write(
|
||||
templates["worktree_repo_with_remote"][configtype].format(
|
||||
root=target, remote=remote1, remotename="origin"
|
||||
)
|
||||
)
|
||||
|
||||
cmd = grm(["repos", "sync", "--config", config.name])
|
||||
assert cmd.returncode != 0
|
||||
assert "already exists" in cmd.stderr
|
||||
assert "not using a worktree setup" in cmd.stderr
|
||||
|
||||
|
||||
@pytest.mark.parametrize("configtype", ["toml", "yaml"])
|
||||
def test_repos_sync_worktree_change_to_normal(configtype):
|
||||
with tempfile.TemporaryDirectory() as target:
|
||||
with TempGitFileRemote() as (remote1, remote1_head_commit_sha):
|
||||
with TempGitFileRemote() as (remote2, remote2_head_commit_sha):
|
||||
with tempfile.NamedTemporaryFile() as config:
|
||||
with open(config.name, "w") as f:
|
||||
f.write(
|
||||
templates["worktree_repo_with_remote"][configtype].format(
|
||||
root=target, remote=remote1, remotename="origin"
|
||||
)
|
||||
)
|
||||
|
||||
cmd = grm(["repos", "sync", "--config", config.name])
|
||||
assert cmd.returncode == 0
|
||||
|
||||
git_dir = os.path.join(target, "test")
|
||||
|
||||
with open(config.name, "w") as f:
|
||||
f.write(
|
||||
templates["repo_with_remote"][configtype].format(
|
||||
root=target, remote=remote1, remotename="origin"
|
||||
)
|
||||
)
|
||||
|
||||
cmd = grm(["repos", "sync", "--config", config.name])
|
||||
assert cmd.returncode != 0
|
||||
assert "already exists" in cmd.stderr
|
||||
assert "using a worktree setup" in cmd.stderr
|
||||
196
e2e_tests/test_worktree_clean.py
Normal file
196
e2e_tests/test_worktree_clean.py
Normal file
@@ -0,0 +1,196 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import pytest
|
||||
|
||||
from helpers import *
|
||||
|
||||
|
||||
def test_worktree_clean():
|
||||
with TempGitRepositoryWorktree() as (base_dir, _commit):
|
||||
cmd = grm(["wt", "add", "test", "--track", "origin/test"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
assert "test" in os.listdir(base_dir)
|
||||
|
||||
cmd = grm(["wt", "clean"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
assert "test" not in os.listdir(base_dir)
|
||||
|
||||
|
||||
def test_worktree_clean_refusal_no_tracking_branch():
|
||||
with TempGitRepositoryWorktree() as (base_dir, _commit):
|
||||
cmd = grm(["wt", "add", "test"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
before = checksum_directory(f"{base_dir}/test")
|
||||
cmd = grm(["wt", "clean"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
assert "test" in os.listdir(base_dir)
|
||||
|
||||
after = checksum_directory(f"{base_dir}/test")
|
||||
assert before == after
|
||||
|
||||
|
||||
def test_worktree_clean_refusal_uncommited_changes_new_file():
|
||||
with TempGitRepositoryWorktree() as (base_dir, _commit):
|
||||
cmd = grm(["wt", "add", "test", "--track", "origin/test"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
shell(f"cd {base_dir}/test && touch changed_file")
|
||||
|
||||
before = checksum_directory(f"{base_dir}/test")
|
||||
cmd = grm(["wt", "clean"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
assert "test" in os.listdir(base_dir)
|
||||
|
||||
after = checksum_directory(f"{base_dir}/test")
|
||||
assert before == after
|
||||
|
||||
|
||||
def test_worktree_clean_refusal_uncommited_changes_changed_file():
|
||||
with TempGitRepositoryWorktree() as (base_dir, _commit):
|
||||
cmd = grm(["wt", "add", "test", "--track", "origin/test"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
shell(f"cd {base_dir}/test && git ls-files | shuf | head | xargs rm -rf")
|
||||
|
||||
before = checksum_directory(f"{base_dir}/test")
|
||||
cmd = grm(["wt", "clean"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
assert "test" in os.listdir(base_dir)
|
||||
|
||||
after = checksum_directory(f"{base_dir}/test")
|
||||
assert before == after
|
||||
|
||||
|
||||
def test_worktree_clean_refusal_uncommited_changes_cleand_file():
|
||||
with TempGitRepositoryWorktree() as (base_dir, _commit):
|
||||
cmd = grm(["wt", "add", "test", "--track", "origin/test"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
shell(
|
||||
f"cd {base_dir}/test && git ls-files | shuf | head | while read f ; do echo $RANDOM > $f ; done"
|
||||
)
|
||||
|
||||
before = checksum_directory(f"{base_dir}/test")
|
||||
cmd = grm(["wt", "clean"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
assert "test" in os.listdir(base_dir)
|
||||
|
||||
after = checksum_directory(f"{base_dir}/test")
|
||||
assert before == after
|
||||
|
||||
|
||||
def test_worktree_clean_refusal_commited_changes():
|
||||
with TempGitRepositoryWorktree() as (base_dir, _commit):
|
||||
cmd = grm(["wt", "add", "test", "--track", "origin/test"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
shell(
|
||||
f'cd {base_dir}/test && touch changed_file && git add changed_file && git commit -m "commitmsg"'
|
||||
)
|
||||
|
||||
before = checksum_directory(f"{base_dir}/test")
|
||||
cmd = grm(["wt", "clean"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
assert "test" in os.listdir(base_dir)
|
||||
|
||||
after = checksum_directory(f"{base_dir}/test")
|
||||
assert before == after
|
||||
|
||||
|
||||
def test_worktree_clean_refusal_tracking_branch_mismatch():
|
||||
with TempGitRepositoryWorktree() as (base_dir, _commit):
|
||||
cmd = grm(["wt", "add", "test", "--track", "origin/test"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
shell(
|
||||
f"cd {base_dir}/test && git push origin test && git reset --hard origin/test^"
|
||||
)
|
||||
|
||||
before = checksum_directory(f"{base_dir}/test")
|
||||
cmd = grm(["wt", "clean"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
assert "test" in os.listdir(base_dir)
|
||||
|
||||
after = checksum_directory(f"{base_dir}/test")
|
||||
assert before == after
|
||||
|
||||
|
||||
def test_worktree_clean_fail_from_subdir():
|
||||
with TempGitRepositoryWorktree() as (base_dir, _commit):
|
||||
cmd = grm(["wt", "add", "test"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
cmd = grm(["wt", "clean"], cwd=f"{base_dir}/test")
|
||||
assert cmd.returncode != 0
|
||||
assert len(cmd.stdout) == 0
|
||||
assert len(cmd.stderr) != 0
|
||||
|
||||
|
||||
def test_worktree_clean_non_worktree():
|
||||
with TempGitRepository() as git_dir:
|
||||
cmd = grm(["wt", "clean"], cwd=git_dir)
|
||||
assert cmd.returncode != 0
|
||||
assert len(cmd.stdout) == 0
|
||||
assert len(cmd.stderr) != 0
|
||||
|
||||
|
||||
def test_worktree_clean_non_git():
|
||||
with NonGitDir() as base_dir:
|
||||
cmd = grm(["wt", "clean"], cwd=base_dir)
|
||||
assert cmd.returncode != 0
|
||||
assert len(cmd.stdout) == 0
|
||||
assert len(cmd.stderr) != 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize("configure_default_branch", [True, False])
|
||||
@pytest.mark.parametrize("branch_list_empty", [True, False])
|
||||
def test_worktree_clean_configured_default_branch(
|
||||
configure_default_branch, branch_list_empty
|
||||
):
|
||||
with TempGitRepositoryWorktree() as (base_dir, _commit):
|
||||
if configure_default_branch:
|
||||
with open(os.path.join(base_dir, "grm.toml"), "w") as f:
|
||||
if branch_list_empty:
|
||||
f.write(
|
||||
f"""
|
||||
persistent_branches = []
|
||||
"""
|
||||
)
|
||||
else:
|
||||
f.write(
|
||||
f"""
|
||||
persistent_branches = [
|
||||
"mybranch"
|
||||
]
|
||||
"""
|
||||
)
|
||||
|
||||
cmd = grm(["wt", "add", "test"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
shell(
|
||||
f"""
|
||||
cd {base_dir}
|
||||
(
|
||||
cd ./test
|
||||
touch change
|
||||
git add change
|
||||
git commit -m commit
|
||||
)
|
||||
|
||||
git --git-dir ./.git-main-working-tree worktree add mybranch
|
||||
(
|
||||
cd ./mybranch
|
||||
git merge --no-ff test
|
||||
)
|
||||
git --git-dir ./.git-main-working-tree worktree remove mybranch
|
||||
"""
|
||||
)
|
||||
|
||||
cmd = grm(["wt", "clean"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
if configure_default_branch and not branch_list_empty:
|
||||
assert "test" not in os.listdir(base_dir)
|
||||
else:
|
||||
assert "test" in os.listdir(base_dir)
|
||||
143
e2e_tests/test_worktree_config_presistent_branch.py
Normal file
143
e2e_tests/test_worktree_config_presistent_branch.py
Normal file
@@ -0,0 +1,143 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os.path
|
||||
|
||||
from helpers import *
|
||||
|
||||
|
||||
def test_worktree_never_clean_persistent_branches():
|
||||
with TempGitRepositoryWorktree() as (base_dir, _commit):
|
||||
with open(os.path.join(base_dir, "grm.toml"), "w") as f:
|
||||
f.write(
|
||||
"""
|
||||
persistent_branches = [
|
||||
"mybranch",
|
||||
]
|
||||
"""
|
||||
)
|
||||
|
||||
cmd = grm(["wt", "add", "mybranch", "--track", "origin/master"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
before = checksum_directory(f"{base_dir}/mybranch")
|
||||
|
||||
cmd = grm(["wt", "clean"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
assert "mybranch" in os.listdir(base_dir)
|
||||
repo = git.Repo(os.path.join(base_dir, "mybranch"))
|
||||
assert str(repo.active_branch) == "mybranch"
|
||||
|
||||
after = checksum_directory(f"{base_dir}/mybranch")
|
||||
assert before == after
|
||||
|
||||
|
||||
def test_worktree_clean_branch_merged_into_persistent():
|
||||
with TempGitRepositoryWorktree() as (base_dir, _commit):
|
||||
with open(os.path.join(base_dir, "grm.toml"), "w") as f:
|
||||
f.write(
|
||||
"""
|
||||
persistent_branches = [
|
||||
"master",
|
||||
]
|
||||
"""
|
||||
)
|
||||
|
||||
cmd = grm(["wt", "add", "test", "--track", "origin/test"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
shell(
|
||||
f"""
|
||||
cd {base_dir}/test
|
||||
touch change1
|
||||
git add change1
|
||||
git commit -m "commit1"
|
||||
"""
|
||||
)
|
||||
|
||||
cmd = grm(["wt", "add", "master"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
shell(
|
||||
f"""
|
||||
cd {base_dir}/master
|
||||
git merge --no-ff test
|
||||
"""
|
||||
)
|
||||
|
||||
cmd = grm(["wt", "clean"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
assert "test" not in os.listdir(base_dir)
|
||||
|
||||
|
||||
def test_worktree_no_clean_unmerged_branch():
|
||||
with TempGitRepositoryWorktree() as (base_dir, _commit):
|
||||
with open(os.path.join(base_dir, "grm.toml"), "w") as f:
|
||||
f.write(
|
||||
"""
|
||||
persistent_branches = [
|
||||
"master",
|
||||
]
|
||||
"""
|
||||
)
|
||||
|
||||
cmd = grm(["wt", "add", "test", "--track", "origin/test"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
shell(
|
||||
f"""
|
||||
cd {base_dir}/test
|
||||
touch change1
|
||||
git add change1
|
||||
git commit -m "commit1"
|
||||
git push origin test
|
||||
"""
|
||||
)
|
||||
|
||||
cmd = grm(["wt", "add", "master"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
cmd = grm(["wt", "clean"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
assert "test" in os.listdir(base_dir)
|
||||
|
||||
|
||||
def test_worktree_delete_branch_merged_into_persistent():
|
||||
with TempGitRepositoryWorktree() as (base_dir, _commit):
|
||||
with open(os.path.join(base_dir, "grm.toml"), "w") as f:
|
||||
f.write(
|
||||
"""
|
||||
persistent_branches = [
|
||||
"master",
|
||||
]
|
||||
"""
|
||||
)
|
||||
|
||||
cmd = grm(["wt", "add", "test", "--track", "origin/test"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
shell(
|
||||
f"""
|
||||
cd {base_dir}/test
|
||||
touch change1
|
||||
git add change1
|
||||
git commit -m "commit1"
|
||||
"""
|
||||
)
|
||||
|
||||
cmd = grm(["wt", "add", "master"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
shell(
|
||||
f"""
|
||||
cd {base_dir}/master
|
||||
git merge --no-ff test
|
||||
"""
|
||||
)
|
||||
|
||||
cmd = grm(["wt", "delete", "test"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
assert "test" not in os.listdir(base_dir)
|
||||
55
e2e_tests/test_worktree_conversion.py
Normal file
55
e2e_tests/test_worktree_conversion.py
Normal file
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import tempfile
|
||||
|
||||
from helpers import *
|
||||
|
||||
|
||||
def test_convert():
|
||||
with TempGitRepository() as git_dir:
|
||||
cmd = grm(["wt", "convert"], cwd=git_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
files = os.listdir(git_dir)
|
||||
assert len(files) == 1
|
||||
assert files[0] == ".git-main-working-tree"
|
||||
|
||||
cmd = grm(["wt", "add", "test"], cwd=git_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
files = os.listdir(git_dir)
|
||||
assert len(files) == 2
|
||||
assert set(files) == {".git-main-working-tree", "test"}
|
||||
|
||||
|
||||
def test_convert_already_worktree():
|
||||
with TempGitRepositoryWorktree() as (git_dir, _commit):
|
||||
before = checksum_directory(git_dir)
|
||||
|
||||
cmd = grm(["wt", "convert"], cwd=git_dir)
|
||||
assert cmd.returncode != 0
|
||||
|
||||
after = checksum_directory(git_dir)
|
||||
assert before == after
|
||||
|
||||
|
||||
def test_convert_non_git():
|
||||
with NonGitDir() as dir:
|
||||
before = checksum_directory(dir)
|
||||
|
||||
cmd = grm(["wt", "convert"], cwd=dir)
|
||||
assert cmd.returncode != 0
|
||||
|
||||
after = checksum_directory(dir)
|
||||
assert before == after
|
||||
|
||||
|
||||
def test_convert_empty():
|
||||
with EmptyDir() as dir:
|
||||
before = checksum_directory(dir)
|
||||
|
||||
cmd = grm(["wt", "convert"], cwd=dir)
|
||||
assert cmd.returncode != 0
|
||||
|
||||
after = checksum_directory(dir)
|
||||
assert before == after
|
||||
176
e2e_tests/test_worktree_fetch.py
Normal file
176
e2e_tests/test_worktree_fetch.py
Normal file
@@ -0,0 +1,176 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from helpers import *
|
||||
|
||||
import re
|
||||
|
||||
import pytest
|
||||
import git
|
||||
|
||||
|
||||
def test_worktree_fetch():
|
||||
with TempGitRepositoryWorktree() as (base_dir, root_commit):
|
||||
with TempGitFileRemote() as (remote_path, _remote_sha):
|
||||
shell(
|
||||
f"""
|
||||
cd {base_dir}
|
||||
git --git-dir .git-main-working-tree remote add upstream file://{remote_path}
|
||||
git --git-dir .git-main-working-tree push --force upstream master:master
|
||||
"""
|
||||
)
|
||||
|
||||
cmd = grm(["wt", "fetch"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
repo = git.Repo(f"{base_dir}/.git-main-working-tree")
|
||||
assert repo.commit("master").hexsha == repo.commit("origin/master").hexsha
|
||||
assert repo.commit("master").hexsha == repo.commit("upstream/master").hexsha
|
||||
|
||||
with EmptyDir() as tmp:
|
||||
shell(
|
||||
f"""
|
||||
cd {tmp}
|
||||
git clone {remote_path} tmp
|
||||
cd tmp
|
||||
echo change > mychange-remote
|
||||
git add mychange-remote
|
||||
git commit -m "change-remote"
|
||||
git push origin HEAD:master
|
||||
"""
|
||||
)
|
||||
remote_commit = git.Repo(f"{tmp}/tmp").commit("master").hexsha
|
||||
|
||||
assert repo.commit("master").hexsha == repo.commit("origin/master").hexsha
|
||||
assert repo.commit("master").hexsha == repo.commit("upstream/master").hexsha
|
||||
|
||||
cmd = grm(["wt", "fetch"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
assert repo.commit("master").hexsha == repo.commit("origin/master").hexsha
|
||||
assert repo.commit("master").hexsha == root_commit
|
||||
assert repo.commit("upstream/master").hexsha == remote_commit
|
||||
|
||||
|
||||
@pytest.mark.parametrize("rebase", [True, False])
|
||||
@pytest.mark.parametrize("ffable", [True, False])
|
||||
@pytest.mark.parametrize("has_changes", [True, False])
|
||||
@pytest.mark.parametrize("stash", [True, False])
|
||||
def test_worktree_pull(rebase, ffable, has_changes, stash):
|
||||
with TempGitRepositoryWorktree() as (base_dir, root_commit):
|
||||
with TempGitFileRemote() as (remote_path, _remote_sha):
|
||||
shell(
|
||||
f"""
|
||||
cd {base_dir}
|
||||
git --git-dir .git-main-working-tree remote add upstream file://{remote_path}
|
||||
git --git-dir .git-main-working-tree push --force upstream master:master
|
||||
"""
|
||||
)
|
||||
|
||||
repo = git.Repo(f"{base_dir}/.git-main-working-tree")
|
||||
assert repo.commit("origin/master").hexsha == repo.commit("master").hexsha
|
||||
assert repo.commit("upstream/master").hexsha == repo.commit("master").hexsha
|
||||
|
||||
with EmptyDir() as tmp:
|
||||
shell(
|
||||
f"""
|
||||
cd {tmp}
|
||||
git clone {remote_path} tmp
|
||||
cd tmp
|
||||
git checkout origin/master
|
||||
echo change > mychange-remote
|
||||
git add mychange-remote
|
||||
git commit -m "change-remote"
|
||||
git push origin HEAD:master
|
||||
"""
|
||||
)
|
||||
remote_commit = git.Repo(f"{tmp}/tmp").commit("HEAD").hexsha
|
||||
|
||||
grm(["wt", "add", "master", "--track", "upstream/master"], cwd=base_dir)
|
||||
|
||||
repo = git.Repo(f"{base_dir}/master")
|
||||
if not ffable:
|
||||
shell(
|
||||
f"""
|
||||
cd {base_dir}/master
|
||||
echo change > mychange
|
||||
git add mychange
|
||||
git commit -m "local-commit-in-master"
|
||||
"""
|
||||
)
|
||||
|
||||
if has_changes:
|
||||
shell(
|
||||
f"""
|
||||
cd {base_dir}/master
|
||||
echo change >> root-commit-in-worktree-1
|
||||
echo uncommitedchange > uncommitedchange
|
||||
"""
|
||||
)
|
||||
|
||||
args = ["wt", "pull"]
|
||||
if rebase:
|
||||
args += ["--rebase"]
|
||||
if stash:
|
||||
args += ["--stash"]
|
||||
cmd = grm(args, cwd=base_dir)
|
||||
if has_changes and not stash:
|
||||
assert cmd.returncode != 0
|
||||
assert re.match(r".*master.*contains changes.*", cmd.stderr)
|
||||
else:
|
||||
assert repo.commit("upstream/master").hexsha == remote_commit
|
||||
assert repo.commit("origin/master").hexsha == root_commit
|
||||
assert (
|
||||
repo.commit("master").hexsha
|
||||
!= repo.commit("origin/master").hexsha
|
||||
)
|
||||
if has_changes:
|
||||
assert ["uncommitedchange"] == repo.untracked_files
|
||||
assert repo.is_dirty()
|
||||
else:
|
||||
assert not repo.is_dirty()
|
||||
|
||||
if not rebase:
|
||||
if ffable:
|
||||
assert cmd.returncode == 0
|
||||
assert (
|
||||
repo.commit("master").hexsha
|
||||
!= repo.commit("origin/master").hexsha
|
||||
)
|
||||
assert (
|
||||
repo.commit("master").hexsha
|
||||
== repo.commit("upstream/master").hexsha
|
||||
)
|
||||
assert (
|
||||
repo.commit("upstream/master").hexsha == remote_commit
|
||||
)
|
||||
else:
|
||||
assert cmd.returncode != 0
|
||||
assert "cannot be fast forwarded" in cmd.stderr
|
||||
assert (
|
||||
repo.commit("master").hexsha
|
||||
!= repo.commit("origin/master").hexsha
|
||||
)
|
||||
assert repo.commit("master").hexsha != remote_commit
|
||||
assert (
|
||||
repo.commit("upstream/master").hexsha == remote_commit
|
||||
)
|
||||
else:
|
||||
assert cmd.returncode == 0
|
||||
if ffable:
|
||||
assert (
|
||||
repo.commit("master").hexsha
|
||||
!= repo.commit("origin/master").hexsha
|
||||
)
|
||||
assert (
|
||||
repo.commit("master").hexsha
|
||||
== repo.commit("upstream/master").hexsha
|
||||
)
|
||||
assert (
|
||||
repo.commit("upstream/master").hexsha == remote_commit
|
||||
)
|
||||
else:
|
||||
assert (
|
||||
repo.commit("master").message.strip()
|
||||
== "local-commit-in-master"
|
||||
)
|
||||
assert repo.commit("master~1").hexsha == remote_commit
|
||||
270
e2e_tests/test_worktree_rebase.py
Normal file
270
e2e_tests/test_worktree_rebase.py
Normal file
@@ -0,0 +1,270 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from helpers import *
|
||||
|
||||
import re
|
||||
|
||||
import pytest
|
||||
import git
|
||||
|
||||
|
||||
@pytest.mark.parametrize("pull", [True, False])
|
||||
@pytest.mark.parametrize("rebase", [True, False])
|
||||
@pytest.mark.parametrize("ffable", [True, False])
|
||||
@pytest.mark.parametrize("has_changes", [True, False])
|
||||
@pytest.mark.parametrize("stash", [True, False])
|
||||
def test_worktree_rebase(pull, rebase, ffable, has_changes, stash):
|
||||
with TempGitRepositoryWorktree() as (base_dir, _root_commit):
|
||||
with open(os.path.join(base_dir, "grm.toml"), "w") as f:
|
||||
f.write('persistent_branches = ["mybasebranch"]')
|
||||
|
||||
repo = git.Repo(f"{base_dir}/.git-main-working-tree")
|
||||
|
||||
grm(
|
||||
["wt", "add", "mybasebranch", "--track", "origin/mybasebranch"],
|
||||
cwd=base_dir,
|
||||
)
|
||||
|
||||
shell(
|
||||
f"""
|
||||
cd {base_dir}/mybasebranch
|
||||
echo change > mychange-root
|
||||
git add mychange-root
|
||||
git commit -m "commit-root"
|
||||
echo change > mychange-base-local
|
||||
git add mychange-base-local
|
||||
git commit -m "commit-in-base-local"
|
||||
git push origin mybasebranch
|
||||
"""
|
||||
)
|
||||
|
||||
grm(
|
||||
["wt", "add", "myfeatbranch", "--track", "origin/myfeatbranch"],
|
||||
cwd=base_dir,
|
||||
)
|
||||
shell(
|
||||
f"""
|
||||
cd {base_dir}/myfeatbranch
|
||||
git reset --hard mybasebranch^ # root
|
||||
echo change > mychange-feat-local
|
||||
git add mychange-feat-local
|
||||
git commit -m "commit-in-feat-local"
|
||||
git push origin HEAD:myfeatbranch
|
||||
"""
|
||||
)
|
||||
|
||||
grm(["wt", "add", "tmp"], cwd=base_dir)
|
||||
shell(
|
||||
f"""
|
||||
cd {base_dir}/tmp
|
||||
git reset --hard mybasebranch
|
||||
echo change > mychange-base-remote
|
||||
git add mychange-base-remote
|
||||
git commit -m "commit-in-base-remote"
|
||||
git push origin HEAD:mybasebranch
|
||||
|
||||
git reset --hard myfeatbranch
|
||||
echo change > mychange-feat-remote
|
||||
git add mychange-feat-remote
|
||||
git commit -m "commit-in-feat-remote"
|
||||
git push origin HEAD:myfeatbranch
|
||||
"""
|
||||
)
|
||||
|
||||
if not ffable:
|
||||
shell(
|
||||
f"""
|
||||
cd {base_dir}/mybasebranch
|
||||
echo change > mychange-base-no-ff
|
||||
git add mychange-base-no-ff
|
||||
git commit -m "commit-in-base-local-no-ff"
|
||||
|
||||
cd {base_dir}/myfeatbranch
|
||||
echo change > mychange-feat-no-ff
|
||||
git add mychange-feat-no-ff
|
||||
git commit -m "commit-in-feat-local-no-ff"
|
||||
"""
|
||||
)
|
||||
|
||||
if has_changes:
|
||||
shell(
|
||||
f"""
|
||||
cd {base_dir}/myfeatbranch
|
||||
echo uncommitedchange > uncommitedchange
|
||||
"""
|
||||
)
|
||||
|
||||
grm(["wt", "delete", "--force", "tmp"], cwd=base_dir)
|
||||
|
||||
repo = git.Repo(f"{base_dir}/.git-main-working-tree")
|
||||
if ffable:
|
||||
assert repo.commit("mybasebranch~1").message.strip() == "commit-root"
|
||||
assert (
|
||||
repo.refs.mybasebranch.commit.message.strip() == "commit-in-base-local"
|
||||
)
|
||||
assert (
|
||||
repo.remote("origin").refs.mybasebranch.commit.message.strip()
|
||||
== "commit-in-base-remote"
|
||||
)
|
||||
assert (
|
||||
repo.refs.myfeatbranch.commit.message.strip() == "commit-in-feat-local"
|
||||
)
|
||||
assert (
|
||||
repo.remote("origin").refs.myfeatbranch.commit.message.strip()
|
||||
== "commit-in-feat-remote"
|
||||
)
|
||||
else:
|
||||
assert (
|
||||
repo.commit("mybasebranch").message.strip()
|
||||
== "commit-in-base-local-no-ff"
|
||||
)
|
||||
assert (
|
||||
repo.commit("mybasebranch~1").message.strip() == "commit-in-base-local"
|
||||
)
|
||||
assert repo.commit("mybasebranch~2").message.strip() == "commit-root"
|
||||
assert (
|
||||
repo.commit("myfeatbranch").message.strip()
|
||||
== "commit-in-feat-local-no-ff"
|
||||
)
|
||||
assert (
|
||||
repo.commit("myfeatbranch~1").message.strip() == "commit-in-feat-local"
|
||||
)
|
||||
assert repo.commit("myfeatbranch~2").message.strip() == "commit-root"
|
||||
assert (
|
||||
repo.remote("origin").refs.mybasebranch.commit.message.strip()
|
||||
== "commit-in-base-remote"
|
||||
)
|
||||
assert (
|
||||
repo.remote("origin").refs.myfeatbranch.commit.message.strip()
|
||||
== "commit-in-feat-remote"
|
||||
)
|
||||
|
||||
args = ["wt", "rebase"]
|
||||
if pull:
|
||||
args += ["--pull"]
|
||||
if rebase:
|
||||
args += ["--rebase"]
|
||||
if stash:
|
||||
args += ["--stash"]
|
||||
cmd = grm(args, cwd=base_dir)
|
||||
|
||||
if rebase and not pull:
|
||||
assert cmd.returncode != 0
|
||||
assert len(cmd.stderr) != 0
|
||||
elif has_changes and not stash:
|
||||
assert cmd.returncode != 0
|
||||
assert re.match(r".*myfeatbranch.*contains changes.*", cmd.stderr)
|
||||
else:
|
||||
repo = git.Repo(f"{base_dir}/myfeatbranch")
|
||||
if has_changes:
|
||||
assert ["uncommitedchange"] == repo.untracked_files
|
||||
if pull:
|
||||
if rebase:
|
||||
assert cmd.returncode == 0
|
||||
if ffable:
|
||||
assert (
|
||||
repo.commit("HEAD").message.strip()
|
||||
== "commit-in-feat-remote"
|
||||
)
|
||||
assert (
|
||||
repo.commit("HEAD~1").message.strip()
|
||||
== "commit-in-feat-local"
|
||||
)
|
||||
assert (
|
||||
repo.commit("HEAD~2").message.strip()
|
||||
== "commit-in-base-remote"
|
||||
)
|
||||
assert (
|
||||
repo.commit("HEAD~3").message.strip()
|
||||
== "commit-in-base-local"
|
||||
)
|
||||
assert repo.commit("HEAD~4").message.strip() == "commit-root"
|
||||
else:
|
||||
assert (
|
||||
repo.commit("HEAD").message.strip()
|
||||
== "commit-in-feat-local-no-ff"
|
||||
)
|
||||
assert (
|
||||
repo.commit("HEAD~1").message.strip()
|
||||
== "commit-in-feat-remote"
|
||||
)
|
||||
assert (
|
||||
repo.commit("HEAD~2").message.strip()
|
||||
== "commit-in-feat-local"
|
||||
)
|
||||
assert (
|
||||
repo.commit("HEAD~3").message.strip()
|
||||
== "commit-in-base-local-no-ff"
|
||||
)
|
||||
assert (
|
||||
repo.commit("HEAD~4").message.strip()
|
||||
== "commit-in-base-remote"
|
||||
)
|
||||
assert (
|
||||
repo.commit("HEAD~5").message.strip()
|
||||
== "commit-in-base-local"
|
||||
)
|
||||
assert repo.commit("HEAD~6").message.strip() == "commit-root"
|
||||
else:
|
||||
if ffable:
|
||||
assert cmd.returncode == 0
|
||||
assert (
|
||||
repo.commit("HEAD").message.strip()
|
||||
== "commit-in-feat-remote"
|
||||
)
|
||||
assert (
|
||||
repo.commit("HEAD~1").message.strip()
|
||||
== "commit-in-feat-local"
|
||||
)
|
||||
assert (
|
||||
repo.commit("HEAD~2").message.strip()
|
||||
== "commit-in-base-remote"
|
||||
)
|
||||
assert (
|
||||
repo.commit("HEAD~3").message.strip()
|
||||
== "commit-in-base-local"
|
||||
)
|
||||
assert repo.commit("HEAD~4").message.strip() == "commit-root"
|
||||
else:
|
||||
assert cmd.returncode != 0
|
||||
assert (
|
||||
repo.commit("HEAD").message.strip()
|
||||
== "commit-in-feat-local-no-ff"
|
||||
)
|
||||
assert (
|
||||
repo.commit("HEAD~1").message.strip()
|
||||
== "commit-in-feat-local"
|
||||
)
|
||||
assert (
|
||||
repo.commit("HEAD~2").message.strip()
|
||||
== "commit-in-base-local-no-ff"
|
||||
)
|
||||
assert (
|
||||
repo.commit("HEAD~3").message.strip()
|
||||
== "commit-in-base-local"
|
||||
)
|
||||
assert repo.commit("HEAD~4").message.strip() == "commit-root"
|
||||
else:
|
||||
assert cmd.returncode == 0
|
||||
if ffable:
|
||||
assert repo.commit("HEAD").message.strip() == "commit-in-feat-local"
|
||||
assert (
|
||||
repo.commit("HEAD~1").message.strip() == "commit-in-base-local"
|
||||
)
|
||||
assert repo.commit("HEAD~2").message.strip() == "commit-root"
|
||||
else:
|
||||
assert (
|
||||
repo.commit("HEAD").message.strip()
|
||||
== "commit-in-feat-local-no-ff"
|
||||
)
|
||||
assert (
|
||||
repo.commit("HEAD~1").message.strip() == "commit-in-feat-local"
|
||||
)
|
||||
assert (
|
||||
repo.commit("HEAD~2").message.strip()
|
||||
== "commit-in-base-local-no-ff"
|
||||
)
|
||||
assert (
|
||||
repo.commit("HEAD~3").message.strip() == "commit-in-base-local"
|
||||
)
|
||||
assert repo.commit("HEAD~4").message.strip() == "commit-root"
|
||||
42
e2e_tests/test_worktree_status.py
Normal file
42
e2e_tests/test_worktree_status.py
Normal file
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from helpers import *
|
||||
|
||||
|
||||
def test_worktree_status():
|
||||
with TempGitRepositoryWorktree() as (base_dir, _commit):
|
||||
cmd = grm(["wt", "add", "test"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
cmd = grm(["wt", "status"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
assert len(cmd.stderr) == 0
|
||||
stdout = cmd.stdout.lower()
|
||||
assert "test" in stdout
|
||||
|
||||
|
||||
def test_worktree_status_fail_from_subdir():
|
||||
with TempGitRepositoryWorktree() as (base_dir, _commit):
|
||||
cmd = grm(["wt", "add", "test"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
cmd = grm(["wt", "status"], cwd=f"{base_dir}/test")
|
||||
assert cmd.returncode != 0
|
||||
assert len(cmd.stdout) == 0
|
||||
assert len(cmd.stderr) != 0
|
||||
|
||||
|
||||
def test_worktree_status_non_worktree():
|
||||
with TempGitRepository() as git_dir:
|
||||
cmd = grm(["wt", "status"], cwd=git_dir)
|
||||
assert cmd.returncode != 0
|
||||
assert len(cmd.stdout) == 0
|
||||
assert len(cmd.stderr) != 0
|
||||
|
||||
|
||||
def test_worktree_status_non_git():
|
||||
with NonGitDir() as base_dir:
|
||||
cmd = grm(["wt", "status"], cwd=base_dir)
|
||||
assert cmd.returncode != 0
|
||||
assert len(cmd.stdout) == 0
|
||||
assert len(cmd.stderr) != 0
|
||||
427
e2e_tests/test_worktrees.py
Normal file
427
e2e_tests/test_worktrees.py
Normal file
@@ -0,0 +1,427 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from helpers import *
|
||||
|
||||
import git
|
||||
import pytest
|
||||
|
||||
import os.path
|
||||
|
||||
|
||||
@pytest.mark.parametrize("remote_branch_already_exists", [True, False])
|
||||
@pytest.mark.parametrize("has_config", [True, False])
|
||||
@pytest.mark.parametrize("has_default", [True, False])
|
||||
@pytest.mark.parametrize("has_prefix", [True, False])
|
||||
def test_worktree_add_simple(
|
||||
remote_branch_already_exists, has_config, has_default, has_prefix
|
||||
):
|
||||
with TempGitRepositoryWorktree() as (base_dir, _commit):
|
||||
if has_config:
|
||||
with open(os.path.join(base_dir, "grm.toml"), "w") as f:
|
||||
f.write(
|
||||
f"""
|
||||
[track]
|
||||
default = {str(has_default).lower()}
|
||||
default_remote = "origin"
|
||||
"""
|
||||
)
|
||||
if has_prefix:
|
||||
f.write(
|
||||
"""
|
||||
default_remote_prefix = "myprefix"
|
||||
"""
|
||||
)
|
||||
|
||||
if remote_branch_already_exists:
|
||||
shell(
|
||||
f"""
|
||||
cd {base_dir}
|
||||
git --git-dir ./.git-main-working-tree worktree add tmp
|
||||
(
|
||||
cd tmp
|
||||
touch change
|
||||
git add change
|
||||
git commit -m commit
|
||||
git push origin HEAD:test
|
||||
#git reset --hard 'HEAD@{1}'
|
||||
git branch -va
|
||||
)
|
||||
git --git-dir ./.git-main-working-tree worktree remove tmp
|
||||
"""
|
||||
)
|
||||
cmd = grm(["wt", "add", "test"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
files = os.listdir(base_dir)
|
||||
if has_config is True:
|
||||
assert len(files) == 3
|
||||
assert set(files) == {".git-main-working-tree", "grm.toml", "test"}
|
||||
else:
|
||||
assert len(files) == 2
|
||||
assert set(files) == {".git-main-working-tree", "test"}
|
||||
|
||||
repo = git.Repo(os.path.join(base_dir, "test"))
|
||||
assert not repo.bare
|
||||
assert not repo.is_dirty()
|
||||
if has_config and has_default:
|
||||
if has_prefix and not remote_branch_already_exists:
|
||||
assert (
|
||||
str(repo.active_branch.tracking_branch()) == "origin/myprefix/test"
|
||||
)
|
||||
else:
|
||||
assert str(repo.active_branch.tracking_branch()) == "origin/test"
|
||||
else:
|
||||
assert repo.active_branch.tracking_branch() is None
|
||||
|
||||
|
||||
def test_worktree_add_into_subdirectory():
|
||||
with TempGitRepositoryWorktree() as (base_dir, _commit):
|
||||
cmd = grm(["wt", "add", "dir/test"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
files = os.listdir(base_dir)
|
||||
assert len(files) == 2
|
||||
assert set(files) == {".git-main-working-tree", "dir"}
|
||||
|
||||
files = os.listdir(os.path.join(base_dir, "dir"))
|
||||
assert set(files) == {"test"}
|
||||
|
||||
repo = git.Repo(os.path.join(base_dir, "dir", "test"))
|
||||
assert not repo.bare
|
||||
assert not repo.is_dirty()
|
||||
assert repo.active_branch.tracking_branch() is None
|
||||
|
||||
|
||||
def test_worktree_add_into_invalid_subdirectory():
|
||||
with TempGitRepositoryWorktree() as (base_dir, _commit):
|
||||
cmd = grm(["wt", "add", "/dir/test"], cwd=base_dir)
|
||||
assert cmd.returncode == 1
|
||||
assert "dir" not in os.listdir(base_dir)
|
||||
assert "dir" not in os.listdir("/")
|
||||
|
||||
cmd = grm(["wt", "add", "dir/"], cwd=base_dir)
|
||||
assert cmd.returncode == 1
|
||||
assert "dir" not in os.listdir(base_dir)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("remote_branch_already_exists", [True, False])
|
||||
@pytest.mark.parametrize("has_config", [True, False])
|
||||
@pytest.mark.parametrize("has_default", [True, False])
|
||||
@pytest.mark.parametrize("has_prefix", [True, False])
|
||||
def test_worktree_add_with_tracking(
|
||||
remote_branch_already_exists, has_config, has_default, has_prefix
|
||||
):
|
||||
with TempGitRepositoryWorktree() as (base_dir, _commit):
|
||||
if has_config:
|
||||
with open(os.path.join(base_dir, "grm.toml"), "w") as f:
|
||||
f.write(
|
||||
f"""
|
||||
[track]
|
||||
default = {str(has_default).lower()}
|
||||
default_remote = "origin"
|
||||
"""
|
||||
)
|
||||
if has_prefix:
|
||||
f.write(
|
||||
"""
|
||||
default_remote_prefix = "myprefix"
|
||||
"""
|
||||
)
|
||||
|
||||
if remote_branch_already_exists:
|
||||
shell(
|
||||
f"""
|
||||
cd {base_dir}
|
||||
git --git-dir ./.git-main-working-tree worktree add tmp
|
||||
(
|
||||
cd tmp
|
||||
touch change
|
||||
git add change
|
||||
git commit -m commit
|
||||
git push origin HEAD:test
|
||||
#git reset --hard 'HEAD@{1}'
|
||||
git branch -va
|
||||
)
|
||||
git --git-dir ./.git-main-working-tree worktree remove tmp
|
||||
"""
|
||||
)
|
||||
cmd = grm(["wt", "add", "test", "--track", "origin/test"], cwd=base_dir)
|
||||
print(cmd.stderr)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
files = os.listdir(base_dir)
|
||||
if has_config is True:
|
||||
assert len(files) == 3
|
||||
assert set(files) == {".git-main-working-tree", "grm.toml", "test"}
|
||||
else:
|
||||
assert len(files) == 2
|
||||
assert set(files) == {".git-main-working-tree", "test"}
|
||||
|
||||
repo = git.Repo(os.path.join(base_dir, "test"))
|
||||
assert not repo.bare
|
||||
assert not repo.is_dirty()
|
||||
assert str(repo.active_branch) == "test"
|
||||
assert str(repo.active_branch.tracking_branch()) == "origin/test"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("has_config", [True, False])
|
||||
@pytest.mark.parametrize("has_default", [True, False])
|
||||
@pytest.mark.parametrize("has_prefix", [True, False])
|
||||
@pytest.mark.parametrize("track", [True, False])
|
||||
def test_worktree_add_with_explicit_no_tracking(
|
||||
has_config, has_default, has_prefix, track
|
||||
):
|
||||
with TempGitRepositoryWorktree() as (base_dir, _commit):
|
||||
if has_config:
|
||||
with open(os.path.join(base_dir, "grm.toml"), "w") as f:
|
||||
f.write(
|
||||
f"""
|
||||
[track]
|
||||
default = {str(has_default).lower()}
|
||||
default_remote = "origin"
|
||||
"""
|
||||
)
|
||||
if has_prefix:
|
||||
f.write(
|
||||
"""
|
||||
default_remote_prefix = "myprefix"
|
||||
"""
|
||||
)
|
||||
if track is True:
|
||||
cmd = grm(
|
||||
["wt", "add", "test", "--track", "origin/test", "--no-track"],
|
||||
cwd=base_dir,
|
||||
)
|
||||
else:
|
||||
cmd = grm(["wt", "add", "test", "--no-track"], cwd=base_dir)
|
||||
print(cmd.stderr)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
files = os.listdir(base_dir)
|
||||
if has_config is True:
|
||||
assert len(files) == 3
|
||||
assert set(files) == {".git-main-working-tree", "grm.toml", "test"}
|
||||
else:
|
||||
assert len(files) == 2
|
||||
assert set(files) == {".git-main-working-tree", "test"}
|
||||
|
||||
repo = git.Repo(os.path.join(base_dir, "test"))
|
||||
assert not repo.bare
|
||||
assert not repo.is_dirty()
|
||||
assert str(repo.active_branch) == "test"
|
||||
assert repo.active_branch.tracking_branch() is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize("remote_branch_already_exists", [True, False])
|
||||
@pytest.mark.parametrize("has_default", [True, False])
|
||||
@pytest.mark.parametrize("has_prefix", [True, False])
|
||||
def test_worktree_add_with_config(
|
||||
remote_branch_already_exists, has_default, has_prefix
|
||||
):
|
||||
with TempGitRepositoryWorktree() as (base_dir, _commit):
|
||||
with open(os.path.join(base_dir, "grm.toml"), "w") as f:
|
||||
f.write(
|
||||
f"""
|
||||
[track]
|
||||
default = {str(has_default).lower()}
|
||||
default_remote = "origin"
|
||||
"""
|
||||
)
|
||||
if has_prefix:
|
||||
f.write(
|
||||
"""
|
||||
default_remote_prefix = "myprefix"
|
||||
"""
|
||||
)
|
||||
if remote_branch_already_exists:
|
||||
shell(
|
||||
f"""
|
||||
cd {base_dir}
|
||||
git --git-dir ./.git-main-working-tree worktree add tmp
|
||||
(
|
||||
cd tmp
|
||||
touch change
|
||||
git add change
|
||||
git commit -m commit
|
||||
git push origin HEAD:test
|
||||
#git reset --hard 'HEAD@{1}'
|
||||
git branch -va
|
||||
)
|
||||
git --git-dir ./.git-main-working-tree worktree remove tmp
|
||||
"""
|
||||
)
|
||||
cmd = grm(["wt", "add", "test"], cwd=base_dir)
|
||||
print(cmd.stderr)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
files = os.listdir(base_dir)
|
||||
assert len(files) == 3
|
||||
assert set(files) == {".git-main-working-tree", "grm.toml", "test"}
|
||||
|
||||
repo = git.Repo(os.path.join(base_dir, "test"))
|
||||
assert not repo.bare
|
||||
assert not repo.is_dirty()
|
||||
assert str(repo.active_branch) == "test"
|
||||
if has_default:
|
||||
if has_prefix and not remote_branch_already_exists:
|
||||
assert (
|
||||
str(repo.active_branch.tracking_branch()) == "origin/myprefix/test"
|
||||
)
|
||||
else:
|
||||
assert str(repo.active_branch.tracking_branch()) == "origin/test"
|
||||
else:
|
||||
assert repo.active_branch.tracking_branch() is None
|
||||
|
||||
|
||||
def test_worktree_delete():
|
||||
with TempGitRepositoryWorktree() as (base_dir, _commit):
|
||||
cmd = grm(["wt", "add", "test", "--track", "origin/test"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
assert "test" in os.listdir(base_dir)
|
||||
|
||||
cmd = grm(["wt", "delete", "test"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
assert "test" not in os.listdir(base_dir)
|
||||
|
||||
cmd = grm(["wt", "add", "check"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
repo = git.Repo(os.path.join(base_dir, ".git-main-working-tree"))
|
||||
print(repo.branches)
|
||||
assert "test" not in [str(b) for b in repo.branches]
|
||||
|
||||
|
||||
def test_worktree_delete_refusal_no_tracking_branch():
|
||||
with TempGitRepositoryWorktree() as (base_dir, _commit):
|
||||
cmd = grm(["wt", "add", "test"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
before = checksum_directory(f"{base_dir}/test")
|
||||
cmd = grm(["wt", "delete", "test"], cwd=base_dir)
|
||||
assert cmd.returncode != 0
|
||||
stderr = cmd.stderr.lower()
|
||||
assert "refuse" in stderr or "refusing" in stderr
|
||||
assert "test" in os.listdir(base_dir)
|
||||
|
||||
after = checksum_directory(f"{base_dir}/test")
|
||||
assert before == after
|
||||
|
||||
|
||||
def test_worktree_delete_refusal_uncommited_changes_new_file():
|
||||
with TempGitRepositoryWorktree() as (base_dir, _commit):
|
||||
cmd = grm(["wt", "add", "test", "--track", "origin/test"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
shell(f"cd {base_dir}/test && touch changed_file")
|
||||
|
||||
before = checksum_directory(f"{base_dir}/test")
|
||||
cmd = grm(["wt", "delete", "test"], cwd=base_dir)
|
||||
assert cmd.returncode != 0
|
||||
stderr = cmd.stderr.lower()
|
||||
assert "refuse" in stderr or "refusing" in stderr
|
||||
assert "test" in os.listdir(base_dir)
|
||||
|
||||
after = checksum_directory(f"{base_dir}/test")
|
||||
assert before == after
|
||||
|
||||
|
||||
def test_worktree_delete_refusal_uncommited_changes_changed_file():
|
||||
with TempGitRepositoryWorktree() as (base_dir, _commit):
|
||||
cmd = grm(["wt", "add", "test", "--track", "origin/test"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
shell(f"cd {base_dir}/test && git ls-files | shuf | head | xargs rm -rf")
|
||||
|
||||
before = checksum_directory(f"{base_dir}/test")
|
||||
cmd = grm(["wt", "delete", "test"], cwd=base_dir)
|
||||
assert cmd.returncode != 0
|
||||
stderr = cmd.stderr.lower()
|
||||
assert "refuse" in stderr or "refusing" in stderr
|
||||
assert "test" in os.listdir(base_dir)
|
||||
|
||||
after = checksum_directory(f"{base_dir}/test")
|
||||
assert before == after
|
||||
|
||||
|
||||
def test_worktree_delete_refusal_uncommited_changes_deleted_file():
|
||||
with TempGitRepositoryWorktree() as (base_dir, _commit):
|
||||
cmd = grm(["wt", "add", "test", "--track", "origin/test"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
shell(
|
||||
f"cd {base_dir}/test && git ls-files | shuf | head | while read f ; do echo $RANDOM > $f ; done"
|
||||
)
|
||||
|
||||
before = checksum_directory(f"{base_dir}/test")
|
||||
cmd = grm(["wt", "delete", "test"], cwd=base_dir)
|
||||
assert cmd.returncode != 0
|
||||
stderr = cmd.stderr.lower()
|
||||
assert "refuse" in stderr or "refusing" in stderr
|
||||
assert "test" in os.listdir(base_dir)
|
||||
|
||||
after = checksum_directory(f"{base_dir}/test")
|
||||
assert before == after
|
||||
|
||||
|
||||
def test_worktree_delete_refusal_commited_changes():
|
||||
with TempGitRepositoryWorktree() as (base_dir, _commit):
|
||||
cmd = grm(["wt", "add", "test", "--track", "origin/test"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
shell(
|
||||
f'cd {base_dir}/test && touch changed_file && git add changed_file && git commit -m "commitmsg"'
|
||||
)
|
||||
|
||||
before = checksum_directory(f"{base_dir}/test")
|
||||
cmd = grm(["wt", "delete", "test"], cwd=base_dir)
|
||||
assert cmd.returncode != 0
|
||||
stderr = cmd.stderr.lower()
|
||||
assert "refuse" in stderr or "refusing" in stderr
|
||||
assert "test" in os.listdir(base_dir)
|
||||
|
||||
after = checksum_directory(f"{base_dir}/test")
|
||||
assert before == after
|
||||
|
||||
|
||||
def test_worktree_delete_refusal_tracking_branch_mismatch():
|
||||
with TempGitRepositoryWorktree() as (base_dir, _commit):
|
||||
cmd = grm(["wt", "add", "test", "--track", "origin/test"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
shell(
|
||||
f"cd {base_dir}/test && git push origin test && git reset --hard origin/test^"
|
||||
)
|
||||
|
||||
before = checksum_directory(f"{base_dir}/test")
|
||||
cmd = grm(["wt", "delete", "test"], cwd=base_dir)
|
||||
assert cmd.returncode != 0
|
||||
stderr = cmd.stderr.lower()
|
||||
assert "refuse" in stderr or "refusing" in stderr
|
||||
assert "test" in os.listdir(base_dir)
|
||||
|
||||
after = checksum_directory(f"{base_dir}/test")
|
||||
assert before == after
|
||||
|
||||
|
||||
def test_worktree_delete_force_refusal():
|
||||
with TempGitRepositoryWorktree() as (base_dir, _commit):
|
||||
cmd = grm(["wt", "add", "test"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
cmd = grm(["wt", "delete", "test", "--force"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
assert "test" not in os.listdir(base_dir)
|
||||
|
||||
|
||||
def test_worktree_add_delete_add():
|
||||
with TempGitRepositoryWorktree() as (base_dir, _commit):
|
||||
cmd = grm(["wt", "add", "test", "--track", "origin/test"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
assert "test" in os.listdir(base_dir)
|
||||
|
||||
cmd = grm(["wt", "delete", "test"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
assert "test" not in os.listdir(base_dir)
|
||||
|
||||
cmd = grm(["wt", "add", "test", "--track", "origin/test"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
assert "test" in os.listdir(base_dir)
|
||||
20
e2e_tests/update_requirementstxt.sh
Executable file
20
e2e_tests/update_requirementstxt.sh
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -o nounset
|
||||
set -o errexit
|
||||
|
||||
# shellcheck disable=SC1091
|
||||
source ./venv/bin/activate
|
||||
|
||||
pip --disable-pip-version-check install -r ./requirements.txt
|
||||
|
||||
pip3 list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | while read -r package ; do
|
||||
[[ "$package" == "pip" ]] && continue
|
||||
[[ "$package" == "setuptools" ]] && continue
|
||||
pip install --upgrade "${package}"
|
||||
version="$(pip show "${package}" | grep '^Version' | cut -d ' ' -f 2)"
|
||||
message="e2e_tests/pip: Update ${package} to ${version}"
|
||||
pip freeze | grep -v '^pkg_resources' > requirements.txt
|
||||
git add ./requirements.txt
|
||||
git commit --message "${message}"
|
||||
done
|
||||
16
example.config.yaml
Normal file
16
example.config.yaml
Normal file
@@ -0,0 +1,16 @@
|
||||
trees:
|
||||
- root: "~/example-projects/"
|
||||
repos:
|
||||
- name: "git-repo-manager"
|
||||
remotes:
|
||||
- name: "origin"
|
||||
url: "https://code.hkoerber.de/hannes/git-repo-manager.git"
|
||||
type: "https"
|
||||
- name: "github"
|
||||
url: "https://github.com/hakoerber/git-repo-manager.git"
|
||||
type: "https"
|
||||
- name: "dotfiles"
|
||||
remotes:
|
||||
- name: "origin"
|
||||
url: "https://github.com/hakoerber/dotfiles.git"
|
||||
type: "https"
|
||||
@@ -1,18 +1,52 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::repo::Repo;
|
||||
use super::repo::RepoConfig;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct Config {
|
||||
pub trees: Vec<Tree>,
|
||||
pub trees: Trees,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Trees(Vec<Tree>);
|
||||
|
||||
impl Trees {
|
||||
pub fn to_config(self) -> Config {
|
||||
Config { trees: self }
|
||||
}
|
||||
|
||||
pub fn from_vec(vec: Vec<Tree>) -> Self {
|
||||
Trees(vec)
|
||||
}
|
||||
|
||||
pub fn as_vec(self) -> Vec<Tree> {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn as_vec_ref(&self) -> &Vec<Tree> {
|
||||
self.0.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn as_toml(&self) -> Result<String, String> {
|
||||
match toml::to_string(self) {
|
||||
Ok(toml) => Ok(toml),
|
||||
Err(error) => Err(error.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_yaml(&self) -> Result<String, String> {
|
||||
serde_yaml::to_string(self).map_err(|e| e.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct Tree {
|
||||
pub root: String,
|
||||
pub repos: Option<Vec<Repo>>,
|
||||
pub repos: Option<Vec<RepoConfig>>,
|
||||
}
|
||||
|
||||
pub fn read_config(path: &str) -> Result<Config, String> {
|
||||
@@ -21,12 +55,18 @@ pub fn read_config(path: &str) -> Result<Config, String> {
|
||||
Err(e) => {
|
||||
return Err(format!(
|
||||
"Error reading configuration file \"{}\": {}",
|
||||
path, e
|
||||
))
|
||||
path,
|
||||
match e.kind() {
|
||||
std::io::ErrorKind::NotFound => String::from("not found"),
|
||||
_ => e.to_string(),
|
||||
}
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
let config: Config = match toml::from_str(&content) {
|
||||
Ok(c) => c,
|
||||
Err(_) => match serde_yaml::from_str(&content) {
|
||||
Ok(c) => c,
|
||||
Err(e) => {
|
||||
return Err(format!(
|
||||
@@ -34,6 +74,7 @@ pub fn read_config(path: &str) -> Result<Config, String> {
|
||||
path, e
|
||||
))
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Ok(config)
|
||||
|
||||
@@ -7,10 +7,8 @@ use clap::{AppSettings, Parser};
|
||||
author = clap::crate_authors!("\n"),
|
||||
about = clap::crate_description!(),
|
||||
long_version = clap::crate_version!(),
|
||||
license = clap::crate_license!(),
|
||||
setting = AppSettings::DeriveDisplayOrder,
|
||||
setting = AppSettings::PropagateVersion,
|
||||
setting = AppSettings::HelpRequired,
|
||||
)]
|
||||
pub struct Opts {
|
||||
#[clap(subcommand)]
|
||||
@@ -51,7 +49,7 @@ pub struct Sync {
|
||||
short,
|
||||
long,
|
||||
default_value = "./config.toml",
|
||||
about = "Path to the configuration file"
|
||||
help = "Path to the configuration file"
|
||||
)]
|
||||
pub config: String,
|
||||
}
|
||||
@@ -59,14 +57,29 @@ pub struct Sync {
|
||||
#[derive(Parser)]
|
||||
#[clap()]
|
||||
pub struct OptionalConfig {
|
||||
#[clap(short, long, about = "Path to the configuration file")]
|
||||
#[clap(short, long, help = "Path to the configuration file")]
|
||||
pub config: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(clap::ArgEnum, Clone)]
|
||||
pub enum ConfigFormat {
|
||||
Yaml,
|
||||
Toml,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
pub struct Find {
|
||||
#[clap(about = "The path to search through")]
|
||||
#[clap(help = "The path to search through")]
|
||||
pub path: String,
|
||||
|
||||
#[clap(
|
||||
arg_enum,
|
||||
short,
|
||||
long,
|
||||
help = "Format to produce",
|
||||
default_value_t = ConfigFormat::Toml,
|
||||
)]
|
||||
pub format: ConfigFormat,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
@@ -87,30 +100,33 @@ pub enum WorktreeAction {
|
||||
Convert(WorktreeConvertArgs),
|
||||
#[clap(about = "Clean all worktrees that do not contain uncommited/unpushed changes")]
|
||||
Clean(WorktreeCleanArgs),
|
||||
#[clap(about = "Fetch refs from remotes")]
|
||||
Fetch(WorktreeFetchArgs),
|
||||
#[clap(about = "Fetch refs from remotes and update local branches")]
|
||||
Pull(WorktreePullArgs),
|
||||
#[clap(about = "Rebase worktree onto default branch")]
|
||||
Rebase(WorktreeRebaseArgs),
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
pub struct WorktreeAddArgs {
|
||||
#[clap(about = "Name of the worktree")]
|
||||
#[clap(help = "Name of the worktree")]
|
||||
pub name: String,
|
||||
|
||||
#[clap(
|
||||
short = 'n',
|
||||
long = "branch-namespace",
|
||||
about = "Namespace of the branch"
|
||||
)]
|
||||
pub branch_namespace: Option<String>,
|
||||
#[clap(short = 't', long = "track", about = "Remote branch to track")]
|
||||
#[clap(short = 't', long = "track", help = "Remote branch to track")]
|
||||
pub track: Option<String>,
|
||||
|
||||
#[clap(long = "--no-track", help = "Disable tracking")]
|
||||
pub no_track: bool,
|
||||
}
|
||||
#[derive(Parser)]
|
||||
pub struct WorktreeDeleteArgs {
|
||||
#[clap(about = "Name of the worktree")]
|
||||
#[clap(help = "Name of the worktree")]
|
||||
pub name: String,
|
||||
|
||||
#[clap(
|
||||
long = "force",
|
||||
about = "Force deletion, even when there are uncommitted/unpushed changes"
|
||||
help = "Force deletion, even when there are uncommitted/unpushed changes"
|
||||
)]
|
||||
pub force: bool,
|
||||
}
|
||||
@@ -124,6 +140,30 @@ pub struct WorktreeConvertArgs {}
|
||||
#[derive(Parser)]
|
||||
pub struct WorktreeCleanArgs {}
|
||||
|
||||
#[derive(Parser)]
|
||||
pub struct WorktreeFetchArgs {}
|
||||
|
||||
#[derive(Parser)]
|
||||
pub struct WorktreePullArgs {
|
||||
#[clap(long = "--rebase", help = "Perform a rebase instead of a fast-forward")]
|
||||
pub rebase: bool,
|
||||
#[clap(long = "--stash", help = "Stash & unstash changes before & after pull")]
|
||||
pub stash: bool,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
pub struct WorktreeRebaseArgs {
|
||||
#[clap(long = "--pull", help = "Perform a pull before rebasing")]
|
||||
pub pull: bool,
|
||||
#[clap(long = "--rebase", help = "Perform a rebase when doing a pull")]
|
||||
pub rebase: bool,
|
||||
#[clap(
|
||||
long = "--stash",
|
||||
help = "Stash & unstash changes before & after rebase"
|
||||
)]
|
||||
pub stash: bool,
|
||||
}
|
||||
|
||||
pub fn parse() -> Opts {
|
||||
Opts::parse()
|
||||
}
|
||||
470
src/grm/main.rs
Normal file
470
src/grm/main.rs
Normal file
@@ -0,0 +1,470 @@
|
||||
use std::path::Path;
|
||||
use std::process;
|
||||
|
||||
mod cmd;
|
||||
|
||||
use grm::config;
|
||||
use grm::output::*;
|
||||
use grm::repo;
|
||||
|
||||
fn main() {
|
||||
let opts = cmd::parse();
|
||||
|
||||
match opts.subcmd {
|
||||
cmd::SubCommand::Repos(repos) => match repos.action {
|
||||
cmd::ReposAction::Sync(sync) => {
|
||||
let config = match config::read_config(&sync.config) {
|
||||
Ok(config) => config,
|
||||
Err(error) => {
|
||||
print_error(&error);
|
||||
process::exit(1);
|
||||
}
|
||||
};
|
||||
match grm::sync_trees(config) {
|
||||
Ok(success) => {
|
||||
if !success {
|
||||
process::exit(1)
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
print_error(&format!("Error syncing trees: {}", error));
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
cmd::ReposAction::Status(args) => match &args.config {
|
||||
Some(config_path) => {
|
||||
let config = match config::read_config(config_path) {
|
||||
Ok(config) => config,
|
||||
Err(error) => {
|
||||
print_error(&error);
|
||||
process::exit(1);
|
||||
}
|
||||
};
|
||||
match grm::table::get_status_table(config) {
|
||||
Ok((tables, errors)) => {
|
||||
for table in tables {
|
||||
println!("{}", table);
|
||||
}
|
||||
for error in errors {
|
||||
print_error(&format!("Error: {}", error));
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
print_error(&format!("Error getting status: {}", error));
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
None => {
|
||||
let dir = match std::env::current_dir() {
|
||||
Ok(dir) => dir,
|
||||
Err(error) => {
|
||||
print_error(&format!("Could not open current directory: {}", error));
|
||||
process::exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
match grm::table::show_single_repo_status(&dir) {
|
||||
Ok((table, warnings)) => {
|
||||
println!("{}", table);
|
||||
for warning in warnings {
|
||||
print_warning(&warning);
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
print_error(&format!("Error getting status: {}", error));
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
cmd::ReposAction::Find(find) => {
|
||||
let path = Path::new(&find.path);
|
||||
if !path.exists() {
|
||||
print_error(&format!("Path \"{}\" does not exist", path.display()));
|
||||
process::exit(1);
|
||||
}
|
||||
if !path.is_dir() {
|
||||
print_error(&format!("Path \"{}\" is not a directory", path.display()));
|
||||
process::exit(1);
|
||||
}
|
||||
|
||||
let path = match path.canonicalize() {
|
||||
Ok(path) => path,
|
||||
Err(error) => {
|
||||
print_error(&format!(
|
||||
"Failed to canonicalize path \"{}\". This is a bug. Error message: {}",
|
||||
&path.display(),
|
||||
error
|
||||
));
|
||||
process::exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
let (found_repos, warnings) = match grm::find_in_tree(&path) {
|
||||
Ok((repos, warnings)) => (repos, warnings),
|
||||
Err(error) => {
|
||||
print_error(&error);
|
||||
process::exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
let trees = grm::config::Trees::from_vec(vec![found_repos]);
|
||||
if trees.as_vec_ref().iter().all(|t| match &t.repos {
|
||||
None => false,
|
||||
Some(r) => r.is_empty(),
|
||||
}) {
|
||||
print_warning("No repositories found");
|
||||
} else {
|
||||
let config = trees.to_config();
|
||||
|
||||
match find.format {
|
||||
cmd::ConfigFormat::Toml => {
|
||||
let toml = match config.as_toml() {
|
||||
Ok(toml) => toml,
|
||||
Err(error) => {
|
||||
print_error(&format!(
|
||||
"Failed converting config to TOML: {}",
|
||||
&error
|
||||
));
|
||||
process::exit(1);
|
||||
}
|
||||
};
|
||||
print!("{}", toml);
|
||||
}
|
||||
cmd::ConfigFormat::Yaml => {
|
||||
let yaml = match config.as_yaml() {
|
||||
Ok(yaml) => yaml,
|
||||
Err(error) => {
|
||||
print_error(&format!(
|
||||
"Failed converting config to YAML: {}",
|
||||
&error
|
||||
));
|
||||
process::exit(1);
|
||||
}
|
||||
};
|
||||
print!("{}", yaml);
|
||||
}
|
||||
}
|
||||
}
|
||||
for warning in warnings {
|
||||
print_warning(&warning);
|
||||
}
|
||||
}
|
||||
},
|
||||
cmd::SubCommand::Worktree(args) => {
|
||||
let cwd = std::env::current_dir().unwrap_or_else(|error| {
|
||||
print_error(&format!("Could not open current directory: {}", error));
|
||||
process::exit(1);
|
||||
});
|
||||
|
||||
match args.action {
|
||||
cmd::WorktreeAction::Add(action_args) => {
|
||||
let track = match &action_args.track {
|
||||
Some(branch) => {
|
||||
let split = branch.split_once('/');
|
||||
|
||||
if split.is_none()
|
||||
|| split.unwrap().0.is_empty()
|
||||
|| split.unwrap().1.is_empty()
|
||||
{
|
||||
print_error("Tracking branch needs to match the pattern <remote>/<branch_name>");
|
||||
process::exit(1);
|
||||
};
|
||||
|
||||
// unwrap() here is safe because we checked for
|
||||
// is_none() explictily before
|
||||
let (remote_name, remote_branch_name) = split.unwrap();
|
||||
|
||||
Some((remote_name, remote_branch_name))
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
|
||||
let mut name: &str = &action_args.name;
|
||||
let subdirectory;
|
||||
let split = name.split_once('/');
|
||||
match split {
|
||||
None => subdirectory = None,
|
||||
Some(split) => {
|
||||
if split.0.is_empty() || split.1.is_empty() {
|
||||
print_error("Worktree name cannot start or end with a slash");
|
||||
process::exit(1);
|
||||
} else {
|
||||
(subdirectory, name) = (Some(Path::new(split.0)), split.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
match grm::add_worktree(&cwd, name, subdirectory, track, action_args.no_track) {
|
||||
Ok(_) => print_success(&format!("Worktree {} created", &action_args.name)),
|
||||
Err(error) => {
|
||||
print_error(&format!("Error creating worktree: {}", error));
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
cmd::WorktreeAction::Delete(action_args) => {
|
||||
let worktree_dir = cwd.join(&action_args.name);
|
||||
|
||||
let worktree_config = match repo::read_worktree_root_config(&cwd) {
|
||||
Ok(config) => config,
|
||||
Err(error) => {
|
||||
print_error(&format!(
|
||||
"Error getting worktree configuration: {}",
|
||||
error
|
||||
));
|
||||
process::exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
let repo = grm::Repo::open(&cwd, true).unwrap_or_else(|error| {
|
||||
print_error(&format!("Error opening repository: {}", error));
|
||||
process::exit(1);
|
||||
});
|
||||
|
||||
match repo.remove_worktree(
|
||||
&action_args.name,
|
||||
&worktree_dir,
|
||||
action_args.force,
|
||||
&worktree_config,
|
||||
) {
|
||||
Ok(_) => print_success(&format!("Worktree {} deleted", &action_args.name)),
|
||||
Err(error) => {
|
||||
match error {
|
||||
grm::WorktreeRemoveFailureReason::Error(msg) => {
|
||||
print_error(&msg);
|
||||
process::exit(1);
|
||||
}
|
||||
grm::WorktreeRemoveFailureReason::Changes(changes) => {
|
||||
print_warning(&format!(
|
||||
"Changes in worktree: {}. Refusing to delete",
|
||||
changes
|
||||
));
|
||||
}
|
||||
grm::WorktreeRemoveFailureReason::NotMerged(message) => {
|
||||
print_warning(&message);
|
||||
}
|
||||
}
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
cmd::WorktreeAction::Status(_args) => {
|
||||
let repo = grm::Repo::open(&cwd, true).unwrap_or_else(|error| {
|
||||
print_error(&format!("Error opening repository: {}", error));
|
||||
process::exit(1);
|
||||
});
|
||||
|
||||
match grm::table::get_worktree_status_table(&repo, &cwd) {
|
||||
Ok((table, errors)) => {
|
||||
println!("{}", table);
|
||||
for error in errors {
|
||||
print_error(&format!("Error: {}", error));
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
print_error(&format!("Error getting status: {}", error));
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
cmd::WorktreeAction::Convert(_args) => {
|
||||
// Converting works like this:
|
||||
// * Check whether there are uncommitted/unpushed changes
|
||||
// * Move the contents of .git dir to the worktree directory
|
||||
// * Remove all files
|
||||
// * Set `core.bare` to `true`
|
||||
|
||||
let repo = grm::Repo::open(&cwd, false).unwrap_or_else(|error| {
|
||||
if error.kind == grm::RepoErrorKind::NotFound {
|
||||
print_error("Directory does not contain a git repository");
|
||||
} else {
|
||||
print_error(&format!("Opening repository failed: {}", error));
|
||||
}
|
||||
process::exit(1);
|
||||
});
|
||||
|
||||
match repo.convert_to_worktree(&cwd) {
|
||||
Ok(_) => print_success("Conversion done"),
|
||||
Err(reason) => {
|
||||
match reason {
|
||||
repo::WorktreeConversionFailureReason::Changes => {
|
||||
print_error("Changes found in repository, refusing to convert");
|
||||
}
|
||||
repo::WorktreeConversionFailureReason::Ignored => {
|
||||
print_error("Ignored files found in repository, refusing to convert. Run git clean -f -d -X to remove them manually.");
|
||||
}
|
||||
repo::WorktreeConversionFailureReason::Error(error) => {
|
||||
print_error(&format!("Error during conversion: {}", error));
|
||||
}
|
||||
}
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
cmd::WorktreeAction::Clean(_args) => {
|
||||
let repo = grm::Repo::open(&cwd, true).unwrap_or_else(|error| {
|
||||
if error.kind == grm::RepoErrorKind::NotFound {
|
||||
print_error("Directory does not contain a git repository");
|
||||
} else {
|
||||
print_error(&format!("Opening repository failed: {}", error));
|
||||
}
|
||||
process::exit(1);
|
||||
});
|
||||
|
||||
match repo.cleanup_worktrees(&cwd) {
|
||||
Ok(warnings) => {
|
||||
for warning in warnings {
|
||||
print_warning(&warning);
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
print_error(&format!("Worktree cleanup failed: {}", error));
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
for unmanaged_worktree in
|
||||
repo.find_unmanaged_worktrees(&cwd).unwrap_or_else(|error| {
|
||||
print_error(&format!("Failed finding unmanaged worktrees: {}", error));
|
||||
process::exit(1);
|
||||
})
|
||||
{
|
||||
print_warning(&format!(
|
||||
"Found {}, which is not a valid worktree directory!",
|
||||
&unmanaged_worktree
|
||||
));
|
||||
}
|
||||
}
|
||||
cmd::WorktreeAction::Fetch(_args) => {
|
||||
let repo = grm::Repo::open(&cwd, true).unwrap_or_else(|error| {
|
||||
if error.kind == grm::RepoErrorKind::NotFound {
|
||||
print_error("Directory does not contain a git repository");
|
||||
} else {
|
||||
print_error(&format!("Opening repository failed: {}", error));
|
||||
}
|
||||
process::exit(1);
|
||||
});
|
||||
|
||||
repo.fetchall().unwrap_or_else(|error| {
|
||||
print_error(&format!("Error fetching remotes: {}", error));
|
||||
process::exit(1);
|
||||
});
|
||||
print_success("Fetched from all remotes");
|
||||
}
|
||||
cmd::WorktreeAction::Pull(args) => {
|
||||
let repo = grm::Repo::open(&cwd, true).unwrap_or_else(|error| {
|
||||
if error.kind == grm::RepoErrorKind::NotFound {
|
||||
print_error("Directory does not contain a git repository");
|
||||
} else {
|
||||
print_error(&format!("Opening repository failed: {}", error));
|
||||
}
|
||||
process::exit(1);
|
||||
});
|
||||
|
||||
repo.fetchall().unwrap_or_else(|error| {
|
||||
print_error(&format!("Error fetching remotes: {}", error));
|
||||
process::exit(1);
|
||||
});
|
||||
|
||||
let mut failures = false;
|
||||
for worktree in repo.get_worktrees().unwrap_or_else(|error| {
|
||||
print_error(&format!("Error getting worktrees: {}", error));
|
||||
process::exit(1);
|
||||
}) {
|
||||
if let Some(warning) = worktree
|
||||
.forward_branch(args.rebase, args.stash)
|
||||
.unwrap_or_else(|error| {
|
||||
print_error(&format!("Error updating worktree branch: {}", error));
|
||||
process::exit(1);
|
||||
})
|
||||
{
|
||||
print_warning(&format!("{}: {}", worktree.name(), warning));
|
||||
failures = true;
|
||||
} else {
|
||||
print_success(&format!("{}: Done", worktree.name()));
|
||||
}
|
||||
}
|
||||
if failures {
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
cmd::WorktreeAction::Rebase(args) => {
|
||||
if args.rebase && !args.pull {
|
||||
print_error("There is no point in using --rebase without --pull");
|
||||
process::exit(1);
|
||||
}
|
||||
let repo = grm::Repo::open(&cwd, true).unwrap_or_else(|error| {
|
||||
if error.kind == grm::RepoErrorKind::NotFound {
|
||||
print_error("Directory does not contain a git repository");
|
||||
} else {
|
||||
print_error(&format!("Opening repository failed: {}", error));
|
||||
}
|
||||
process::exit(1);
|
||||
});
|
||||
|
||||
if args.pull {
|
||||
repo.fetchall().unwrap_or_else(|error| {
|
||||
print_error(&format!("Error fetching remotes: {}", error));
|
||||
process::exit(1);
|
||||
});
|
||||
}
|
||||
|
||||
let config =
|
||||
grm::repo::read_worktree_root_config(&cwd).unwrap_or_else(|error| {
|
||||
print_error(&format!(
|
||||
"Failed to read worktree configuration: {}",
|
||||
error
|
||||
));
|
||||
process::exit(1);
|
||||
});
|
||||
|
||||
let worktrees = repo.get_worktrees().unwrap_or_else(|error| {
|
||||
print_error(&format!("Error getting worktrees: {}", error));
|
||||
process::exit(1);
|
||||
});
|
||||
|
||||
let mut failures = false;
|
||||
|
||||
for worktree in &worktrees {
|
||||
if args.pull {
|
||||
if let Some(warning) = worktree
|
||||
.forward_branch(args.rebase, args.stash)
|
||||
.unwrap_or_else(|error| {
|
||||
print_error(&format!(
|
||||
"Error updating worktree branch: {}",
|
||||
error
|
||||
));
|
||||
process::exit(1);
|
||||
})
|
||||
{
|
||||
failures = true;
|
||||
print_warning(&format!("{}: {}", worktree.name(), warning));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for worktree in &worktrees {
|
||||
if let Some(warning) = worktree
|
||||
.rebase_onto_default(&config, args.stash)
|
||||
.unwrap_or_else(|error| {
|
||||
print_error(&format!("Error rebasing worktree branch: {}", error));
|
||||
process::exit(1);
|
||||
})
|
||||
{
|
||||
failures = true;
|
||||
print_warning(&format!("{}: {}", worktree.name(), warning));
|
||||
} else {
|
||||
print_success(&format!("{}: Done", worktree.name()));
|
||||
}
|
||||
}
|
||||
if failures {
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1251
src/lib.rs
1251
src/lib.rs
File diff suppressed because it is too large
Load Diff
@@ -1,5 +0,0 @@
|
||||
use grm::run;
|
||||
|
||||
fn main() {
|
||||
run();
|
||||
}
|
||||
1304
src/repo.rs
1304
src/repo.rs
File diff suppressed because it is too large
Load Diff
323
src/table.rs
Normal file
323
src/table.rs
Normal file
@@ -0,0 +1,323 @@
|
||||
use comfy_table::{Cell, Table};
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
fn add_table_header(table: &mut Table) {
|
||||
table
|
||||
.load_preset(comfy_table::presets::UTF8_FULL)
|
||||
.apply_modifier(comfy_table::modifiers::UTF8_ROUND_CORNERS)
|
||||
.set_header(vec![
|
||||
Cell::new("Repo"),
|
||||
Cell::new("Worktree"),
|
||||
Cell::new("Status"),
|
||||
Cell::new("Branches"),
|
||||
Cell::new("HEAD"),
|
||||
Cell::new("Remotes"),
|
||||
]);
|
||||
}
|
||||
|
||||
fn add_repo_status(
|
||||
table: &mut Table,
|
||||
repo_name: &str,
|
||||
repo_handle: &crate::Repo,
|
||||
is_worktree: bool,
|
||||
) -> Result<(), String> {
|
||||
let repo_status = repo_handle.status(is_worktree)?;
|
||||
|
||||
table.add_row(vec![
|
||||
repo_name,
|
||||
match is_worktree {
|
||||
true => "\u{2714}",
|
||||
false => "",
|
||||
},
|
||||
&match is_worktree {
|
||||
true => String::from(""),
|
||||
false => match repo_status.changes {
|
||||
Some(changes) => {
|
||||
let mut out = Vec::new();
|
||||
if changes.files_new > 0 {
|
||||
out.push(format!("New: {}\n", changes.files_new))
|
||||
}
|
||||
if changes.files_modified > 0 {
|
||||
out.push(format!("Modified: {}\n", changes.files_modified))
|
||||
}
|
||||
if changes.files_deleted > 0 {
|
||||
out.push(format!("Deleted: {}\n", changes.files_deleted))
|
||||
}
|
||||
out.into_iter().collect::<String>().trim().to_string()
|
||||
}
|
||||
None => String::from("\u{2714}"),
|
||||
},
|
||||
},
|
||||
repo_status
|
||||
.branches
|
||||
.iter()
|
||||
.map(|(branch_name, remote_branch)| {
|
||||
format!(
|
||||
"branch: {}{}\n",
|
||||
&branch_name,
|
||||
&match remote_branch {
|
||||
None => String::from(" <!local>"),
|
||||
Some((remote_branch_name, remote_tracking_status)) => {
|
||||
format!(
|
||||
" <{}>{}",
|
||||
remote_branch_name,
|
||||
&match remote_tracking_status {
|
||||
crate::RemoteTrackingStatus::UpToDate =>
|
||||
String::from(" \u{2714}"),
|
||||
crate::RemoteTrackingStatus::Ahead(d) => format!(" [+{}]", &d),
|
||||
crate::RemoteTrackingStatus::Behind(d) => format!(" [-{}]", &d),
|
||||
crate::RemoteTrackingStatus::Diverged(d1, d2) =>
|
||||
format!(" [+{}/-{}]", &d1, &d2),
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
.collect::<String>()
|
||||
.trim(),
|
||||
&match is_worktree {
|
||||
true => String::from(""),
|
||||
false => match repo_status.head {
|
||||
Some(head) => head,
|
||||
None => String::from("Empty"),
|
||||
},
|
||||
},
|
||||
repo_status
|
||||
.remotes
|
||||
.iter()
|
||||
.map(|r| format!("{}\n", r))
|
||||
.collect::<String>()
|
||||
.trim(),
|
||||
]);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Don't return table, return a type that implements Display(?)
|
||||
pub fn get_worktree_status_table(
|
||||
repo: &crate::Repo,
|
||||
directory: &Path,
|
||||
) -> Result<(impl std::fmt::Display, Vec<String>), String> {
|
||||
let worktrees = repo.get_worktrees()?;
|
||||
let mut table = Table::new();
|
||||
|
||||
let mut errors = Vec::new();
|
||||
|
||||
add_worktree_table_header(&mut table);
|
||||
for worktree in &worktrees {
|
||||
let worktree_dir = &directory.join(&worktree.name());
|
||||
if worktree_dir.exists() {
|
||||
let repo = match crate::Repo::open(worktree_dir, false) {
|
||||
Ok(repo) => repo,
|
||||
Err(error) => {
|
||||
errors.push(format!(
|
||||
"Failed opening repo of worktree {}: {}",
|
||||
&worktree.name(),
|
||||
&error
|
||||
));
|
||||
continue;
|
||||
}
|
||||
};
|
||||
if let Err(error) = add_worktree_status(&mut table, worktree, &repo) {
|
||||
errors.push(error);
|
||||
}
|
||||
} else {
|
||||
errors.push(format!(
|
||||
"Worktree {} does not have a directory",
|
||||
&worktree.name()
|
||||
));
|
||||
}
|
||||
}
|
||||
for entry in std::fs::read_dir(&directory).map_err(|error| error.to_string())? {
|
||||
let dirname = crate::path_as_string(
|
||||
entry
|
||||
.map_err(|error| error.to_string())?
|
||||
.path()
|
||||
.strip_prefix(&directory)
|
||||
// this unwrap is safe, as we can be sure that each subentry of
|
||||
// &directory also has the prefix &dir
|
||||
.unwrap(),
|
||||
);
|
||||
if dirname == crate::GIT_MAIN_WORKTREE_DIRECTORY {
|
||||
continue;
|
||||
}
|
||||
if !&worktrees.iter().any(|worktree| worktree.name() == dirname) {
|
||||
errors.push(format!(
|
||||
"Found {}, which is not a valid worktree directory!",
|
||||
&dirname
|
||||
));
|
||||
}
|
||||
}
|
||||
Ok((table, errors))
|
||||
}
|
||||
|
||||
pub fn get_status_table(config: crate::Config) -> Result<(Vec<Table>, Vec<String>), String> {
|
||||
let mut errors = Vec::new();
|
||||
let mut tables = Vec::new();
|
||||
for tree in config.trees.as_vec() {
|
||||
let repos = tree.repos.unwrap_or_default();
|
||||
|
||||
let root_path = crate::expand_path(Path::new(&tree.root));
|
||||
|
||||
let mut table = Table::new();
|
||||
add_table_header(&mut table);
|
||||
|
||||
for repo in &repos {
|
||||
let repo_path = root_path.join(&repo.name);
|
||||
|
||||
if !repo_path.exists() {
|
||||
errors.push(format!(
|
||||
"{}: Repository does not exist. Run sync?",
|
||||
&repo.name
|
||||
));
|
||||
continue;
|
||||
}
|
||||
|
||||
let repo_handle = crate::Repo::open(&repo_path, repo.worktree_setup);
|
||||
|
||||
let repo_handle = match repo_handle {
|
||||
Ok(repo) => repo,
|
||||
Err(error) => {
|
||||
if error.kind == crate::RepoErrorKind::NotFound {
|
||||
errors.push(format!(
|
||||
"{}: No git repository found. Run sync?",
|
||||
&repo.name
|
||||
));
|
||||
} else {
|
||||
errors.push(format!(
|
||||
"{}: Opening repository failed: {}",
|
||||
&repo.name, error
|
||||
));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
add_repo_status(&mut table, &repo.name, &repo_handle, repo.worktree_setup)?;
|
||||
}
|
||||
|
||||
tables.push(table);
|
||||
}
|
||||
|
||||
Ok((tables, errors))
|
||||
}
|
||||
|
||||
fn add_worktree_table_header(table: &mut Table) {
|
||||
table
|
||||
.load_preset(comfy_table::presets::UTF8_FULL)
|
||||
.apply_modifier(comfy_table::modifiers::UTF8_ROUND_CORNERS)
|
||||
.set_header(vec![
|
||||
Cell::new("Worktree"),
|
||||
Cell::new("Status"),
|
||||
Cell::new("Branch"),
|
||||
Cell::new("Remote branch"),
|
||||
]);
|
||||
}
|
||||
|
||||
fn add_worktree_status(
|
||||
table: &mut Table,
|
||||
worktree: &crate::repo::Worktree,
|
||||
repo: &crate::Repo,
|
||||
) -> Result<(), String> {
|
||||
let repo_status = repo.status(false)?;
|
||||
|
||||
let local_branch = repo
|
||||
.head_branch()
|
||||
.map_err(|error| format!("Failed getting head branch: {}", error))?;
|
||||
|
||||
let upstream_output = match local_branch.upstream() {
|
||||
Ok(remote_branch) => {
|
||||
let remote_branch_name = remote_branch
|
||||
.name()
|
||||
.map_err(|error| format!("Failed getting name of remote branch: {}", error))?;
|
||||
|
||||
let (ahead, behind) = repo
|
||||
.graph_ahead_behind(&local_branch, &remote_branch)
|
||||
.map_err(|error| format!("Failed computing branch deviation: {}", error))?;
|
||||
|
||||
format!(
|
||||
"{}{}\n",
|
||||
&remote_branch_name,
|
||||
&match (ahead, behind) {
|
||||
(0, 0) => String::from(""),
|
||||
(d, 0) => format!(" [+{}]", &d),
|
||||
(0, d) => format!(" [-{}]", &d),
|
||||
(d1, d2) => format!(" [+{}/-{}]", &d1, &d2),
|
||||
},
|
||||
)
|
||||
}
|
||||
Err(_) => String::from(""),
|
||||
};
|
||||
|
||||
table.add_row(vec![
|
||||
worktree.name(),
|
||||
&match repo_status.changes {
|
||||
Some(changes) => {
|
||||
let mut out = Vec::new();
|
||||
if changes.files_new > 0 {
|
||||
out.push(format!("New: {}\n", changes.files_new))
|
||||
}
|
||||
if changes.files_modified > 0 {
|
||||
out.push(format!("Modified: {}\n", changes.files_modified))
|
||||
}
|
||||
if changes.files_deleted > 0 {
|
||||
out.push(format!("Deleted: {}\n", changes.files_deleted))
|
||||
}
|
||||
out.into_iter().collect::<String>().trim().to_string()
|
||||
}
|
||||
None => String::from("\u{2714}"),
|
||||
},
|
||||
&local_branch
|
||||
.name()
|
||||
.map_err(|error| format!("Failed getting name of branch: {}", error))?,
|
||||
&upstream_output,
|
||||
]);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn show_single_repo_status(
|
||||
path: &Path,
|
||||
) -> Result<(impl std::fmt::Display, Vec<String>), String> {
|
||||
let mut table = Table::new();
|
||||
let mut warnings = Vec::new();
|
||||
|
||||
let is_worktree = crate::Repo::detect_worktree(path);
|
||||
add_table_header(&mut table);
|
||||
|
||||
let repo_handle = crate::Repo::open(path, is_worktree);
|
||||
|
||||
if let Err(error) = repo_handle {
|
||||
if error.kind == crate::RepoErrorKind::NotFound {
|
||||
return Err(String::from("Directory is not a git directory"));
|
||||
} else {
|
||||
return Err(format!("Opening repository failed: {}", error));
|
||||
}
|
||||
};
|
||||
|
||||
let repo_name = match path.file_name() {
|
||||
None => {
|
||||
warnings.push(format!(
|
||||
"Cannot detect repo name for path {}. Are you working in /?",
|
||||
&path.display()
|
||||
));
|
||||
String::from("unknown")
|
||||
}
|
||||
Some(file_name) => match file_name.to_str() {
|
||||
None => {
|
||||
warnings.push(format!(
|
||||
"Name of repo directory {} is not valid UTF-8",
|
||||
&path.display()
|
||||
));
|
||||
String::from("invalid")
|
||||
}
|
||||
Some(name) => name.to_string(),
|
||||
},
|
||||
};
|
||||
|
||||
add_repo_status(&mut table, &repo_name, &repo_handle.unwrap(), is_worktree)?;
|
||||
|
||||
Ok((table, warnings))
|
||||
}
|
||||
@@ -8,13 +8,13 @@ use helpers::*;
|
||||
fn open_empty_repo() {
|
||||
let tmpdir = init_tmpdir();
|
||||
assert!(matches!(
|
||||
open_repo(tmpdir.path(), true),
|
||||
Repo::open(tmpdir.path(), true),
|
||||
Err(RepoError {
|
||||
kind: RepoErrorKind::NotFound
|
||||
})
|
||||
));
|
||||
assert!(matches!(
|
||||
open_repo(tmpdir.path(), false),
|
||||
Repo::open(tmpdir.path(), false),
|
||||
Err(RepoError {
|
||||
kind: RepoErrorKind::NotFound
|
||||
})
|
||||
@@ -25,7 +25,7 @@ fn open_empty_repo() {
|
||||
#[test]
|
||||
fn create_repo() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let tmpdir = init_tmpdir();
|
||||
let repo = init_repo(tmpdir.path(), false)?;
|
||||
let repo = Repo::init(tmpdir.path(), false)?;
|
||||
assert!(!repo.is_bare());
|
||||
assert!(repo.is_empty()?);
|
||||
cleanup_tmpdir(tmpdir);
|
||||
@@ -35,7 +35,7 @@ fn create_repo() -> Result<(), Box<dyn std::error::Error>> {
|
||||
#[test]
|
||||
fn create_repo_with_worktree() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let tmpdir = init_tmpdir();
|
||||
let repo = init_repo(tmpdir.path(), true)?;
|
||||
let repo = Repo::init(tmpdir.path(), true)?;
|
||||
assert!(repo.is_bare());
|
||||
assert!(repo.is_empty()?);
|
||||
cleanup_tmpdir(tmpdir);
|
||||
|
||||
Reference in New Issue
Block a user