# Code

Represents the contents to initialize the repository with.

Obtainable from: Code.fromAsset, Code.fromDirectory, Code.fromZipFile

- Source: [`aws-codecommit/lib/code.ts`](https://github.com/aws/aws-cdk/blob/v2.277.0/packages/aws-cdk-lib/aws-codecommit/lib/code.ts#L22)
- Type last changed: v2.4.0 · 6 Jan 2022

## Example

TypeScript:

```ts
const repo = new codecommit.Repository(this, 'Repository', {
  repositoryName: 'MyRepositoryName',
  code: codecommit.Code.fromDirectory(path.join(__dirname, 'directory/'), 'develop'), // optional property, branch parameter can be omitted
});
```

Python:

```python
repo = codecommit.Repository(self, "Repository",
    repository_name="MyRepositoryName",
    code=codecommit.Code.from_directory(path.join(__dirname, "directory/"), "develop")
)
```

Java:

```java
Repository repo = Repository.Builder.create(this, "Repository")
        .repositoryName("MyRepositoryName")
        .code(Code.fromDirectory(join(__dirname, "directory/"), "develop"))
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
var repo = new Repository(this, "Repository", new RepositoryProps {
    RepositoryName = "MyRepositoryName",
    Code = Code.FromDirectory(Join(__dirname, "directory/"), "develop")
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
repo := codecommit.NewRepository(this, jsii.String("Repository"), &RepositoryProps{
	RepositoryName: jsii.String("MyRepositoryName"),
	Code: codecommit.Code_FromDirectory(path.join(__dirname, jsii.String("directory/")), jsii.String("develop")),
})
```

## Initializer

TypeScript:

```ts
new Code()
```

Python:

```python
Code()
```

Java:

```java
new Code()
```

C# / .NET:

```csharp
new Code()
```

Golang:

```go
NewCode()
```

## Methods

- `bind(scope: Construct): CodeConfig` — This method is called after a repository is passed this instance of Code in its 'code' property.

  **Parameters**

  - `scope` — the binding scope.

- `fromAsset(asset: Asset, branch?: string): Code // chainable` (static) — Code from user-supplied asset.

  **Parameters**

  - `asset` — pre-existing asset.
  - `branch` — the name of the branch to create in the repository.

- `fromDirectory(directoryPath: string, branch?: string): Code // chainable` (static) — Code from directory.

  **Parameters**

  - `directoryPath` — the path to the local directory containing the contents to initialize the repository with.
  - `branch` — the name of the branch to create in the repository.

- `fromZipFile(filePath: string, branch?: string): Code // chainable` (static) — Code from preexisting ZIP file.

  **Parameters**

  - `filePath` — the path to the local ZIP file containing the contents to initialize the repository with.
  - `branch` — the name of the branch to create in the repository.
