git-remote-dropbox 1.1.4__tar.gz → 2.0.1__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.
Files changed (29) hide show
  1. git-remote-dropbox-2.0.1/LICENSE.md +22 -0
  2. git-remote-dropbox-2.0.1/PKG-INFO +199 -0
  3. {git-remote-dropbox-1.1.4 → git-remote-dropbox-2.0.1}/README.md +47 -48
  4. {git-remote-dropbox-1.1.4 → git-remote-dropbox-2.0.1}/git_remote_dropbox/__init__.py +2 -2
  5. git-remote-dropbox-2.0.1/git_remote_dropbox/cli/common.py +96 -0
  6. {git-remote-dropbox-1.1.4 → git-remote-dropbox-2.0.1}/git_remote_dropbox/cli/helper.py +3 -3
  7. git-remote-dropbox-2.0.1/git_remote_dropbox/cli/manage.py +164 -0
  8. git-remote-dropbox-2.0.1/git_remote_dropbox/constants.py +9 -0
  9. {git-remote-dropbox-1.1.4 → git-remote-dropbox-2.0.1}/git_remote_dropbox/git.py +61 -54
  10. {git-remote-dropbox-1.1.4 → git-remote-dropbox-2.0.1}/git_remote_dropbox/helper.py +177 -153
  11. git-remote-dropbox-2.0.1/git_remote_dropbox/util.py +279 -0
  12. git-remote-dropbox-2.0.1/git_remote_dropbox.egg-info/PKG-INFO +199 -0
  13. {git-remote-dropbox-1.1.4 → git-remote-dropbox-2.0.1}/git_remote_dropbox.egg-info/SOURCES.txt +2 -1
  14. {git-remote-dropbox-1.1.4 → git-remote-dropbox-2.0.1}/git_remote_dropbox.egg-info/entry_points.txt +1 -1
  15. git-remote-dropbox-2.0.1/git_remote_dropbox.egg-info/requires.txt +2 -0
  16. git-remote-dropbox-2.0.1/pyproject.toml +11 -0
  17. {git-remote-dropbox-1.1.4 → git-remote-dropbox-2.0.1}/setup.cfg +0 -3
  18. git-remote-dropbox-2.0.1/setup.py +64 -0
  19. git-remote-dropbox-1.1.4/PKG-INFO +0 -200
  20. git-remote-dropbox-1.1.4/git_remote_dropbox/cli/common.py +0 -73
  21. git-remote-dropbox-1.1.4/git_remote_dropbox/cli/manage.py +0 -81
  22. git-remote-dropbox-1.1.4/git_remote_dropbox/constants.py +0 -8
  23. git-remote-dropbox-1.1.4/git_remote_dropbox/util.py +0 -121
  24. git-remote-dropbox-1.1.4/git_remote_dropbox.egg-info/PKG-INFO +0 -200
  25. git-remote-dropbox-1.1.4/git_remote_dropbox.egg-info/requires.txt +0 -1
  26. git-remote-dropbox-1.1.4/setup.py +0 -79
  27. {git-remote-dropbox-1.1.4 → git-remote-dropbox-2.0.1}/git_remote_dropbox/cli/__init__.py +0 -0
  28. {git-remote-dropbox-1.1.4 → git-remote-dropbox-2.0.1}/git_remote_dropbox.egg-info/dependency_links.txt +0 -0
  29. {git-remote-dropbox-1.1.4 → git-remote-dropbox-2.0.1}/git_remote_dropbox.egg-info/top_level.txt +0 -0
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+ =====================
3
+
4
+ **Copyright (c) Anish Athalye (me@anishathalye.com)**
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
7
+ this software and associated documentation files (the "Software"), to deal in
8
+ the Software without restriction, including without limitation the rights to
9
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10
+ of the Software, and to permit persons to whom the Software is furnished to do
11
+ so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
@@ -0,0 +1,199 @@
1
+ Metadata-Version: 2.1
2
+ Name: git-remote-dropbox
3
+ Version: 2.0.1
4
+ Summary: A transparent bidirectional bridge between Git and Dropbox
5
+ Home-page: https://github.com/anishathalye/git-remote-dropbox
6
+ Author: Anish Athalye
7
+ Author-email: me@anishathalye.com
8
+ License: MIT
9
+ Keywords: git dropbox
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Topic :: Software Development :: Version Control
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.6
16
+ Classifier: Programming Language :: Python :: 3.7
17
+ Classifier: Programming Language :: Python :: 3.8
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE.md
22
+ Requires-Dist: dropbox<12,>=11
23
+ Requires-Dist: setuptools<70,>=69
24
+
25
+ # git-remote-dropbox [![Build Status](https://github.com/anishathalye/git-remote-dropbox/workflows/CI/badge.svg)](https://github.com/anishathalye/git-remote-dropbox/actions?query=workflow%3ACI) [![pypi](https://img.shields.io/pypi/v/git-remote-dropbox.svg)](https://pypi.org/pypi/git-remote-dropbox/)
26
+
27
+ git-remote-dropbox is a transparent bidirectional bridge between Git and
28
+ Dropbox. It lets you use a Dropbox folder or a shared folder as a Git remote!
29
+
30
+ ---
31
+
32
+ This Git remote helper makes Dropbox act like a _true Git remote_. It maintains
33
+ _all guarantees_ that are provided by a traditional Git remote while using
34
+ Dropbox as a backing store. This means that it works correctly even when there
35
+ are multiple people operating on the repository at once, making it possible to
36
+ use a Dropbox shared folder as a Git remote for collaboration.
37
+
38
+ Once the helper is installed, using it is as simple as adding a remote like
39
+ `dropbox:///path/to/repo`.
40
+
41
+ To clone repositories in folders or shared folders mounted in your Dropbox, you
42
+ can run:
43
+
44
+ ```bash
45
+ git clone "dropbox:///path/to/repo"
46
+ ```
47
+
48
+ To add a remote to an existing local repository, you can run:
49
+
50
+ ```bash
51
+ git remote add origin "dropbox:///path/to/repo"
52
+ ```
53
+
54
+ The repository directory will be created automatically the first time you push.
55
+
56
+ After adding the remote, you can treat it just like a regular Git remote. The
57
+ Dropbox-backed remote supports all operations that regular remotes support, and
58
+ it provides identical guarantees in terms of atomicity even when there are
59
+ concurrent operations, even when using a shared folder.
60
+
61
+ ## Setup
62
+
63
+ ### Install git-remote-dropbox
64
+
65
+ 1. Prerequisites:
66
+ 1. `python` and matching `pip`
67
+ 2. `git`
68
+ 2. Install this package with `pip install git-remote-dropbox`. Use `which git-remote-dropbox` to make sure it's available via `$PATH`. If not, edit `$PATH` appropriately.
69
+
70
+ ### Log in to Dropbox
71
+
72
+ Run `git dropbox login` and follow the instructions to authenticate with OAuth
73
+ and log in to your Dropbox account.
74
+
75
+ ## Sharing
76
+
77
+ The above gives you a way to create a Git repository on Dropbox and use it from multiple machines that you own. In other words, it's a convenient way to share a remote with your laptop and your desktop.
78
+
79
+ If you want to share with other people, you should explicitly share (e.g. via the Dropbox website) the root folder of the repo with your collaborators. Then they should also install git-remote-dropbox and log in *with their own account*.
80
+
81
+ ## Multiple Accounts
82
+
83
+ git-remote-dropbox supports using multiple Dropbox accounts. You can have named
84
+ accounts with `git dropbox login <username>`. **These usernames are unrelated
85
+ to your Dropbox login; you can choose whatever names you want to organize your
86
+ accounts, e.g. "work".**
87
+
88
+ You can tell git-remote-dropbox to use a particular account by setting the git
89
+ remote URL appropriately, specifying a username like:
90
+ `dropbox://username@/path/to/repo`.
91
+
92
+ ## Repository Manager
93
+
94
+ In addition to the git remote helper, git-remote-dropbox comes with an
95
+ additional tool to manage your logins and repositories on Dropbox. This tool
96
+ can be invoked as `git dropbox`.
97
+
98
+ The tool supports the following commands:
99
+
100
+ - `git dropbox login [username]`: log in, either with the default account (no
101
+ need to specify a username in remote), or with an alias (for multi-account
102
+ support)
103
+ - `git dropbox logout [username]`: log out
104
+ - `git dropbox show-logins`: list logged-in accounts
105
+ - `git dropbox set-head <remote> <branch>`: set default branch on the remote
106
+ - `git dropbox version`: show version
107
+
108
+ ## Notes
109
+
110
+ - Do not directly interact with Git repositories in your Dropbox folder -always
111
+ use git-remote-dropbox. If you're using the Dropbox client to sync files,
112
+ it's a good idea to use [selective
113
+ sync](https://help.dropbox.com/installs-integrations/sync-uploads/selective-sync-overview)
114
+ and disable syncing of the folder containing the repository to avoid any
115
+ unexpected conflicts, just in case.
116
+
117
+ - git-remote-dropbox does not use the Dropbox desktop client - it uses the API
118
+ directly. It does not require that the desktop client is installed.
119
+
120
+ - The remote helper does not support shallow cloning.
121
+
122
+ - Cloning a repository or fetching a lot of objects produces lots of loose
123
+ objects. To save space in the local repository, run `git gc --aggressive`.
124
+
125
+ - If the remote HEAD (default branch on the remote) is not set, after cloning a
126
+ repository from Dropbox, Git will not automatically check out a branch. To
127
+ check out a branch, run `git checkout <branch>`. To set the default branch on
128
+ the remote, use the [`git dropbox`](#repository-manager) command.
129
+
130
+ ## FAQ
131
+
132
+ **Why shouldn't I keep my Git repository in Dropbox and let the client sync
133
+ it?**
134
+
135
+ There seem to be a lot of articles on the Internet recommending this as a good
136
+ workflow. However, this is *not a good idea*! The desktop client is not aware
137
+ of how Git manages it's on-disk format, so if there are concurrent changes or
138
+ delays in syncing, it's possible to have conflicts that result in a corrupted
139
+ Git repository. This may be uncommon with the way the timing works out in the
140
+ single user case, but it's still not safe!
141
+
142
+ **Why shouldn't I keep a bare Git repository in a Dropbox shared folder, use it
143
+ as a folder-based Git remote, and sync it with the desktop client?**
144
+
145
+ There seem to be some articles on the Internet suggesting that this is a good
146
+ idea. It's not. Using the desktop client to sync a bare Git repository is not
147
+ safe. Concurrent changes or delays in syncing can result in a corrupted Git
148
+ repository.
149
+
150
+ **How can I access / recover my repository from Dropbox without using the
151
+ git-remote-dropbox helper?**
152
+
153
+ Because git-remote-dropbox uses an on-disk format that's compatible with Git,
154
+ accessing your repository without using the helper is easy:
155
+
156
+ 1. Download the repository data (a directory containing the `objects` and
157
+ `refs` directories) from Dropbox.
158
+ 2. Make a new directory and initialize an empty Git repository in the
159
+ directory.
160
+ 3. Overwrite `.git/refs` and `.git/objects` in your newly initialized
161
+ repository with the data downloaded from Dropbox (using a command like `rm
162
+ -rf .git/{refs,objects} && cp -r /path/to/data/{refs,objects} .git/`).
163
+ 4. Check out a branch (using a command like `git checkout -f master`).
164
+ 5. Optionally, run `git gc --aggressive` to save disk space in your local
165
+ repository.
166
+
167
+ **How do I use git-remote-dropbox from behind a proxy server?**
168
+
169
+ You can use git-remote-dropbox from behind a proxy server by setting the
170
+ `HTTP_PROXY` and `HTTPS_PROXY` environment variables. See
171
+ [here](http://docs.python-requests.org/en/latest/user/advanced/#proxies) for
172
+ more details.
173
+
174
+ **How do I use git-remote-dropbox with submodules?**
175
+
176
+ You can allow this by setting
177
+ [`protocol.dropbox.allow`](https://git-scm.com/docs/git-config#Documentation/git-config.txt-protocolltnamegtallow)
178
+ to `always`:
179
+
180
+ ```bash
181
+ git config --global --add protocol.dropbox.allow always
182
+ ```
183
+
184
+ ## Design
185
+
186
+ To read about the design of git-remote-dropbox, see [DESIGN.md](DESIGN.md).
187
+ This could be especially useful if you're thinking about contributing to the
188
+ project.
189
+
190
+ ## Contributing
191
+
192
+ Do you have ideas on how to improve git-remote-dropbox? Have a feature request,
193
+ bug report, or patch? Great! See [CONTRIBUTING.md](CONTRIBUTING.md) for
194
+ information on what you can do about that.
195
+
196
+ ## License
197
+
198
+ Copyright (c) Anish Athalye. Released under the MIT License. See
199
+ [LICENSE.md](LICENSE.md) for details.
@@ -1,4 +1,4 @@
1
- # git-remote-dropbox [![Build Status](https://github.com/anishathalye/git-remote-dropbox/workflows/CI/badge.svg)](https://github.com/anishathalye/git-remote-dropbox/actions?query=workflow%3ACI)
1
+ # git-remote-dropbox [![Build Status](https://github.com/anishathalye/git-remote-dropbox/workflows/CI/badge.svg)](https://github.com/anishathalye/git-remote-dropbox/actions?query=workflow%3ACI) [![pypi](https://img.shields.io/pypi/v/git-remote-dropbox.svg)](https://pypi.org/pypi/git-remote-dropbox/)
2
2
 
3
3
  git-remote-dropbox is a transparent bidirectional bridge between Git and
4
4
  Dropbox. It lets you use a Dropbox folder or a shared folder as a Git remote!
@@ -36,59 +36,50 @@ concurrent operations, even when using a shared folder.
36
36
 
37
37
  ## Setup
38
38
 
39
- 1. Install the helper with `pip install git-remote-dropbox`. Make sure the
40
- `git-remote-dropbox` executable is on your `$PATH`.
39
+ ### Install git-remote-dropbox
41
40
 
42
- 2. Generate an OAuth 2 token by going to the [app
43
- console](https://www.dropbox.com/developers/apps), creating a Dropbox API
44
- app with "Full Dropbox" access (or "App folder" access if you prefer, if
45
- you're not going to be using Dropbox's sharing features to use
46
- git-remote-dropbox in a multi-user setup), and generating an access token
47
- for yourself.
41
+ 1. Prerequisites:
42
+ 1. `python` and matching `pip`
43
+ 2. `git`
44
+ 2. Install this package with `pip install git-remote-dropbox`. Use `which git-remote-dropbox` to make sure it's available via `$PATH`. If not, edit `$PATH` appropriately.
48
45
 
49
- 3. Save your OAuth token in `~/.config/git/git-remote-dropbox.json` or
50
- `~/.git-remote-dropbox.json`. The file should look something like this:
46
+ ### Log in to Dropbox
51
47
 
52
- ```json
53
- {
54
- "default": "xxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxx"
55
- }
56
- ```
48
+ Run `git dropbox login` and follow the instructions to authenticate with OAuth
49
+ and log in to your Dropbox account.
57
50
 
58
- ## Multiple Accounts
51
+ ## Sharing
59
52
 
60
- git-remote-dropbox supports using multiple Dropbox accounts. You can create
61
- OAuth tokens for different accounts and add them all to the config file, using
62
- a user-defined username as the key:
53
+ The above gives you a way to create a Git repository on Dropbox and use it from multiple machines that you own. In other words, it's a convenient way to share a remote with your laptop and your desktop.
63
54
 
64
- ```json
65
- {
66
- "alice": "xxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxx",
67
- "ben": "xxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxx",
68
- "charlie": "xxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxx"
69
- }
70
- ```
55
+ If you want to share with other people, you should explicitly share (e.g. via the Dropbox website) the root folder of the repo with your collaborators. Then they should also install git-remote-dropbox and log in *with their own account*.
71
56
 
72
- You can tell git-remote-dropbox to use the token corresponding to `username` by
73
- specifying a URL like `dropbox://username@/path/to/repo`.
57
+ ## Multiple Accounts
74
58
 
75
- You can also specify the token inline by using a URL like
76
- `dropbox://:token@/path/to/repo`.
59
+ git-remote-dropbox supports using multiple Dropbox accounts. You can have named
60
+ accounts with `git dropbox login <username>`. **These usernames are unrelated
61
+ to your Dropbox login; you can choose whatever names you want to organize your
62
+ accounts, e.g. "work".**
63
+
64
+ You can tell git-remote-dropbox to use a particular account by setting the git
65
+ remote URL appropriately, specifying a username like:
66
+ `dropbox://username@/path/to/repo`.
77
67
 
78
68
  ## Repository Manager
79
69
 
80
70
  In addition to the git remote helper, git-remote-dropbox comes with an
81
- additional tool to manage repositories on Dropbox. This tool can be invoked as
82
- `git-dropbox-manage`. You can also create an alias for it with the following:
71
+ additional tool to manage your logins and repositories on Dropbox. This tool
72
+ can be invoked as `git dropbox`.
83
73
 
84
- ```bash
85
- git config --global alias.dropbox '!git-dropbox-manage'
86
- ```
87
-
88
- With this configuration, the tool can be invoked as `git dropbox`.
74
+ The tool supports the following commands:
89
75
 
90
- Currently the tool supports a single subcommand, `git dropbox set-head <remote>
91
- <branch>`, that can be used to set the default branch on the remote.
76
+ - `git dropbox login [username]`: log in, either with the default account (no
77
+ need to specify a username in remote), or with an alias (for multi-account
78
+ support)
79
+ - `git dropbox logout [username]`: log out
80
+ - `git dropbox show-logins`: list logged-in accounts
81
+ - `git dropbox set-head <remote> <branch>`: set default branch on the remote
82
+ - `git dropbox version`: show version
92
83
 
93
84
  ## Notes
94
85
 
@@ -98,15 +89,19 @@ Currently the tool supports a single subcommand, `git dropbox set-head <remote>
98
89
  sync](https://help.dropbox.com/installs-integrations/sync-uploads/selective-sync-overview)
99
90
  and disable syncing of the folder containing the repository to avoid any
100
91
  unexpected conflicts, just in case.
92
+
101
93
  - git-remote-dropbox does not use the Dropbox desktop client - it uses the API
102
94
  directly. It does not require that the desktop client is installed.
95
+
103
96
  - The remote helper does not support shallow cloning.
97
+
104
98
  - Cloning a repository or fetching a lot of objects produces lots of loose
105
99
  objects. To save space in the local repository, run `git gc --aggressive`.
100
+
106
101
  - If the remote HEAD (default branch on the remote) is not set, after cloning a
107
102
  repository from Dropbox, Git will not automatically check out a branch. To
108
103
  check out a branch, run `git checkout <branch>`. To set the default branch on
109
- the remote, use the [git-dropbox-manage](#repository-manager) command.
104
+ the remote, use the [`git dropbox`](#repository-manager) command.
110
105
 
111
106
  ## FAQ
112
107
 
@@ -152,6 +147,16 @@ You can use git-remote-dropbox from behind a proxy server by setting the
152
147
  [here](http://docs.python-requests.org/en/latest/user/advanced/#proxies) for
153
148
  more details.
154
149
 
150
+ **How do I use git-remote-dropbox with submodules?**
151
+
152
+ You can allow this by setting
153
+ [`protocol.dropbox.allow`](https://git-scm.com/docs/git-config#Documentation/git-config.txt-protocolltnamegtallow)
154
+ to `always`:
155
+
156
+ ```bash
157
+ git config --global --add protocol.dropbox.allow always
158
+ ```
159
+
155
160
  ## Design
156
161
 
157
162
  To read about the design of git-remote-dropbox, see [DESIGN.md](DESIGN.md).
@@ -164,13 +169,7 @@ Do you have ideas on how to improve git-remote-dropbox? Have a feature request,
164
169
  bug report, or patch? Great! See [CONTRIBUTING.md](CONTRIBUTING.md) for
165
170
  information on what you can do about that.
166
171
 
167
- ## Packaging
168
-
169
- 1. Update version information.
170
- 2. Build the package using `python setup.py sdist bdist_wheel`.
171
- 3. Sign and upload the package using `twine upload -s dist/*`.
172
-
173
172
  ## License
174
173
 
175
- Copyright (c) 2015-2020 Anish Athalye. Released under the MIT License. See
174
+ Copyright (c) Anish Athalye. Released under the MIT License. See
176
175
  [LICENSE.md](LICENSE.md) for details.
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2015-2020 Anish Athalye (me@anishathalye.com)
1
+ # Copyright (c) Anish Athalye (me@anishathalye.com)
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
19
  # SOFTWARE.
20
20
 
21
- __version__ = '1.1.4'
21
+ __version__ = "2.0.1"
@@ -0,0 +1,96 @@
1
+ from git_remote_dropbox.util import (
2
+ Config,
3
+ stderr,
4
+ Token,
5
+ LongLivedToken,
6
+ )
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
+
16
+
17
+ def error(msg: str) -> NoReturn:
18
+ stderr("error: %s\n" % msg)
19
+ sys.exit(1)
20
+
21
+
22
+ def get_config() -> Config:
23
+ config_files = [
24
+ os.path.join(
25
+ os.environ.get("XDG_CONFIG_HOME", os.path.expanduser("~/.config")),
26
+ "git",
27
+ "git-remote-dropbox.json",
28
+ ),
29
+ os.path.expanduser("~/.git-remote-dropbox.json"),
30
+ ]
31
+ for path in config_files:
32
+ if os.path.exists(path):
33
+ return Config(path)
34
+ path = config_files[0]
35
+ os.makedirs(os.path.dirname(path), exist_ok=True)
36
+ return Config(path, create=True)
37
+
38
+
39
+ def check_connection(dbx: dropbox.Dropbox) -> None:
40
+ dbx.users_get_current_account()
41
+
42
+
43
+ def get_helper(url: str) -> Helper:
44
+ """
45
+ Return a Helper configured to point at the given URL.
46
+
47
+ URLs must be formatted as:
48
+ dropbox:///path/to/repo
49
+ dropbox://username@/path/to/repo
50
+ dropbox://:token@/path/to/repo
51
+ """
52
+ parsed = urlparse(url)
53
+ if parsed.scheme != "dropbox":
54
+ error('URL must start with the "dropbox://" scheme')
55
+ if parsed.netloc:
56
+ if not parsed.username and not parsed.password:
57
+ # user probably put in something like "dropbox://path/to/repo"
58
+ # missing the third "/"
59
+ error('URL with no username or token must start with "dropbox:///"')
60
+ if parsed.username and parsed.password:
61
+ # user supplied both username and token
62
+ error("URL must not specify both username and token")
63
+ path = parsed.path.lower() # dropbox is case insensitive, so we must canonicalize
64
+ if path.endswith("/"):
65
+ error("URL path must not have trailing slash")
66
+
67
+ config = get_config()
68
+ token: Token
69
+ if parsed.password:
70
+ token = LongLivedToken(parsed.password)
71
+ elif parsed.username:
72
+ t = config.get_named_token(parsed.username)
73
+ if not t:
74
+ error("you must log in first with 'git dropbox login %s'" % parsed.username)
75
+ token = t
76
+ else:
77
+ t = config.get_default_token()
78
+ if not t:
79
+ error("you must log in first with 'git dropbox login'")
80
+ token = t
81
+ try:
82
+ check_connection(token.connect())
83
+ except dropbox.exceptions.DropboxException:
84
+ if parsed.password:
85
+ error(
86
+ "invalid inline legacy access token, try switching to short-lived access tokens with 'git dropbox login'"
87
+ )
88
+ elif parsed.username:
89
+ error(
90
+ "invalid access token, try logging in again with 'git dropbox login %s'"
91
+ % parsed.username
92
+ )
93
+ else:
94
+ error("invalid access token, try logging in again with 'git dropbox login'")
95
+
96
+ return Helper(token, path)
@@ -10,7 +10,7 @@ from git_remote_dropbox.cli.common import (
10
10
  import sys
11
11
 
12
12
 
13
- def main():
13
+ def main() -> None:
14
14
  """
15
15
  Main entry point for git-remote-dropbox Git remote helper.
16
16
  """
@@ -25,7 +25,7 @@ def main():
25
25
  if helper.verbosity >= Level.DEBUG:
26
26
  raise # re-raise exception so it prints out a stack trace
27
27
  else:
28
- error('unexpected exception (run with -v for details)')
28
+ error("unexpected exception (run with -v for details)")
29
29
  except KeyboardInterrupt:
30
30
  # exit silently with an error code
31
- exit(1)
31
+ sys.exit(1)
@@ -0,0 +1,164 @@
1
+ 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
5
+ from git_remote_dropbox.cli.common import (
6
+ error,
7
+ get_helper,
8
+ get_config,
9
+ )
10
+
11
+ import dropbox # type: ignore
12
+
13
+ import argparse
14
+ import subprocess
15
+ import sys
16
+ from typing import Optional
17
+
18
+
19
+ def main() -> None:
20
+ """
21
+ Main entry point for git-dropbox program.
22
+ """
23
+ parser = argparse.ArgumentParser()
24
+ subparsers = parser.add_subparsers()
25
+ subparsers.required = True
26
+ subparsers.dest = "command"
27
+
28
+ parser_set_head = subparsers.add_parser("set-head", help="set the default branch on the remote")
29
+ parser_set_head.add_argument("remote", type=str, help="name of the remote")
30
+ parser_set_head.add_argument("branch", type=str, help="name of the branch on the remote")
31
+
32
+ parser_version = subparsers.add_parser(
33
+ "version", help="print the version of git-remote-dropbox"
34
+ )
35
+
36
+ parser_login = subparsers.add_parser("login", help="log in to Dropbox")
37
+ parser_login.add_argument("username", type=str, help="username/tag", nargs="?", default=None)
38
+
39
+ parser_logout = subparsers.add_parser("logout", help="log out from Dropbox")
40
+ parser_logout.add_argument("username", type=str, help="username/tag", nargs="?", default=None)
41
+
42
+ parser_show_logins = subparsers.add_parser(
43
+ "show-logins", help="show logged-in accounts and their usernames/tags"
44
+ )
45
+
46
+ args = parser.parse_args()
47
+
48
+ if args.command == "set-head":
49
+ set_head(args.remote, args.branch)
50
+ elif args.command == "version":
51
+ version()
52
+ elif args.command == "login":
53
+ login(args.username)
54
+ elif args.command == "logout":
55
+ logout(args.username)
56
+ elif args.command == "show-logins":
57
+ show_logins()
58
+
59
+
60
+ def set_head(remote: str, branch: str) -> None:
61
+ """
62
+ Set the default branch on the remote to point to branch.
63
+
64
+ While almost all git-remote-dropbox functionality is fully safe under
65
+ concurrent operation, this particular functionality is not safe under a
66
+ particular kind of concurrent modification. In particular, if set-head is
67
+ called with a branch that is concurrently deleted, then the operation fails
68
+ (and notifies the user).
69
+ """
70
+ try:
71
+ url = git.get_remote_url(remote)
72
+ except subprocess.CalledProcessError:
73
+ error("no such remote '%s'" % remote)
74
+ sys.exit(1)
75
+ helper = get_helper(url)
76
+
77
+ remote_ref = "refs/heads/%s" % branch
78
+
79
+ 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
85
+
86
+ # check if target branch exists
87
+ if not branch_exists():
88
+ error("remote has no such ref '%s'" % remote_ref)
89
+ # get current head
90
+ old_head = helper.read_symbolic_ref("HEAD")
91
+ if old_head and old_head[1] == remote_ref:
92
+ error("remote HEAD is already '%s'" % remote_ref)
93
+ rev = old_head[0] if old_head else None
94
+ # write new head
95
+ ok = helper.write_symbolic_ref("HEAD", remote_ref, rev=rev)
96
+ if not ok:
97
+ error("concurrent modification of remote HEAD detected (try again)")
98
+ # ensure that target branch still exists
99
+ if not branch_exists():
100
+ # this should be a really rare occurrence: have the user fix it up if
101
+ # it happens
102
+ error("remote ref '%s' was concurrently deleted: remote HEAD needs to be fixed (try again)")
103
+ print("Updated remote HEAD to '%s'." % remote_ref)
104
+
105
+
106
+ def login(username: Optional[str]) -> None:
107
+ auth_flow = dropbox.DropboxOAuth2FlowNoRedirect(
108
+ constants.APP_KEY, use_pkce=True, token_access_type="offline"
109
+ )
110
+ authorize_url = auth_flow.start()
111
+ print("Logging in to Dropbox using OAuth...")
112
+ print("1. Go to: %s" % authorize_url)
113
+ print('2. Click "Allow" (you might have to log in first)')
114
+ print("3. Copy the authorization code")
115
+ auth_code = input("Enter authorization code: ").strip()
116
+ try:
117
+ oauth_result = auth_flow.finish(auth_code)
118
+ token = RefreshToken(oauth_result.refresh_token)
119
+ except Exception:
120
+ error("failed to log in; did you copy the code correctly?")
121
+
122
+ config = get_config()
123
+ if username is None:
124
+ config.set_default_token(token)
125
+ else:
126
+ config.set_named_token(username, token)
127
+ config.save()
128
+
129
+ if username is None:
130
+ example = "dropbox:///path/to/repo"
131
+ else:
132
+ example = "dropbox://%s@/path/to/repo" % username
133
+ print("Successfully logged in! You can now add Dropbox remotes like '%s'" % example)
134
+
135
+
136
+ def logout(username: Optional[str]) -> None:
137
+ config = get_config()
138
+ if username is None:
139
+ config.delete_default_token()
140
+ config.save()
141
+ print("Logged out!")
142
+ else:
143
+ config.delete_named_token(username)
144
+ config.save()
145
+ print("Logged out %s!" % username)
146
+
147
+
148
+ def show_logins() -> None:
149
+ config = get_config()
150
+ token = config.get_default_token()
151
+ if token is not None:
152
+ deprecated = ""
153
+ if isinstance(token, LongLivedToken):
154
+ deprecated = " [deprecated long-lived token]"
155
+ print("(default user)%s" % deprecated)
156
+ for username, token in config.named_tokens().items():
157
+ deprecated = ""
158
+ if isinstance(token, LongLivedToken):
159
+ deprecated = " [deprecated long-lived token]"
160
+ print("%s%s" % (username, deprecated))
161
+
162
+
163
+ def version() -> None:
164
+ print("git-remote-dropbox %s" % git_remote_dropbox.__version__)
@@ -0,0 +1,9 @@
1
+ import os
2
+ from typing import TextIO
3
+
4
+
5
+ APP_KEY: str = "h7d8z1irmz0r7lp"
6
+ DEVNULL: TextIO = open(os.devnull, "w")
7
+ PROCESSES: int = 20
8
+ MAX_RETRIES: int = 3
9
+ CHUNK_SIZE: int = 50 * 1024 * 1024 # 50 megabytes