
                            S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ	r	  SSKJ
r  SS	KJr  SS
KJr  \	R"                  " \	R$                  R&                  5      \	R(                   " S S\	R*                  5      5       5       r\	R"                  " \	R$                  R.                  \	R$                  R0                  5       " S S\5      5       rg)z+Clone Google Cloud Platform git repository.    )absolute_import)division)unicode_literals)git)
sourcerepo)base)
exceptions)log)storec                   D    \ rS rSrSrSSS.r\S 5       rS rS r	S	 r
S
rg)CloneGA   z Clone a cloud source repository.aZ          This command clones a git repository from the currently active
        Google Cloud project into the specified directory or into the current
        directory if no target directory is specified.

        Each Google Cloud project can have zero or more git repositories
        associated with it. To see the available repositories, run:

          $ {parent_command} list

        The clone operation configures the local clone to use your gcloud
        credentials to authenticate future git operations. This command emits a
        warning if the cloud source repository is a mirror.
      a
        The example commands below show a sample workflow.

        $ gcloud init

        $ {command} REPOSITORY_NAME DIRECTORY_NAME

        $ cd DIRECTORY_NAME
          ... create/edit files and create one or more commits ...

        $ git push origin main
      )DESCRIPTIONEXAMPLESc                 l    U R                  SSSS9  U R                  SSSS9  U R                  S	S
SSS9  g )Nz	--dry-run
store_truezZIf provided, prints the command that would be run to standard out instead of executing it.actionhelpsrcREPOSITORY_NAMEzName of the repository.)metavarr   dstDIRECTORY_NAME?zDDirectory name for the cloned repo. Defaults to the repository name.)r   nargsr   )add_argumentparsers    !lib/surface/source/repos/clone.pyArgsCloneGA.Args?   s`    
-  /
 (/H  J
 	      c                     g)zBAlways false because --use-full-gcloud-path argument is not in GA.F selfargss     r    UseFullGcloudPathCloneGA.UseFullGcloudPathO   s    r#   c                 P    SR                  X!US9n[        R                  " U5        g)z/Prints a warning if the repository is a mirror.zRepository "{repo}" in project "{prj}" is a mirror. Pushing to this clone will have no effect.  Instead, clone the mirrored repository directly with 
$ git clone {url}repoprjurlN)formatr
   warningr'   projectr-   
mirror_urlmessages        r    ActionIfMirrorCloneGA.ActionIfMirrorS   s*     v4*vE  KKr#   c                    [         R                  " SS9  [        R                  " UR                  5      n[        R
                  " 5       nUR                  U5      n[        US5      (       aL  UR                  (       a;  UR                  R                  nU R                  UR                  UR                  US9  [        R                  " UR                  UR                  UR                  S9nUR                  UR                  =(       d    UR                  UR                   U R#                  U5      S9nU(       aT  UR                   (       dB  [$        R&                  R)                  SR+                  UR                  XqR                  S95        g	g	g	)
zClone a GCP repository to the current directory.

Args:
  args: argparse.Namespace, the arguments this command is run with.

Returns:
  The path to the new git repository.
T)use_google_authmirrorConfig)r3   r-   r4   )uri)destination_pathdry_run	full_pathz<Project [{prj}] repository [{repo}] was cloned to [{path}].
)r.   pathr-   N)c_storeLoadr   	ParseRepor   SourceGetRepohasattrr:   r/   r6   
projectsIdr   GitCloner   r=   r)   r
   statuswriter0   )r'   r(   ressource_handlerr-   r4   
git_helperr?   s           r    RunCloneGA.Run[   s,    LL&


txx
(C&&(N!!#&Dt^$$):):$$((j
..txxJ  H txx@J-TXX((.  0D DLL	jj ((."~~Dxx )/ )IJ !tr#   r%   N)__name__
__module____qualname____firstlineno____doc__detailed_helpstaticmethodr!   r)   r6   rN   __static_attributes__r%   r#   r    r   r      s<     )

-:  Jr#   r   c                   4    \ rS rSrSr\S 5       rS rS rSr	g)
CloneAlpha{   a  Clone a cloud source repository.

This command clones a git repository for the currently active
Google Cloud Platform project into the specified directory or into
the current directory if no target directory is specified.  This command
gives an error if the cloud source repository is a mirror.

The clone operation configures the local clone to use your gcloud
credentials to authenticate future git operations.

## EXAMPLES

The example commands below show a sample workflow.

  $ gcloud init
  $ {command} REPOSITORY_NAME DIRECTORY_NAME
  $ cd DIRECTORY_NAME
  ... create/edit files and create one or more commits ...
  $ git push origin main
c                 P    [         R                  U 5        U R                  SSSS9  g )Nz--use-full-gcloud-pathr   zIf provided, use the full gcloud path for the git credential.helper. Using the full path means that gcloud does not need to be in the path for future git operations on the repository.r   )r   r!   r   r   s    r    r!   CloneAlpha.Args   s.    LL
 
A	  Cr#   c                     UR                   $ )z?Use value of --use-full-gcloud-path argument in beta and alpha.)use_full_gcloud_pathr&   s     r    r)   CloneAlpha.UseFullGcloudPath   s    $$$r#   c                 P    SR                  X!US9n[        R                  " SU5      e)z2Raises an exception if the repository is a mirror.zrRepository "{repo}" in project "{prj}" is a mirror. Clone the mirrored repository directly with 
$ git clone {url}r,   r   )r0   c_excInvalidArgumentExceptionr2   s        r    r6   CloneAlpha.ActionIfMirror   s0    v4*vE  
(
():G
DDr#   r%   N)
rP   rQ   rR   rS   rT   rV   r!   r)   r6   rW   r%   r#   r    rY   rY   {   s(    * C C%Er#   rY   N)rT   
__future__r   r   r   googlecloudsdk.api_lib.sourcer   r   googlecloudsdk.callioper   r	   ra   googlecloudsdk.corer
   googlecloudsdk.core.credentialsr   r@   ReleaseTracksReleaseTrackGADefaultUniverseOnlyCommandr   BETAALPHArY   r%   r#   r    <module>rp      s    2 &  ' - 4 ( 7 # < D%%(()YJdll YJ  *YJx D%%**D,=,=,C,CD*E *E E*Er#   