git-remote-dropbox 2.0.2__tar.gz → 2.0.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- git_remote_dropbox-2.0.3/.editorconfig +11 -0
- git_remote_dropbox-2.0.3/.github/workflows/build.yml +44 -0
- git_remote_dropbox-2.0.3/.gitignore +2 -0
- git_remote_dropbox-2.0.3/CONTRIBUTING.md +63 -0
- git_remote_dropbox-2.0.3/DESIGN.md +110 -0
- {git-remote-dropbox-2.0.2 → git_remote_dropbox-2.0.3}/PKG-INFO +11 -16
- git_remote_dropbox-2.0.3/pyproject.toml +53 -0
- {git-remote-dropbox-2.0.2 → git_remote_dropbox-2.0.3/src}/git_remote_dropbox/__init__.py +1 -1
- {git-remote-dropbox-2.0.2 → git_remote_dropbox-2.0.3/src}/git_remote_dropbox/cli/common.py +13 -16
- {git-remote-dropbox-2.0.2 → git_remote_dropbox-2.0.3/src}/git_remote_dropbox/cli/helper.py +7 -8
- {git-remote-dropbox-2.0.2 → git_remote_dropbox-2.0.3/src}/git_remote_dropbox/cli/manage.py +31 -36
- {git-remote-dropbox-2.0.2 → git_remote_dropbox-2.0.3/src}/git_remote_dropbox/constants.py +1 -2
- {git-remote-dropbox-2.0.2 → git_remote_dropbox-2.0.3/src}/git_remote_dropbox/git.py +14 -18
- {git-remote-dropbox-2.0.2 → git_remote_dropbox-2.0.3/src}/git_remote_dropbox/helper.py +76 -81
- {git-remote-dropbox-2.0.2 → git_remote_dropbox-2.0.3/src}/git_remote_dropbox/util.py +25 -24
- git_remote_dropbox-2.0.3/tests/.gitignore +1 -0
- git_remote_dropbox-2.0.3/tests/README.md +22 -0
- git_remote_dropbox-2.0.3/tests/Vagrantfile +27 -0
- git_remote_dropbox-2.0.3/tests/dropbox_delete.py +21 -0
- git_remote_dropbox-2.0.3/tests/test-lib.sh +70 -0
- git_remote_dropbox-2.0.3/tests/test.sh +100 -0
- git-remote-dropbox-2.0.2/git_remote_dropbox.egg-info/PKG-INFO +0 -199
- git-remote-dropbox-2.0.2/git_remote_dropbox.egg-info/SOURCES.txt +0 -19
- git-remote-dropbox-2.0.2/git_remote_dropbox.egg-info/dependency_links.txt +0 -1
- git-remote-dropbox-2.0.2/git_remote_dropbox.egg-info/entry_points.txt +0 -4
- git-remote-dropbox-2.0.2/git_remote_dropbox.egg-info/requires.txt +0 -2
- git-remote-dropbox-2.0.2/git_remote_dropbox.egg-info/top_level.txt +0 -1
- git-remote-dropbox-2.0.2/pyproject.toml +0 -11
- git-remote-dropbox-2.0.2/setup.cfg +0 -4
- git-remote-dropbox-2.0.2/setup.py +0 -64
- {git-remote-dropbox-2.0.2 → git_remote_dropbox-2.0.3}/LICENSE.md +0 -0
- {git-remote-dropbox-2.0.2 → git_remote_dropbox-2.0.3}/README.md +0 -0
- {git-remote-dropbox-2.0.2 → git_remote_dropbox-2.0.3/src}/git_remote_dropbox/cli/__init__.py +0 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
schedule:
|
|
5
|
+
- cron: '0 8 * * 6'
|
|
6
|
+
jobs:
|
|
7
|
+
test:
|
|
8
|
+
runs-on: ubuntu-20.04
|
|
9
|
+
environment: main
|
|
10
|
+
strategy:
|
|
11
|
+
matrix:
|
|
12
|
+
python: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
|
|
13
|
+
name: "Test: Python ${{ matrix.python }}"
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
- uses: actions/setup-python@v5
|
|
17
|
+
with:
|
|
18
|
+
python-version: ${{ matrix.python }}
|
|
19
|
+
- run: |
|
|
20
|
+
python -m pip install --upgrade pip
|
|
21
|
+
- run: pip install .
|
|
22
|
+
- run: ./tests/test.sh
|
|
23
|
+
env:
|
|
24
|
+
DROPBOX_TOKEN: ${{ secrets.DROPBOX_TOKEN }}
|
|
25
|
+
typecheck:
|
|
26
|
+
name: Type check
|
|
27
|
+
runs-on: ubuntu-24.04
|
|
28
|
+
steps:
|
|
29
|
+
- uses: actions/checkout@v4
|
|
30
|
+
- uses: actions/setup-python@v5
|
|
31
|
+
with:
|
|
32
|
+
python-version: "3.13"
|
|
33
|
+
- uses: pypa/hatch@install
|
|
34
|
+
- run: hatch run types:check
|
|
35
|
+
fmt:
|
|
36
|
+
name: Format and lint
|
|
37
|
+
runs-on: ubuntu-24.04
|
|
38
|
+
steps:
|
|
39
|
+
- uses: actions/checkout@v4
|
|
40
|
+
- uses: actions/setup-python@v5
|
|
41
|
+
with:
|
|
42
|
+
python-version: "3.13"
|
|
43
|
+
- uses: pypa/hatch@install
|
|
44
|
+
- run: hatch fmt --check
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
All kinds of contributions to git-remote-dropbox are greatly appreciated. For
|
|
4
|
+
someone unfamiliar with the code base, the easiest way to contribute is
|
|
5
|
+
probably to submit a [feature request](#feature-requests) or [bug
|
|
6
|
+
report](#bug-reports). If you want to dive into the source code, you can submit
|
|
7
|
+
a [patch](#patches) as well, either working on your own ideas or [existing
|
|
8
|
+
issues][issues].
|
|
9
|
+
|
|
10
|
+
## Feature Requests
|
|
11
|
+
|
|
12
|
+
Do you have an idea for an improvement to git-remote-dropbox? Please [submit a
|
|
13
|
+
feature request][issue]. It's great to hear about new ideas.
|
|
14
|
+
|
|
15
|
+
If you are inclined to do so, you're welcome to [fork][fork]
|
|
16
|
+
git-remote-dropbox, work on implementing the feature yourself, and submit a
|
|
17
|
+
patch. In this case, it's *highly recommended* that you first [open an
|
|
18
|
+
issue][issue] describing your enhancement to get early feedback on what you're
|
|
19
|
+
doing. This will help avoid wasted efforts and ensure that your work is
|
|
20
|
+
incorporated into the code base.
|
|
21
|
+
|
|
22
|
+
## Bug Reports
|
|
23
|
+
|
|
24
|
+
Did something go wrong with git-remote-dropbox? Sorry about that! Bug reports
|
|
25
|
+
are greatly appreciated!
|
|
26
|
+
|
|
27
|
+
When you [submit a bug report][issue], please include relevant information such
|
|
28
|
+
as git-remote-dropbox version, Git version, operating system, error messages,
|
|
29
|
+
and steps to reproduce the bug. The more details you can include, the easier it
|
|
30
|
+
is to find and fix the bug.
|
|
31
|
+
|
|
32
|
+
## Patches
|
|
33
|
+
|
|
34
|
+
Want to hack on git-remote-dropbox? Awesome!
|
|
35
|
+
|
|
36
|
+
You may find the documentation in [DESIGN.md][design] and the source code
|
|
37
|
+
helpful.
|
|
38
|
+
|
|
39
|
+
If there are [open issues][issues], you're more than welcome to work on those -
|
|
40
|
+
this is probably the best way to contribute code to git-remote-dropbox. If you
|
|
41
|
+
have your own ideas, that's great too! In that case, before working on
|
|
42
|
+
substantial changes to the code base, it is *highly recommended* that you first
|
|
43
|
+
[open an issue][issue] describing what you intend to work on.
|
|
44
|
+
|
|
45
|
+
**Patches are generally submitted as pull requests.** Patches are also
|
|
46
|
+
[accepted over email][email].
|
|
47
|
+
|
|
48
|
+
Any changes to the code base should follow the style and coding conventions
|
|
49
|
+
used in the rest of the project. The version history should be clean, and
|
|
50
|
+
commit messages should be descriptive and [properly
|
|
51
|
+
formatted][commit-messages].
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
If you have any questions about anything, feel free to [ask][email]!
|
|
56
|
+
|
|
57
|
+
[design]: DESIGN.md
|
|
58
|
+
[issue]: https://github.com/anishathalye/git-remote-dropbox/issues/new
|
|
59
|
+
[issues]: https://github.com/anishathalye/git-remote-dropbox/issues
|
|
60
|
+
[fork]: https://github.com/anishathalye/git-remote-dropbox/fork
|
|
61
|
+
[email]: mailto:me@anishathalye.com
|
|
62
|
+
[gitremote-helpers]: https://www.kernel.org/pub/software/scm/git/docs/gitremote-helpers.html
|
|
63
|
+
[commit-messages]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Design
|
|
2
|
+
|
|
3
|
+
Many things are designed the way they are in order to have the same semantics
|
|
4
|
+
and guarantees as a regular Git remote *without running any special code on the
|
|
5
|
+
server side*.
|
|
6
|
+
|
|
7
|
+
git-remote-dropbox is a [Git remote helper][gitremote-helper].
|
|
8
|
+
|
|
9
|
+
To support all Git operations, we need to support one capability for pushing
|
|
10
|
+
and one capability for fetching. For our use case, the best way to do this is
|
|
11
|
+
to implement the `push` and `fetch` capabilities. Alternatives are better
|
|
12
|
+
suited for interacting with foreign version control systems.
|
|
13
|
+
|
|
14
|
+
## Repository Layout
|
|
15
|
+
|
|
16
|
+
We store repository data on Dropbox in a similar way to how Git stores data on
|
|
17
|
+
disk. In particular, we store [references][git-references] and [loose
|
|
18
|
+
objects][git-objects], which make up all information that needs to be stored on
|
|
19
|
+
the server. The repository folder layout looks almost identical to a bare Git
|
|
20
|
+
repository.
|
|
21
|
+
|
|
22
|
+
### References
|
|
23
|
+
|
|
24
|
+
References are stored in `refs` (relative to the repository root). The format
|
|
25
|
+
of references is identical to how Git stores references in the `.git`
|
|
26
|
+
directory. For example, the `master` ref would be stored in
|
|
27
|
+
`refs/heads/master`, and the file would contain the SHA1 hash corresponding to
|
|
28
|
+
the commit that the master branch points to.
|
|
29
|
+
|
|
30
|
+
### Symbolic References
|
|
31
|
+
|
|
32
|
+
Symbolic references are stored in the repository root. The format of the
|
|
33
|
+
symbolic refs is identical to how Git stores symbolic refs in the `.git`
|
|
34
|
+
directory. For example, `HEAD` would be stored in `HEAD`, and if it is pointing
|
|
35
|
+
to `refs/heads/master`, the file would contain `ref: refs/heads/master`.
|
|
36
|
+
|
|
37
|
+
### Objects
|
|
38
|
+
|
|
39
|
+
Objects are stored in `objects` (relative to the repository root). The path and
|
|
40
|
+
file name of objects is identical to how Git stores loose objects in the `.git`
|
|
41
|
+
directory. For example, an object with the hash
|
|
42
|
+
`5f1594aa9545fab32ae35276cb03002f29ce9b79` would be stored in
|
|
43
|
+
`objects/5f/1594aa9545fab32ae35276cb03002f29ce9b79`.
|
|
44
|
+
|
|
45
|
+
The files may not actually be identical on disk due to differences in DEFLATE
|
|
46
|
+
compression, but in fact, if the files are copied as-is into a local Git
|
|
47
|
+
repository, Git will recognize the files as valid.
|
|
48
|
+
|
|
49
|
+
git-remote-dropbox stores all objects as loose objects - it does not pack
|
|
50
|
+
objects. This means that we do not perform delta compression. In addition, we
|
|
51
|
+
do not perform garbage collection of dangling objects.
|
|
52
|
+
|
|
53
|
+
## Push
|
|
54
|
+
|
|
55
|
+
To push a ref, we need to ensure that the server has all objects reachable from
|
|
56
|
+
the ref, and we need to update the ref in a safe way such that concurrent
|
|
57
|
+
operations don't cause problems.
|
|
58
|
+
|
|
59
|
+
### Objects
|
|
60
|
+
|
|
61
|
+
We can use the `git rev-list --objects <ref>` command to get all the objects
|
|
62
|
+
reachable from `ref`. We could just upload all of these, but that would be a
|
|
63
|
+
lot of unnecessary work, equivalent to uploading the entire repository for
|
|
64
|
+
every push.
|
|
65
|
+
|
|
66
|
+
Instead, we can figure out exactly what objects the server is missing, and then
|
|
67
|
+
we can upload only those objects. We can get a list of refs present on the
|
|
68
|
+
server, and then we can compute which objects the server is missing by using
|
|
69
|
+
`git rev-list --objects <ref> ^<exclude>`, where `exclude` is a ref present on
|
|
70
|
+
the server. We can do this with multiple exclusions too.
|
|
71
|
+
|
|
72
|
+
Once we have the list of objects that the server is missing, we can upload them
|
|
73
|
+
all. Because objects are content-addressed, we don't need to worry about
|
|
74
|
+
conflicts.
|
|
75
|
+
|
|
76
|
+
### Refs
|
|
77
|
+
|
|
78
|
+
Pushing the ref itself is slightly more complicated. Once all the objects are
|
|
79
|
+
present, we need to update the remote ref atomically. First, we check if we're
|
|
80
|
+
performing a fast-forward, and then we perform a compare-and-swap operation. If
|
|
81
|
+
there are any concurrent changes, we require the user to fetch before
|
|
82
|
+
continuing, maintaining safety.
|
|
83
|
+
|
|
84
|
+
We can perform a compare-and-swap operation in Dropbox by using the "update"
|
|
85
|
+
write mode with a specific revision number.
|
|
86
|
+
|
|
87
|
+
If we're doing a force push, the process is simpler - we can just overwrite the
|
|
88
|
+
ref with the new value.
|
|
89
|
+
|
|
90
|
+
If we're deleting a branch, we make sure that we're not deleting the default
|
|
91
|
+
branch before deleting the ref.
|
|
92
|
+
|
|
93
|
+
### Symbolic refs
|
|
94
|
+
|
|
95
|
+
The symbolic ref `HEAD` is set upon repository creation.
|
|
96
|
+
|
|
97
|
+
## Fetch
|
|
98
|
+
|
|
99
|
+
For fetching remote refs, we could just fetch everything from the `objects`
|
|
100
|
+
directory. However, that would be really slow because of all the unnecessary
|
|
101
|
+
work involved, especially when fetching small changes.
|
|
102
|
+
|
|
103
|
+
Instead, we fetch refs by recursively downloading all of the objects reachable
|
|
104
|
+
from the object pointed to by the ref, terminating branches of the recursion
|
|
105
|
+
when we reach objects that we already have locally, provided that we have the
|
|
106
|
+
full history from that point on.
|
|
107
|
+
|
|
108
|
+
[gitremote-helper]: https://www.kernel.org/pub/software/scm/git/docs/gitremote-helpers.html
|
|
109
|
+
[git-objects]: https://git-scm.com/book/en/v2/Git-Internals-Git-Objects
|
|
110
|
+
[git-references]: https://git-scm.com/book/en/v2/Git-Internals-Git-References
|
|
@@ -1,26 +1,21 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: git-remote-dropbox
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.3
|
|
4
4
|
Summary: A transparent bidirectional bridge between Git and Dropbox
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
Project-URL: homepage, https://github.com/anishathalye/git-remote-dropbox
|
|
6
|
+
Project-URL: repository, https://github.com/anishathalye/git-remote-dropbox.git
|
|
7
|
+
Project-URL: issues, https://github.com/anishathalye/git-remote-dropbox/issues
|
|
8
|
+
Author-email: Anish Athalye <me@anishathalye.com>
|
|
9
|
+
License-File: LICENSE.md
|
|
10
|
+
Keywords: dropbox,git
|
|
10
11
|
Classifier: Development Status :: 5 - Production/Stable
|
|
11
12
|
Classifier: Intended Audience :: Developers
|
|
12
|
-
Classifier: Topic :: Software Development :: Version Control
|
|
13
13
|
Classifier: License :: OSI Approved :: MIT License
|
|
14
14
|
Classifier: Programming Language :: Python :: 3
|
|
15
|
-
Classifier:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Topic :: Software Development :: Version Control
|
|
16
|
+
Requires-Python: >=3.6
|
|
17
|
+
Requires-Dist: dropbox<13,>=12
|
|
20
18
|
Description-Content-Type: text/markdown
|
|
21
|
-
License-File: LICENSE.md
|
|
22
|
-
Requires-Dist: dropbox<12,>=11
|
|
23
|
-
Requires-Dist: setuptools
|
|
24
19
|
|
|
25
20
|
# git-remote-dropbox [](https://github.com/anishathalye/git-remote-dropbox/actions?query=workflow%3ACI) [](https://pypi.org/pypi/git-remote-dropbox/)
|
|
26
21
|
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "git-remote-dropbox"
|
|
7
|
+
authors = [
|
|
8
|
+
{ name = "Anish Athalye", email = "me@anishathalye.com" },
|
|
9
|
+
]
|
|
10
|
+
description = "A transparent bidirectional bridge between Git and Dropbox"
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
requires-python = ">=3.6"
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Development Status :: 5 - Production/Stable",
|
|
15
|
+
"Intended Audience :: Developers",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Topic :: Software Development :: Version Control",
|
|
19
|
+
]
|
|
20
|
+
keywords = ["git", "dropbox"]
|
|
21
|
+
dynamic = ["version"]
|
|
22
|
+
dependencies = [
|
|
23
|
+
"dropbox>=12,<13"
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[project.scripts]
|
|
27
|
+
git-remote-dropbox = "git_remote_dropbox.cli.helper:main"
|
|
28
|
+
git-dropbox = "git_remote_dropbox.cli.manage:main"
|
|
29
|
+
# Users might have a `git dropbox` alias set up for `git-dropbox-manage`,
|
|
30
|
+
# according to the old instructions. Don't break their config.
|
|
31
|
+
git-dropbox-manage = "git_remote_dropbox.cli.manage:main"
|
|
32
|
+
|
|
33
|
+
[project.urls]
|
|
34
|
+
homepage = "https://github.com/anishathalye/git-remote-dropbox"
|
|
35
|
+
repository = "https://github.com/anishathalye/git-remote-dropbox.git"
|
|
36
|
+
issues = "https://github.com/anishathalye/git-remote-dropbox/issues"
|
|
37
|
+
|
|
38
|
+
[tool.hatch.version]
|
|
39
|
+
path = "src/git_remote_dropbox/__init__.py"
|
|
40
|
+
|
|
41
|
+
[tool.hatch.envs.types]
|
|
42
|
+
extra-dependencies = [
|
|
43
|
+
"mypy>=1.0.0",
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
[tool.hatch.envs.types.scripts]
|
|
47
|
+
check = "mypy --strict --install-types --non-interactive {args:src tests}"
|
|
48
|
+
|
|
49
|
+
[tool.ruff.lint]
|
|
50
|
+
ignore = [
|
|
51
|
+
"FA100",
|
|
52
|
+
"T201",
|
|
53
|
+
]
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
from typing import NoReturn
|
|
4
|
+
from urllib.parse import urlparse
|
|
5
|
+
|
|
6
|
+
import dropbox # type: ignore
|
|
7
|
+
|
|
8
|
+
from git_remote_dropbox.helper import Helper
|
|
1
9
|
from git_remote_dropbox.util import (
|
|
2
10
|
Config,
|
|
3
|
-
stderr,
|
|
4
|
-
Token,
|
|
5
11
|
LongLivedToken,
|
|
12
|
+
Token,
|
|
13
|
+
stderr,
|
|
6
14
|
)
|
|
7
|
-
from git_remote_dropbox.helper import Helper
|
|
8
|
-
|
|
9
|
-
import dropbox # type: ignore
|
|
10
|
-
|
|
11
|
-
import sys
|
|
12
|
-
import os
|
|
13
|
-
from typing import NoReturn
|
|
14
|
-
from urllib.parse import urlparse
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
def error(msg: str) -> NoReturn:
|
|
18
|
-
stderr("error:
|
|
18
|
+
stderr(f"error: {msg}\n")
|
|
19
19
|
sys.exit(1)
|
|
20
20
|
|
|
21
21
|
|
|
@@ -71,7 +71,7 @@ def get_helper(url: str) -> Helper:
|
|
|
71
71
|
elif parsed.username:
|
|
72
72
|
t = config.get_named_token(parsed.username)
|
|
73
73
|
if not t:
|
|
74
|
-
error("you must log in first with 'git dropbox login
|
|
74
|
+
error(f"you must log in first with 'git dropbox login {parsed.username}'")
|
|
75
75
|
token = t
|
|
76
76
|
else:
|
|
77
77
|
t = config.get_default_token()
|
|
@@ -86,10 +86,7 @@ def get_helper(url: str) -> Helper:
|
|
|
86
86
|
"invalid inline legacy access token, try switching to short-lived access tokens with 'git dropbox login'"
|
|
87
87
|
)
|
|
88
88
|
elif parsed.username:
|
|
89
|
-
error(
|
|
90
|
-
"invalid access token, try logging in again with 'git dropbox login %s'"
|
|
91
|
-
% parsed.username
|
|
92
|
-
)
|
|
89
|
+
error(f"invalid access token, try logging in again with 'git dropbox login {parsed.username}'")
|
|
93
90
|
else:
|
|
94
91
|
error("invalid access token, try logging in again with 'git dropbox login'")
|
|
95
92
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
stdout_to_binary,
|
|
4
|
-
)
|
|
1
|
+
import sys
|
|
2
|
+
|
|
5
3
|
from git_remote_dropbox.cli.common import (
|
|
6
4
|
error,
|
|
7
5
|
get_helper,
|
|
8
6
|
)
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
from git_remote_dropbox.util import (
|
|
8
|
+
Level,
|
|
9
|
+
stdout_to_binary,
|
|
10
|
+
)
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
def main() -> None:
|
|
@@ -24,8 +24,7 @@ def main() -> None:
|
|
|
24
24
|
except Exception:
|
|
25
25
|
if helper.verbosity >= Level.DEBUG:
|
|
26
26
|
raise # re-raise exception so it prints out a stack trace
|
|
27
|
-
|
|
28
|
-
error("unexpected exception (run with -v for details)")
|
|
27
|
+
error("unexpected exception (run with -v for details)")
|
|
29
28
|
except KeyboardInterrupt:
|
|
30
29
|
# exit silently with an error code
|
|
31
30
|
sys.exit(1)
|
|
@@ -1,19 +1,18 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import subprocess
|
|
3
|
+
import sys
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
import dropbox # type: ignore
|
|
7
|
+
|
|
1
8
|
import git_remote_dropbox
|
|
2
|
-
from git_remote_dropbox import constants
|
|
3
|
-
from git_remote_dropbox import git
|
|
4
|
-
from git_remote_dropbox.util import RefreshToken, LongLivedToken
|
|
9
|
+
from git_remote_dropbox import constants, git
|
|
5
10
|
from git_remote_dropbox.cli.common import (
|
|
6
11
|
error,
|
|
7
|
-
get_helper,
|
|
8
12
|
get_config,
|
|
13
|
+
get_helper,
|
|
9
14
|
)
|
|
10
|
-
|
|
11
|
-
import dropbox # type: ignore
|
|
12
|
-
|
|
13
|
-
import argparse
|
|
14
|
-
import subprocess
|
|
15
|
-
import sys
|
|
16
|
-
from typing import Optional
|
|
15
|
+
from git_remote_dropbox.util import LongLivedToken, RefreshToken
|
|
17
16
|
|
|
18
17
|
|
|
19
18
|
def main() -> None:
|
|
@@ -29,7 +28,7 @@ def main() -> None:
|
|
|
29
28
|
parser_set_head.add_argument("remote", type=str, help="name of the remote")
|
|
30
29
|
parser_set_head.add_argument("branch", type=str, help="name of the branch on the remote")
|
|
31
30
|
|
|
32
|
-
parser_version = subparsers.add_parser(
|
|
31
|
+
parser_version = subparsers.add_parser( # noqa: F841
|
|
33
32
|
"version", help="print the version of git-remote-dropbox"
|
|
34
33
|
)
|
|
35
34
|
|
|
@@ -39,7 +38,7 @@ def main() -> None:
|
|
|
39
38
|
parser_logout = subparsers.add_parser("logout", help="log out from Dropbox")
|
|
40
39
|
parser_logout.add_argument("username", type=str, help="username/tag", nargs="?", default=None)
|
|
41
40
|
|
|
42
|
-
parser_show_logins = subparsers.add_parser(
|
|
41
|
+
parser_show_logins = subparsers.add_parser( # noqa: F841
|
|
43
42
|
"show-logins", help="show logged-in accounts and their usernames/tags"
|
|
44
43
|
)
|
|
45
44
|
|
|
@@ -70,26 +69,23 @@ def set_head(remote: str, branch: str) -> None:
|
|
|
70
69
|
try:
|
|
71
70
|
url = git.get_remote_url(remote)
|
|
72
71
|
except subprocess.CalledProcessError:
|
|
73
|
-
error("no such remote '
|
|
72
|
+
error(f"no such remote '{remote}'")
|
|
74
73
|
sys.exit(1)
|
|
75
74
|
helper = get_helper(url)
|
|
76
75
|
|
|
77
|
-
remote_ref = "refs/heads
|
|
76
|
+
remote_ref = f"refs/heads/{branch}"
|
|
78
77
|
|
|
79
78
|
def branch_exists() -> bool:
|
|
80
|
-
refs = helper.get_refs(False)
|
|
81
|
-
for _, name in refs
|
|
82
|
-
if name == remote_ref:
|
|
83
|
-
return True
|
|
84
|
-
return False
|
|
79
|
+
refs = helper.get_refs(for_push=False)
|
|
80
|
+
return any(name == remote_ref for _, name in refs)
|
|
85
81
|
|
|
86
82
|
# check if target branch exists
|
|
87
83
|
if not branch_exists():
|
|
88
|
-
error("remote has no such ref '
|
|
84
|
+
error(f"remote has no such ref '{remote_ref}'")
|
|
89
85
|
# get current head
|
|
90
86
|
old_head = helper.read_symbolic_ref("HEAD")
|
|
91
87
|
if old_head and old_head[1] == remote_ref:
|
|
92
|
-
error("remote HEAD is already '
|
|
88
|
+
error(f"remote HEAD is already '{remote_ref}'")
|
|
93
89
|
rev = old_head[0] if old_head else None
|
|
94
90
|
# write new head
|
|
95
91
|
ok = helper.write_symbolic_ref("HEAD", remote_ref, rev=rev)
|
|
@@ -99,24 +95,26 @@ def set_head(remote: str, branch: str) -> None:
|
|
|
99
95
|
if not branch_exists():
|
|
100
96
|
# this should be a really rare occurrence: have the user fix it up if
|
|
101
97
|
# it happens
|
|
102
|
-
error("remote ref '
|
|
103
|
-
print("Updated remote HEAD to '
|
|
98
|
+
error(f"remote ref '{remote_ref}' was concurrently deleted: remote HEAD needs to be fixed (try again)")
|
|
99
|
+
print(f"Updated remote HEAD to '{remote_ref}'.")
|
|
104
100
|
|
|
105
101
|
|
|
106
102
|
def login(username: Optional[str]) -> None:
|
|
107
103
|
auth_flow = dropbox.DropboxOAuth2FlowNoRedirect(
|
|
108
|
-
constants.APP_KEY,
|
|
104
|
+
constants.APP_KEY,
|
|
105
|
+
use_pkce=True,
|
|
106
|
+
token_access_type="offline", # noqa: S106
|
|
109
107
|
)
|
|
110
108
|
authorize_url = auth_flow.start()
|
|
111
109
|
print("Logging in to Dropbox using OAuth...")
|
|
112
|
-
print("1. Go to:
|
|
110
|
+
print(f"1. Go to: {authorize_url}")
|
|
113
111
|
print('2. Click "Allow" (you might have to log in first)')
|
|
114
112
|
print("3. Copy the authorization code")
|
|
115
113
|
auth_code = input("Enter authorization code: ").strip()
|
|
116
114
|
try:
|
|
117
115
|
oauth_result = auth_flow.finish(auth_code)
|
|
118
116
|
token = RefreshToken(oauth_result.refresh_token)
|
|
119
|
-
except Exception:
|
|
117
|
+
except Exception: # noqa: BLE001
|
|
120
118
|
error("failed to log in; did you copy the code correctly?")
|
|
121
119
|
|
|
122
120
|
config = get_config()
|
|
@@ -126,11 +124,8 @@ def login(username: Optional[str]) -> None:
|
|
|
126
124
|
config.set_named_token(username, token)
|
|
127
125
|
config.save()
|
|
128
126
|
|
|
129
|
-
if username is None
|
|
130
|
-
|
|
131
|
-
else:
|
|
132
|
-
example = "dropbox://%s@/path/to/repo" % username
|
|
133
|
-
print("Successfully logged in! You can now add Dropbox remotes like '%s'" % example)
|
|
127
|
+
example = "dropbox:///path/to/repo" if username is None else f"dropbox://{username}@/path/to/repo"
|
|
128
|
+
print(f"Successfully logged in! You can now add Dropbox remotes like '{example}'")
|
|
134
129
|
|
|
135
130
|
|
|
136
131
|
def logout(username: Optional[str]) -> None:
|
|
@@ -142,7 +137,7 @@ def logout(username: Optional[str]) -> None:
|
|
|
142
137
|
else:
|
|
143
138
|
config.delete_named_token(username)
|
|
144
139
|
config.save()
|
|
145
|
-
print("Logged out
|
|
140
|
+
print(f"Logged out {username}!")
|
|
146
141
|
|
|
147
142
|
|
|
148
143
|
def show_logins() -> None:
|
|
@@ -152,13 +147,13 @@ def show_logins() -> None:
|
|
|
152
147
|
deprecated = ""
|
|
153
148
|
if isinstance(token, LongLivedToken):
|
|
154
149
|
deprecated = " [deprecated long-lived token]"
|
|
155
|
-
print("(default user)
|
|
150
|
+
print(f"(default user){deprecated}")
|
|
156
151
|
for username, token in config.named_tokens().items():
|
|
157
152
|
deprecated = ""
|
|
158
153
|
if isinstance(token, LongLivedToken):
|
|
159
154
|
deprecated = " [deprecated long-lived token]"
|
|
160
|
-
print("
|
|
155
|
+
print(f"{username}{deprecated}")
|
|
161
156
|
|
|
162
157
|
|
|
163
158
|
def version() -> None:
|
|
164
|
-
print("git-remote-dropbox
|
|
159
|
+
print(f"git-remote-dropbox {git_remote_dropbox.__version__}")
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import os
|
|
2
2
|
from typing import TextIO
|
|
3
3
|
|
|
4
|
-
|
|
5
4
|
APP_KEY: str = "h7d8z1irmz0r7lp"
|
|
6
|
-
DEVNULL: TextIO = open(os.devnull, "w")
|
|
5
|
+
DEVNULL: TextIO = open(os.devnull, "w") # noqa: SIM115
|
|
7
6
|
PROCESSES: int = 20
|
|
8
7
|
MAX_RETRIES: int = 3
|
|
9
8
|
CHUNK_SIZE: int = 50 * 1024 * 1024 # 50 megabytes
|